markdown-viewer icon indicating copy to clipboard operation
markdown-viewer copied to clipboard

Code block render tab incorrectly

Open albertyckwok opened this issue 5 years ago • 4 comments
trafficstars

The tab character is render as 4 spaces instead of 8. Here is the test code block:

`123456789`
`<tab>9`

The following how it is rendered:

`123456789`
`    9`

The expect the result is:

`123456789`
`        9`

Thanks very much in advance Albert

albertyckwok avatar May 22 '20 17:05 albertyckwok

That's controlled by the internal library used for syntax highlighting called Prism. Probably this plugin could help with configuring that aspect of it.

simov avatar May 23 '20 12:05 simov

Thanks @simov, Do you know if it is possible to imbed JavaScript code in MK. According to the link, I need to put the following code in but it didn't seem to work.

<script type="text/javascript">
// Optional
Prism.plugins.NormalizeWhitespace.setDefaults({
        'tabs-to-spaces': 4,
});
</script>

albertyckwok avatar May 26 '20 21:05 albertyckwok

First you need to include the plugin with a <script> tag I think, because it's not part of what I have bundled with Prism.

For example see how I'm including MathJax in the content script. So in your case it have to be:

dom.push(m('script', {
  src: 'https://the-prism-plugin.js'
}))
dom.push(m('script', `
  Prism.plugins.NormalizeWhitespace.setDefaults({
          'tabs-to-spaces': 4,
  });
`))

And then you have to load the extension from your local fork instead.

Of course I can't tell with 100% certainty that it is going to work, but worth a try.

simov avatar May 27 '20 05:05 simov

Thanks @simov, I will look into forking the code. I am setting vim with expandtab so that my team mates don't have to load my forked plugging.

albertyckwok avatar Jun 03 '20 15:06 albertyckwok