6 Commits

Author SHA1 Message Date
e184b6f8b4 0.1.21 2023-05-13 22:12:04 -07:00
e601f45836 update bin scripts to work as symlinks 2023-05-13 22:11:59 -07:00
8203bbe763 0.1.20 2023-05-13 20:13:50 -07:00
2bd98c788d export 2023-05-13 20:13:49 -07:00
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
7 changed files with 43 additions and 6 deletions

View File

@@ -1,2 +1,2 @@
#!/bin/sh
node $(dirname $0)/markdown2html.js $*
node $(dirname "$(readlink -f "$0")")/markdown2html.js $*

View File

@@ -1,2 +1,2 @@
#!/bin/sh
node $(dirname $0)/strip-frontmatter.js $*
node $(dirname "$(readlink -f "$0")")/strip-frontmatter.js $*

4
package-lock.json generated
View File

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

View File

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

View File

@@ -3,6 +3,8 @@ import { marked } from 'marked';
import { ParsedAttributes, parse_attributes } from './attrs';
import { MarkdownOptions } from './render';
// todo: deprecate this
export interface BreadcrumbNavToken extends marked.Tokens.Generic {
text: string;
attrs: ParsedAttributes;

View File

@@ -1,3 +1,3 @@
export { process_frontmatter } from './frontmatter';
export { render_markdown_to_html, MarkdownExtension, MarkdownOptions } from './render';
export { render_markdown_to_html, render_markdown_to_html_inline_sync, MarkdownExtension, MarkdownOptions } from './render';

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);
}