@zaeny/literate

1.0.7 • Public • Published

@zaeny/literate

npm version npm downloads

literate programming, extract code blocks from markdown file

See related packages : @composable

Table of Contents

Usage

Node.js Installing

npm install @zaeny/literate

Import

import {extractCode} from 'https://cdn.jsdelivr.net/npm/@zaeny/literate';
// import core code individually without side effects, and use in browser
import {extractCode} from 'https://cdn.jsdelivr.net/npm/@zaeny/literate/src/core.js';

Extracting Code

var {extractCode}  = require('@zaeny/literate');
// or
var {extractCode} = await import('@zaeny/litarte');

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');" }
  ]
*/

evaluating markdown files

var {evaluateBlock} = require('@zaeny/literate');
// or
var {evaluateBlock} = await import('@zaeny/literate');

evaluateBlock(testMdFile);
/*
  welcome
  hai
*/
// more advanced,
// evaluateBlock(md, validation, context, requiredContext)
evalulateBlock(testMdFile, (file) => (file.code && file.lang === "js" && file.eval===1), global, {require, console, module });

extracting code blocks from markdown alias tangle

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

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

Documentation

check the index.md;

Changes

  • [1.0.2] tangle and eval now return object of inputed
  • [1.0.5] refactor groupBlockBy, rename eval to evalaute, move repository to composable
  • [1.0.7] add captureCode captureCodeAt

/@zaeny/literate/

    Package Sidebar

    Install

    npm i @zaeny/literate

    Weekly Downloads

    195

    Version

    1.0.7

    License

    GPL-3.0

    Unpacked Size

    8.68 kB

    Total Files

    8

    Last publish

    Collaborators

    • azizzaeny