literate programming, extract code blocks from markdown file
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'
- [1.0.2]
tangle
andeval
now return object of inputed