diff --git a/src/processors/markdown.js b/src/processors/markdown.js index 6f497fb..b965f1e 100644 --- a/src/processors/markdown.js +++ b/src/processors/markdown.js @@ -1,6 +1,6 @@ import { marked } from "marked"; import { gfmHeadingId } from "marked-gfm-heading-id"; - +import markedExtension from "./marked-extension.js"; import StaticProcessor from "./processor.js"; const defaultOptions = { @@ -15,6 +15,7 @@ const defaultOptions = { }; marked.use(gfmHeadingId(false)); +marked.use(markedExtension()); export default class MarkdownStaticProcessor extends StaticProcessor { constructor(options) { super(); diff --git a/src/processors/marked-extension.js b/src/processors/marked-extension.js new file mode 100644 index 0000000..dc292a9 --- /dev/null +++ b/src/processors/marked-extension.js @@ -0,0 +1,28 @@ +// This code defines a custom renderer that extends marked.js and overrides the table rendering method to include a . +// You can learn more about custom renderer here at https://marked.js.org/using_pro#renderer +export default function markedExtension() { + // Declare the heading text so it can be used globally + let headingText; + return { + renderer: { + // Custom renderer for headings + heading(text) { + // Set the heading text + headingText = text; + // Return an empty string to skip rendering the heading itself + return ''; + }, + // Custom renderer for tables + table(header, body){ + // Check if there is heading text so we can add a caption + const caption = headingText ? `${headingText}` : ''; + // Construct the table element with the optional caption + return ` + ${caption} + ${header} + ${body} +
`; + } + } + }; +} diff --git a/src/rendering/filters/htmlContentFilter.js b/src/rendering/filters/htmlContentFilter.js index aea6f0e..5491001 100644 --- a/src/rendering/filters/htmlContentFilter.js +++ b/src/rendering/filters/htmlContentFilter.js @@ -35,8 +35,7 @@ export default function createHtmlContentFilter(data) { // Decorate table elements with ONS design system classes. [escape("")]: '
', [escape("
")]: '', - [escape("

")]: '

', - [escape("

")]: '', + [escape("")]: '', [escape("")]: '', [escape("")]: '', [escape("")]: '',