Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass custom extension to marked #127

Merged
merged 3 commits into from
Jul 15, 2022

Conversation

LachlanNewman
Copy link
Contributor

Ths PR allows the user to pass a custom extension to the marked parser.
see https://marked.js.org/using_pro#extensions

Copy link
Owner

@simonhaenisch simonhaenisch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I've been wanting to do sth like that for a while anyway.

Please see the suggestions. Instead of using [] as a default in the function params, can you add marked_extensions: [] to the defaultConfig in src/lib/config.ts, please?

@@ -165,6 +165,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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Custm Extensions to be passed to marked
* Custom Extensions to be passed to marked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -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[] = []) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const getMarked = (options: marked.MarkedOptions, extensions: marked.MarkedExtension[] = []) => {
export const getMarked = (options: marked.MarkedOptions, extensions: marked.MarkedExtension[]) => {

@@ -11,6 +11,6 @@ export const getMarked = (options: marked.MarkedOptions) => {
langPrefix: 'hljs ',
...options,
});

marked.use(...extensions)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
marked.use(...extensions)
marked.use(...extensions);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*
* See https://marked.js.org/using_pro#extensions
*/
extensions?: marked.MarkedExtension[]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extensions?: marked.MarkedExtension[]
marked_extensions: marked.MarkedExtension[];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -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.extensions)(md)}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
${getMarked(config.marked_options, config.extensions)(md)}
${getMarked(config.marked_options, config.marked_extensions)(md)}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Owner

@simonhaenisch simonhaenisch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple style issues then it's good to go (:

src/lib/config.ts Outdated Show resolved Hide resolved
src/lib/config.ts Outdated Show resolved Hide resolved
@simonhaenisch simonhaenisch merged commit d790b2b into simonhaenisch:master Jul 15, 2022
@simonhaenisch
Copy link
Owner

Hey sorry somehow I never got around to releasing this 🙈 I just did, so with 5.2.0 this should be available now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants