Parse README.md files and turn LaTeX equations into SVGs.
$ npm install insert-equations
var insertEquations = require( 'insert-equations' );
Parses the README.md
file in the supplied directory and inserts SVG images for all <equation>
tags. The label
, align
, raw
and alt
attributes of the equation tag will be used. Upon creating the SVG images, the README.md
file will be overwritten with the newly generated markup.
insertEquations( 'mydirectory', done )
function done( err ) {
if ( err ) {
throw err;
}
console.log( 'README.md file successfully processed.' );
} // end FUNCTION done()
-
As a concrete example
<!-- <equation class="equation" label="eq:gamma_function_positive_integers" align="center" raw="\Gamma ( n ) = (n-1)!" alt="Gamma function for positive integers."> --> <!-- </equation> -->
will be transformed to
<!-- <equation class="equation" label="eq:gamma_function_positive_integers" align="center" raw="\Gamma ( n ) = (n-1)!" alt="Gamma function for positive integers."> --> <div class="equation" align="center" data-raw-text="\Gamma ( n ) = (n-1)!" data-equation="eq:gamma_function_positive_integers"> <img src="https://cdn.rawgit.com/Planeshifter/insert-equations-examples/8fd73c14a23a0bcb1d31e7e3246ae411e11a0c70/docs/img/eqn1.svg" alt="Gamma function for positive integers."> <br> </div> <!-- </equation> -->
-
The supplied directory has to be a git project with a remote branch on GitHub. Otherwise,
insertEquations
will throw an error. -
Beware:
insertEquations
automatically creates a commit for the newly created files and changes toREADME.md
.
var child_process = require( 'child_process' );
var fs = require( 'fs-extra' );
var path = require( 'path' );
var insertEquations = require( 'insert-equations' );
var fPath = path.resolve( __dirname, './fixtures' );
var inputPath = path.join( fPath, '_README.md' );
var outputPath = path.join( fPath, 'README.md' );
fs.copySync( inputPath, outputPath );
child_process.execSync( 'rm -rf .git', { cwd: fPath } );
child_process.execSync( 'git init', { cwd: fPath } );
child_process.execSync( 'git remote add origin https://github.com/Planeshifter/insert-equations-examples.git', { cwd: fPath } );
insertEquations( fPath, done );
function done( err ) {
if ( err ) {
throw err;
}
console.log( 'README.md file successfully processed.' );
} // end FUNCTION done()
To run the example code from the top-level application directory,
$ node ./examples/index.js
To use the module as a general utility, install the module globally
$ npm install -g insert-equations
Usage: insert-equations [options] [directory]
Options:
-h, --help Print this message.
-V, --version Print the package version.
- If no
directory
is supplied, the current working directory will be used to look for aREADME.md
file.
$ insert-equations examples/fixtures
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.
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
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
Copyright © 2016. Philipp Burckhardt.