UNPKG

typedoc-plugin-markdown

Version:

A TypeDoc plugin that generates TypeScript API documentation as Markdown.

17 lines (16 loc) • 617 B
/** * - Replace new lines with spaces * - Replaces code blocks with single backticks * - Replaces multiple spaces with single spaces * - Escapes pipes not already escaped, which would otherwise end the cell. * GFM splits rows before parsing code spans, so this applies inside code * spans too; renderers drop the backslash and show a plain `|`. */ export function formatTableCell(str) { return str .replace(/\r?\n/g, ' ') .replace(/```(\w+\s)?([\s\S]*?)```/gs, (match, p1, p2) => `\`${p2.trim()}\``) .replace(/ +/g, ' ') .replace(/(?<!\\)\|/g, '\\|') .trim(); }