Admittedly non-standard use of code block language confuses Marked

Bill Smargiassi's Avatar

Bill Smargiassi

14 May, 2018 08:11 PM

// Please enter a detailed description of the issue // Description of the issue:

Marked gets confused with an odd code block syntax. My former, now-defunct employer used file locations »```/etc/security/limits.conf« in their documentation in addition to »’’’erlang« for instance. Hugo and GitHub render it fine, but Marked throws out the first backquotes, and the code blocks become regular text and the regular text becomes code blocks. My old employer’s use here is an odd thing, but the open source software seems to have legs, and I’m still supporting some of their customers.

// Please enter a list of steps required to reproduce the issue // Steps to reproduce:

  1. Use a code block with a file path instead of a language
  2. Render it in Marked

// If applicable please attach a sample document that causes the issue for you.

Here is the Markdown source:

You can see what GitHub does with it there for comparison with Marked. Also, shows what the Hugo theme does with the odd code block syntax.

I've attached the source as well. I tried to create a smaller example, but though the second block is ugly, Marked doesn't ignore the beginning of the code blocks if I set up a sample of one good one and one bad one. Something more complicated must be going on. Adding the front matter seems to have no effect.

// Configuration (do not edit) Marked 2 946 (Direct)

macOS Version: 10.13.4

allowPageBreakInCode: TRUE
bookTxtIsLeanpub: TRUE
summaryMdIsGitBook: TRUE
codeIsPoetry: TRUE
codeCanWrap: TRUE
collapsibleHeadlines: TRUE
convertGithubCheckboxes: TRUE
defaultMathJaxConfig: TeX-AMS-MML_HTMLorMML
defaultPreviewStyle: 102
defaultProcessor: Discount (GFM)
enableMiniMap: TRUE
excludeBlockQuotesFromCounts: TRUE
excludeFootnotesFromCounts: TRUE
excludeVerbatimFromCounts: TRUE
excludeCaptionsFromCounts: TRUE
folderPreviewExtensionsArray: md, markdown, txt, mdown, html, opml
githubNewlines: TRUE
h1IsPageBreak: TRUE
h2IsPageBreak: TRUE
hrIsPageBreak: TRUE
includeMathJax: TRUE
limitTextWidth: TRUE
minimalJavaScript: TRUE
permissionGranted: TRUE
printHeaderFirstPage: TRUE
printFooterFirstPage: TRUE
processHTMLFiles: TRUE
removeMetadataForPreview: TRUE
removeYAMLHeaders: TRUE
scrollToEdit: TRUE
shouldDetectCritic: TRUE
shouldHighlightMarkupErrors: TRUE
shouldLoadCritic: TRUE
syntaxHighlight: TRUE

  1. Support Staff 1 Posted by Brett on 15 May, 2018 12:40 PM

    Brett's Avatar

    Hi Bill,

    That formatting definitely isn't standard, and Marked's regex for code blocks isn't going to catch it. I'm willing to add support for it, but in the meantime the best solution might be a custom preprocessor that converts the syntax for preview, likely removing the backslash sequences completely, unless you can tell what language specifier to substitute...

    Something like:

    cat | sed -e 's/\`\`\`\/.*/\`\`\`/g'

    would do the trick.

  2. 2 Posted by Bill Smargiassi on 15 May, 2018 03:27 PM

    Bill Smargiassi's Avatar

    Thanks, that’s a great idea. I never had a use for the preprocessors before.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Already uploaded files

  • 7.67 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac