-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from ONSdigital/feature-update-markdown-proces…
…sor-to-allow-captions Feature update markdown processor to allow captions
- Loading branch information
Showing
3 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This code defines a custom renderer that extends marked.js and overrides the table rendering method to include a <caption>. | ||
// 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 ? `<caption>${headingText}</caption>` : ''; | ||
// Construct the table element with the optional caption | ||
return `<table> | ||
${caption} | ||
<thead>${header}</thead> | ||
<tbody>${body}</tbody> | ||
</table>`; | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters