Skip to content

Don't throw an exception for unknown code block languages #810

Closed

Description

@aaronpk

In my source content, I have:

```HTTP
stuff
```

This results in a Javascript error:

example.html:28 Uncaught Error: Unknown language: "HTTP"
Please report this to https://github.com/chjj/marked.

If an unknown language is encountered, it should be treated as plain text rather than throwing an exception.

Activity

  1. Feder1co5oave commented on Sep 26, 2016

    @Feder1co5oave
    Contributor

    I'm pretty sure this is highlight.js throwing the exception, and marked just reports it. What options are you using?

  2. acorbel commented on Oct 22, 2016

    @acorbel

    To prevent this exception, I did:

    markedProvider.setOptions({
                gfm: true,
                tables: true,
                breaks: false,
                pedantic: false,
                sanitize: true, // if false -> allow plain old HTML ;)
                smartLists: true,
                smartypants: false,
                highlight: function (code, lang) {
                  if (lang && hljs.getLanguage(lang)) {
                    return hljs.highlight(lang, code, true).value;
                  } else {
                    return hljs.highlightAuto(code).value;
                  }
                }
              });

    Hope it helps.

  3. joshbruce commented on Dec 25, 2017

    @joshbruce
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions