npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

github-markdown-equation-element

v2.0.0

Published

Generate an HTML string for displaying an SVG equation in a Github Markdown file.

Downloads

7

Readme

Equation Element

NPM version Build Status Coverage Status Dependencies

Generate an HTML string for displaying an SVG equation in a Github Markdown file.

Installation

$ npm install github-markdown-equation-element

Usage

var createElement = require( 'github-markdown-equation-element' );

createElement( [options] )

Generate an HTML string for displaying an SVG equation in a Github Markdown file.

var html = createElement();
/* returns 
    '<div class="equation" align="center" data-raw-text="" data-equation="">
       <img src="" alt="">
       <br>
     </div>'
*/

The function accepts the following options:

  • className: element class name. Default: 'equation'.
  • align: element alignment. Default: 'center'.
  • raw: raw equation text.
  • label: equation label.
  • src: image source URL.
  • alt: alternative image text.

Each option corresponds an HTML attribute. For example, to set the image source URL, set the src option.

var opts = {
	'src': 'https://cdn.rawgit.com/math-io/gamma/master/docs/img/eqn1.svg'
};

var html = createElement( opts );
/* returns
    '<div class="equation" align="center" data-raw-text="" data-equation="">
      <img src="https://cdn.rawgit.com/math-io/gamma/master/docs/img/eqn1.svg" alt="">
      <br>
    </div>'
*/

To include a raw equation TeX or LaTeX string in the element, set the raw option.

var opts = {
	'raw': '\\Gamma ( n ) = (n-1)!',
	'src': 'https://cdn.rawgit.com/math-io/gamma/master/docs/img/eqn1.svg'
};

var html = createElement( opts );
/* returns 
    '<div class="equation" align="center" data-raw-text="\Gamma ( n ) = (n-1)!" data-equation="">
      <img src="https://cdn.rawgit.com/math-io/gamma/master/docs/img/eqn1.svg" alt="">
      <br>
    </div>'
*/

Examples

var createElement = require( 'github-markdown-equation-element' );

var opts = {
	'className': 'eqn',
	'align': 'left',
	'raw': '\\operatorname{erf}(x) = \\frac{2}{\\sqrt\\pi}\\int_0^x e^{-t^2}\\,\\mathrm dt',
	'label': 'eq:erf',
	'src': 'https://cdn.rawgit.com/math-io/erf/master/docs/img/eqn.svg',
	'alt': 'Error function.'
};

var html = createElement( opts );

console.log( html );
/* returns 
    '<div class="eqn" align="left" data-raw-text="\operatorname{erf}(x) = \frac{2}{\sqrt\pi}\int_0^x e^{-t^2}\,\mathrm dt" data-equation="eq:erf">
      <img src="https://cdn.rawgit.com/math-io/erf/master/docs/img/eqn.svg" alt="Error function.">
      <br>
    </div>'
*/

To run the example code from the top-level application directory,

$ node ./examples/index.js

CLI

Installation

To use the module as a general utility, install the module globally

$ npm install -g github-markdown-equation-element

Usage

Usage: gheqn [options]

Options:

  -h,  --help               Print this message.
  -V,  --version            Print the package version.
       --class name         Element class name. Default: equation.
       --align alignment    Element alignment. Default: center.
       --raw text           Raw equation text.
       --label label        Equation label.
       --src url            Image source URL.
       --alt text           Alternative image text.

Examples

$ gheqn --raw '\Gamma ( n ) = (n-1)!' --src 'https://cdn.rawgit.com/math-io/gamma/master/docs/img/eqn1.svg'
# => <div class="equation" align="center" data-raw-text="\Gamma ( n ) = (n-1)!" data-equation="">\n\t<img src="https://cdn.rawgit.com/math-io/gamma/master/docs/img/eqn1.svg" alt="">\n\t<br>\n</div>

Tests

Unit

This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

Browser Support

This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:

$ make test-browsers

To view the tests in a local web browser,

$ make view-browser-tests

License

MIT license.

Copyright

Copyright © 2016. Athan Reines.