Compare commits
2 Commits
1dcc58c4b2
...
5304e20c94
Author | SHA1 | Date | |
---|---|---|---|
5304e20c94 | |||
865016bb26 |
4
package-lock.json
generated
4
package-lock.json
generated
@ -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",
|
||||||
|
@ -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/"
|
||||||
},
|
},
|
||||||
|
@ -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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user