Giter VIP home page Giter VIP logo

Comments (7)

david-mcafee avatar david-mcafee commented on June 2, 2024 2

Attempted this with a fenced code block, but highlighting is still not present.

from markdown-it.

mbaraa avatar mbaraa commented on June 2, 2024 1

@kristijorgji of course it won't work, you're not importing a highlighting style (alongside fencing the code)
for example using solarized dark

import "highlight.js/styles/base16/solarized-dark.css";

I forgot where I found it, but here is an example of where I used it, also if you take a look at the directory highlight.js/styles/ you'll find a ton of other highlighting themes.

Hope I helped!

from markdown-it.

gillo04 avatar gillo04 commented on June 2, 2024 1

Could we add to the README a reference to this or to https://highlightjs.org/#usage ?

from markdown-it.

rlidwka avatar rlidwka commented on June 2, 2024

Are you expecting that: .render('<pre>const a = 2; console.log(a);</pre>); to be highlighted?

Syntax highlighting works only for fenced code blocks like this:

```js
const a = 2; console.log(a);
```

from markdown-it.

mbaraa avatar mbaraa commented on June 2, 2024

sure

from markdown-it.

cris-m avatar cris-m commented on June 2, 2024

I faced the same issue. I noticed that hljs.getLanguage(lang) always return undefined.

const md = new MarkdownIt({
            html: true,
            linkify: true,
            quotes: '“”‘’',
            // langPrefix: 'language-',
            typographer: true,
            highlight: (str, lang) => {
                console.log(hljs.getLanguage(lang))
                if (lang && hljs.getLanguage(lang)) {
                    try {
                        return '<pre class="hljs"><code>' +
                            hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
                            '</code></pre>';
                    } catch (__) {}
                }

                return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
            },
        });

you need to register the language you want to highlight otherwise it will return undefined

hljs.registerLanguage('javascript', require('highlight.js/lib/languages/javascript'));        
hljs.registerLanguage('json', require('highlight.js/lib/languages/json'));

from markdown-it.

puzrin avatar puzrin commented on June 2, 2024

#946 (comment)

Closing as not a bug.

from markdown-it.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.