Skip to content

Commit

Permalink
feat: allow passing custom extensions to marked (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
LachlanNewman authored Jul 15, 2022
1 parent 3e45dc7 commit d790b2b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const defaultConfig: Config = {
stylesheet_encoding: 'utf-8',
as_html: false,
devtools: false,
marked_extensions: [],
};

/**
Expand Down Expand Up @@ -165,6 +166,13 @@ interface BasicConfig {
* This is specifically useful when running into issues when editor plugins trigger additional saves after the initial save.
*/
watch_options?: WatchOptions;

/**
* Custm Extensions to be passed to marked.
*
* @see https://marked.js.org/using_pro#extensions
*/
marked_extensions: marked.MarkedExtension[];
}

export type PuppeteerLaunchOptions = Parameters<typeof launch>[0];
2 changes: 1 addition & 1 deletion src/lib/get-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getHtml = (md: string, config: Config) => `<!DOCTYPE html>
<html>
<head><title>${config.document_title}</title><meta charset="utf-8"></head>
<body class="${config.body_class.join(' ')}">
${getMarked(config.marked_options)(md)}
${getMarked(config.marked_options, config.marked_extensions)(md)}
</body>
</html>
`;
4 changes: 2 additions & 2 deletions src/lib/get-marked-with-highlighter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hljs from 'highlight.js';
import { marked } from 'marked';

export const getMarked = (options: marked.MarkedOptions) => {
export const getMarked = (options: marked.MarkedOptions, extensions: marked.MarkedExtension[]) => {
marked.setOptions({
highlight: (code, languageName) => {
const language = hljs.getLanguage(languageName) ? languageName : 'plaintext';
Expand All @@ -11,6 +11,6 @@ export const getMarked = (options: marked.MarkedOptions) => {
langPrefix: 'hljs ',
...options,
});

marked.use(...extensions);
return marked;
};

0 comments on commit d790b2b

Please sign in to comment.