1.0.8 • Published 10 months ago

@zaeny/literate v1.0.8

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
10 months ago

@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
  • 1.0.8 fix homepage repository, add global to incldue in simple script tag literate
1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago