UNPKG

@thi.ng/tangle

Version:

Literate programming code block tangling / codegen utility, inspired by org-mode & noweb

74 lines (73 loc) 1.19 kB
import { ConsoleLogger, LogLevel, ROOT } from "@thi.ng/logger"; import { split } from "@thi.ng/strings"; import { map, str, transduce } from "@thi.ng/transducers"; const JS_DOC = { prefix: /^\s*\*\s+```/, suffix: /^\s*\*\s+```/m, xform: (body) => transduce( map((x) => x.replace(/^\s*\*\s?/, "")), str("\n"), split(body) ) }; const BLOCK_FORMATS = { ".md": { prefix: "```", suffix: "```" }, ".org": { prefix: "#+BEGIN_SRC ", suffix: "#+END_SRC" }, ".js": JS_DOC, ".ts": JS_DOC }; const C = "//"; const P = "#"; const L = "--"; const S = ";;"; const C89 = ["/*", "*/"]; const HTML = ["<!--", "-->"]; const COMMENT_FORMATS = { c: C89, clj: S, cljs: S, cpp: C, cs: C, css: C89, docker: "::", elm: L, erl: "%", fs: "\\", go: C, h: C, html: HTML, java: C, js: C, jsonc: C, lua: L, md: HTML, ml: ["(*", "*)"], pde: C, py: P, rs: C, scala: C, scm: S, sh: P, sql: L, swift: C, tex: "%", toml: P, ts: C, ttl: P, wast: S, xml: HTML, yaml: P, zig: C }; const LOGGER = ROOT.addChild(new ConsoleLogger("tangle", LogLevel.INFO)); export { BLOCK_FORMATS, COMMENT_FORMATS, LOGGER };