question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom syntax highlighter is never called

See original GitHub issue

Steps to reproduce:

  • Clone the Svelte template
  • Install mdsvex: yarn add -D mdsvex
  • Set up MDsveX in rollup.config.js:
// ...
import { mdsvex } from 'mdsvex';

export default {
  // ...
  plugins: [
    // ...
    svelte({
      extensions: ['.svelte', '.svx'],
      preprocess: mdsvex({
        highlight(code, _lang) {
          console.log('called');
          return `<pre>${code}</pre>`;
        }
      }),
    }),
// ...
  • Add an MDsveX file (src/test.svx) with the following content:
```js
alert()
```
  • Import the new file into src/App.svelte

Expected

called will be printed anywhere signifying that the highlighter was called

Actual

Nothing printed, the default highlighter is used

Also I’m wondering if there’s any simple way of stripping the initial newline that is rendered in the <pre>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pngwncommented, Jul 10, 2020

Looks like I didn’t update the docs. Highlight should be an object that accepts a highlighter property:

// ...
import { mdsvex } from 'mdsvex';

function highlighter(code, _lang) {
  console.log('called');
  return `<pre>${code}</pre>`;
}

export default {
  // ...
  plugins: [
    // ...
    svelte({
      extensions: ['.svelte', '.svx'],
      preprocess: mdsvex({
        highlight: { highlighter }
      }),
    }),
// ...

I’ll update the documentation.

Can you give an example for the initial newline you mentioned?

0reactions
pngwncommented, Aug 7, 2020

Fixed in #110.

Thanks @TheComputerM!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom syntax highlighting in vim for links
I have a plugin that I wrote called the ctags highlighter which does a fairly similar thing: it uses ctags to generate a...
Read more >
jgnewman/custom-syntax-highlighter: Define your own ...
Custom -syntax-highlighter will loop over your code blocks and wrap the matches it finds with spans that have the class name. This way,...
Read more >
Syntax Highlight Guide | Visual Studio Code Extension API
Syntax highlighting determines the color and style of source code displayed in the Visual Studio Code editor. It is responsible for colorizing keywords...
Read more >
react-syntax-highlighter-custom
syntax highlighting component for react with prismjs or highlightjs ast using inline styles. Latest version: 15.5.0, last published: 2 years ...
Read more >
Goodbye, Prettify. Hello highlight.js! Swapping out our ...
We are updating the client-side code block renderer that styles your code in posts (Questions, Answers, etc) and in the editor preview. Syntax...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found