8 Commits

Author SHA1 Message Date
96f468c4f8 0.1.19 2023-05-13 20:12:44 -07:00
c06c01823b add sync inline renderer 2023-05-13 20:12:39 -07:00
8afb5423e3 0.1.18 2023-05-12 15:07:47 -07:00
0f83a56299 cleanup 2023-05-12 15:07:43 -07:00
ae7b491107 0.1.17 2023-05-12 14:59:49 -07:00
8599460702 whitelist rdfa tags/attrs in html sanitizer 2023-05-12 14:59:45 -07:00
fb52d31090 0.1.16 2023-05-12 14:54:12 -07:00
859064f00b add rdfa for breadcrumbs 2023-05-12 14:54:05 -07:00
5 changed files with 44 additions and 7 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@doc-utils/markdown2html",
"version": "0.1.15",
"version": "0.1.19",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@doc-utils/markdown2html",
"version": "0.1.15",
"version": "0.1.19",
"dependencies": {
"bytefield-svg": "^1.6.1",
"dompurify": "^2.3.6",

View File

@@ -1,6 +1,6 @@
{
"name": "@doc-utils/markdown2html",
"version": "0.1.15",
"version": "0.1.19",
"publishConfig": {
"registry": "https://gitea.home.jbrumond.me/api/packages/doc-utils/npm/"
},

View File

@@ -44,13 +44,15 @@ export function breadcrumb_nav_ext(renderer: marked.Renderer, opts: MarkdownOpti
+ `\t<ol>\n`
+ '\t\t'
+ token.items.map((tokens, index) =>{
let item = '<li>';
let item = '<li>\n';
if (index) {
item += '<span class="separator" aria-hidden="true">/</span> ';
item += '\t\t\t<span class="separator" aria-hidden="true">/</span>\n';
}
return item + this.parser.parseInline(tokens, renderer) + '</li>';
item += `\t\t\t${this.parser.parseInline(tokens, renderer)}\n`;
return item + '\t\t</li>';
}).join('\n\t\t')
+ '\n'
+ `\t</ol>\n`

View File

@@ -8,6 +8,6 @@ export function sanitize_html(html: string, custom_elements?: CustomElementHandl
const { window } = new JSDOM('');
const dom_purify = createDOMPurify(window as any as Window);
return dom_purify.sanitize(html, {
CUSTOM_ELEMENT_HANDLING: custom_elements
CUSTOM_ELEMENT_HANDLING: custom_elements,
});
}

View File

@@ -69,3 +69,38 @@ export async function render_markdown_to_html(markdown: string, options: Markdow
return sanitize_html(unsafe_html, options.custom_elements);
}
export function render_markdown_to_html_inline_sync(markdown: string, options: MarkdownOptions = { }) {
const marked_options: marked.MarkedOptions = {
baseUrl: options.base_url,
breaks: options.breaks || false,
renderer: create_renderer(options),
};
marked.use({
extensions: [
katex_block_ext(marked_options.renderer, options),
katex_inline_ext(marked_options.renderer, options),
footnote_ref_ext(marked_options.renderer, options),
footnote_list_ext(marked_options.renderer, options),
mark_ext(marked_options.renderer, options),
description_list_ext(marked_options.renderer, options),
section_ext(marked_options.renderer, options),
icon_ext(marked_options.renderer, options),
breadcrumb_nav_ext(marked_options.renderer, options),
...(options.extensions || [ ]).map((ext) => {
return ext(marked_options.renderer, options);
}),
],
tokenizer: {
url(src) {
// disable auto-linking; more can be added here to auto-link only sometimes
// see: https://github.com/markedjs/marked/issues/882#issuecomment-781628889
return null;
}
},
});
const unsafe_html = marked.parseInline(markdown, marked_options);
return sanitize_html(unsafe_html, options.custom_elements);
}