@zaeny/literate

1.0.3 • Public • Published

@zaeny/literate

npm version npm downloads

literate programming, extract code blocks from markdown file

Getting Started

npm install @zaeny/literate

Usage

var {extractCode}  = require('@zaeny/literate');
var testMdFile = fs.readFileSync('./test.md', 'utf8');

extractCode(testMdFile);

/*
  [
  { path: 'index.js', lang: 'js', code: "console.log('welcome');" },
  { path: 'index.js', lang: 'js', code: "console.log('hai');" }
]
*/

var {eval} = require('@zaeny/literate/eval');
eval(testMdFile);
/*
  welcome
  hai
*/

var {tangle} = require('@zaeny/literate/tangle');
tangle(testMdFile);
/*
  'tangle files: #1 index.js'
*/

More example

eval(string, validatorFn)
eval(testMdFile, (file) => (file.code && file.lang === "js" && file.eval===1));
// welcome
// hai

tangle(testMdFile, (file) => (file.path && file.lang === "js"));
//  'tangle files: #1 index.js'

Changes

  • [1.0.2] tangle and eval now return object of inputed

Package Sidebar

Install

npm i @zaeny/literate

Weekly Downloads

0

Version

1.0.3

License

GPL-3.0

Unpacked Size

39.6 kB

Total Files

7

Last publish

Collaborators

  • azizzaeny