GithubHelp home page GithubHelp logo

term-helper's Introduction

Term Helper

Show <abbr>'s title and further detail when hovering or tapped.

Usage

> npm run build
<p>
    Simply wrap terms with the abbreviation tag in <abbr>HTML</abbr>.
</p>
import { TermHelper } from "./dist/index.mjs"


const helper = new TermHelper({
    HTML: {
        title: 'HyperText Markup Language',
        description: "<dfn>HTML</dfn> (HyperText Markup Language) is a descriptive language that specifies webpage structure. (See more on <a href='https://developer.mozilla.org/en-US/docs/Glossary/HTML'>MDN Web Docs</a>)"
    }
    // …
})
helper.on(document.body)

See example.html (and src/example.scss) for full example.

The example.scss is only an example — not intended for real usage. At least, it will break if you change the call-out's CSS class.

This project is agnostic for CSS. You can change tags' names and CSS classes freely. Here are the default.

const helper = new TermHelper(glossary, {
  callout: {
    className: 'term-callout',
    tagName: {
      outer: 'aside',
      inner: 'article',
      title: 'h4',
      description: 'div'
    }
  },
  term: {
    markedClassName: 'active',
    selector: 'abbr'
  }
})

Call-out's structure:

outer.className (aside.term-callout)
└─ inner (article)
   ├─ title (h4)
   └─ description (div)

The titles and descriptions in the glossary are used as inner HTML. You can provide a tex preprocessor for them.

const helper = new TermHelper(glossary, {
  callout: {
    preprocessor: {
      title: (original: string) => `🔎 ${original}`,
      description (original: string) {
        return original.split('\n').map(p => `<p>${p}</p>`).join('')
      }
    }
  }
})

Using TypeScript here.

Inspired by

ICANN website. (One of their pages and their glossary_terms.js)

term-helper's People

Contributors

ydx-2147483647 avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.