Skip to content

Support custom Markdown renderer and HTML sanitizer#28

Open
jfx2006 wants to merge 3 commits intonezanuha:mainfrom
jfx2006:custom_renderer
Open

Support custom Markdown renderer and HTML sanitizer#28
jfx2006 wants to merge 3 commits intonezanuha:mainfrom
jfx2006:custom_renderer

Conversation

@jfx2006
Copy link
Copy Markdown

@jfx2006 jfx2006 commented Apr 11, 2026

Allow for custom options in Marked and an HTML santizer.

Sample usage:

function mkRender() {
    const mdRender = new Marked()

    mdRender.setOptions({
      async: false,
      gfm: true,
      pedantic: false,
      breaks: false,
    })
    mdRender.use(
        markedHighlight({
          langPrefix: "hljs language-",
          highlight(code, lang) {
            const lowerLang = lang.toLowerCase()
            const language = hljs.getLanguage(lowerLang) ? lowerLang : "plaintext"
            return hljs.highlight(code, { language }).value
          },
        }),
    )

    return mdRender.parse
}

const editor = new MarkdownEditor('#markdown-editor', {
  placeholder: 'Write your markdown...',
  mode: "hybrid",
  toolbar: ['heading', 'bold', 'italic', 'strikethrough', 'ul', 'ol', 'checklist', 'blockquote', 'link', 'image', 'preview'],
  renderer: mkRender(),
  sanitizer: DOMPurify.sanitize,
});

jfx2006 added 3 commits April 11, 2026 17:19
Have a single way of setting the preview content. Ensure that renderHybrid
is called whereever the previous method was used.
Marked's documentation suggests sanitizing its output. Allow
for any sanitizer to be used such as DOMPurify, defaulting to
a no-op.
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.

1 participant