simov / markdown-viewer

Markdown Viewer / Browser Extension
MIT License
1.05k stars 133 forks source link

Code block render tab incorrectly #120

Open albertyckwok opened 4 years ago

albertyckwok commented 4 years ago

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

simov commented 4 years ago

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

albertyckwok commented 4 years ago

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>
simov commented 4 years ago

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.

albertyckwok commented 4 years ago

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.