/* Parses fenced code blocks with `annotate` in info string. Results in single line comments split out, output format is: .annotate .annotate-row (n) .annotate-code .annotate-note Contributing rules: - You must include `annotate` in the info string - You must include a language on the starting ` ``` ` tag. - Notes must start with one of: `#`, `//`, `` to maintain syntax highlighting; this will not impact what renders. `parse-info-string.js` plugin is required for this to work, and must come before `remark-rehype`. `annotate` must come before the `highlight` plugin. */ import yaml from 'js-yaml' import fs from 'fs' import { chunk, last } from 'lodash-es' import { visit } from 'unist-util-visit' import { h } from 'hastscript' import { fromMarkdown } from 'mdast-util-from-markdown' import { toHast } from 'mdast-util-to-hast' // import { header } from './code-header.js' const languages = yaml.load(fs.readFileSync('./data/variables/code-languages.yml', 'utf8')) const commentRegexes = { number: /^\s*#\s*/, // also known has hash or sharp; but the unicode name is "number sign" slash: /^\s*\/\/\s*/, xml: /^\s*