-
First of all: this is such a great framework and it really helps me to create nice slides using Latex / code in much less time than before. I am using VSCode extension and don't know much about CSS/HTML, but managed to create my own template using my own css theme. One thing I can't manage to do: is there a way to add line numbers to code blocks? something like this: 1: a = 3
2: b = 4
3: c = a * b Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
It cannot only in theme CSS + Marp for VS Code. It's a time to borrow a power of JavaScript with Marp CLI! Customize a Markdown engine with a Marp plugin. The engine in below has written a plugin inline. // engine.js
module.exports = ({ marp }) =>
marp.use(({ marpit }) => {
const { highlighter } = marpit
// Override Marp Core's highlighter to wrap each lines by ordered list items
marpit.highlighter = (...args) => {
const original = highlighter(...args)
const listItems = original
.split(/\n(?!$)/) // Don't split at the trailing newline
.map((line) => `<li>${line}</li>`)
return `<ol>${listItems.join('')}</ol>`
}
}) And contain its style to either of Markdown or theme CSS: ```javascript
a = 3
b = 4
c = a * b
```
<style>
pre ol {
all: unset;
display: block;
counter-reset: line-number 0;
}
pre ol li {
all: unset;
display: list-item;
list-style: none;
}
pre ol li::before {
content: counter(line-number) ": ";
counter-increment: line-number;
}
</style> And convert Markdown by using Marp CLI. It works!
|
Beta Was this translation helpful? Give feedback.
It cannot only in theme CSS + Marp for VS Code. It's a time to borrow a power of JavaScript with Marp CLI!
Customize a Markdown engine with a Marp plugin. The engine in below has written a plugin inline.
And contain its styl…