Comments (7)
Attempted this with a fenced code block, but highlighting is still not present.
from markdown-it.
@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.
Could we add to the README a reference to this or to https://highlightjs.org/#usage ?
from markdown-it.
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.
sure
from markdown-it.
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.
Closing as not a bug.
from markdown-it.
Related Issues (20)
- Quadratic output size explosion with tables extension HOT 1
- Convenient way to use markdown-it via cdn? HOT 1
- “Propuesta de Integración de Funcionalidad de Comentarios en la Plataforma de Blog XYZ”
- Improve code in `state_inline.mjs` HOT 1
- Table parsing does not work HOT 3
- Is it possible to get col number and row number of each token? HOT 1
- isString is not a function HOT 1
- bold render error HOT 1
- crash when input has brackets without parentheses HOT 1
- inline html transform error HOT 3
- Bold can not be rendered with punctuation marks HOT 1
- Disabling the "code" rule doesn't disable code parsing, just code rendering
- Nested numbering not working as expected HOT 1
- How can I custom renderer tag? HOT 4
- Error parsing numbered bullet in Markdown HOT 1
- Is this a markdown-it thing or a commonmark thing? HOT 3
- Certain tables under bullet points are not rendered HOT 7
- When a math fence immediately follows text, the resulting tokens are multiplied HOT 4
- Regression with v14.1.0 regarding ~~strikethrough text~~ HOT 1
- Inserting a link in markdown with underscore HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown-it.