import type { BlockPlugin, HmmBlock, HmmOptions } from "../types.ts"; import { renderNode } from "../render.ts"; const REGEXP = /^\d+\.\s+/; /** * @todo Handle nested and indented lists */ const plugin: BlockPlugin = { type: "orderedList", multiline: true, matchStart: (line: string, index: number): boolean => { if (index > 0 && /^\s{4}[^\s]/.test(line)) return true; return REGEXP.test(line); }, render: (block: HmmBlock, options: HmmOptions) => { block.render = "
    "; // Merge space-indented lines const lines: Array = []; for (let i = 0; i < block.lines.length; i++) { const line = block.lines[i]; if (/^\s*$/.test(line)) continue; if (line.startsWith(" ")) { lines[lines.length - 1] += `
    ${line}`; } else { lines.push(line.replace(/^\d+\.\s+/, "")); } } for (const line of lines) { const text = renderNode(line, options, "li"); block.render += `
  1. ${text}
  2. `; } block.render += "
"; return block.render; }, }; export default plugin;