Compare commits

...

2 Commits

Author SHA1 Message Date
5304e20c94
0.2.5 2023-05-18 21:56:19 -07:00
865016bb26
do not render in async mode 2023-05-18 21:56:18 -07:00
3 changed files with 8 additions and 9 deletions

4
package-lock.json generated
View File

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

View File

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

View File

@ -26,24 +26,23 @@ export interface MarkdownExtension {
} }
export async function render_markdown_to_html(markdown: string, options: MarkdownOptions = { }) { export async function render_markdown_to_html(markdown: string, options: MarkdownOptions = { }) {
const marked_options = marked_opts(true, options); const marked_options = marked_opts(options);
const unsafe_html = options.inline const unsafe_html = options.inline
? marked.parseInline(markdown, marked_options) ? marked.parseInline(markdown, marked_options)
: await marked.parse(markdown, marked_options).then(resolve_async_bindings); : marked.parse(markdown, marked_options);
return sanitize_html(unsafe_html, options.custom_elements); return sanitize_html(await resolve_async_bindings(unsafe_html), options.custom_elements);
} }
export function render_markdown_to_html_inline_sync(markdown: string, options: MarkdownOptions = { }) { export function render_markdown_to_html_inline_sync(markdown: string, options: MarkdownOptions = { }) {
const marked_options = marked_opts(false, options); const marked_options = marked_opts(options);
setup_marked(options, marked_options); setup_marked(options, marked_options);
const unsafe_html = marked.parseInline(markdown, marked_options); const unsafe_html = marked.parseInline(markdown, marked_options);
return sanitize_html(unsafe_html, options.custom_elements); return sanitize_html(unsafe_html, options.custom_elements);
} }
function marked_opts<T extends boolean>(async: T, options: MarkdownOptions) : marked.MarkedOptions & { async: T } { function marked_opts<T extends boolean>(options: MarkdownOptions) : marked.MarkedOptions {
return { return {
async,
breaks: options.breaks || false, breaks: options.breaks || false,
renderer: create_renderer(options), renderer: create_renderer(options),
mangle: false, mangle: false,