vim-pandoc-syntax icon indicating copy to clipboard operation
vim-pandoc-syntax copied to clipboard

Syntax error in tagged code block breaks highlighting outside the code block.

Open nybblr opened this issue 5 years ago • 5 comments

Hey folks, I'm using vim-pandoc for editing a coding book. Most of the book is incomplete JavaScript code samples. It seems that when there is a syntax error in a marked code snippet — such as a missing parenthesis or curly — it breaks all following syntax highlighting. Here's an example:

# Hello world

Here's a code block with a syntax error:

```javascript
let app = express();
app.use((req, res) => {
  /* ... */
```

When I continue afterwards, the `missing` parenthesis and *curly* break syntax highlighting outside the code block.

Since the book is primarily made of incomplete snippets, it's tricky to workaround and makes it difficult to spellcheck or spot other errors.

Thoughts? Is this a can of worms in Vim's syntax highlighting engine?

nybblr avatar May 15 '19 14:05 nybblr

It seems like this is problematic even for github's markdown parser ;)

Some embedded syntax files can create this kind of conflict, there isn't really anything that can be done as a general fix really (the solution would be to fix the javascript syntax so that it behaves differently when it is embedded, but it's not obvious how do to it...) :(

fmoralesc avatar May 15 '19 14:05 fmoralesc

Does vim really not let us limit the scope of any applicable embedded rules based on our rules for where the scope ends?

alerque avatar May 15 '19 15:05 alerque

Not really. Some cases are just pathological. I remember a case where ruby or perl embeds would cause this sort of thing. The problem is that in some cases the match doesn't terminate, and the highlighting doesn't yield (I think the underlying issue is the same that we have when a rule fails and it ends breaking the rest of the file...).

fmoralesc avatar May 15 '19 15:05 fmoralesc

@nybblr Apparently the answer is "this is a can of worms". See also #236.

I poked around a little and it looks like Neovim issue 9876 is one thing to keep an eye on. Also we've talked before about using Pandoc itself to determine the block context, but that would require implementing the change noted in Pandoc issue 4565. Neither of these things help you with your project right now, but we'll be keeping an eye on them for the long term.

alerque avatar May 16 '19 08:05 alerque

Ooo, I am intrigued, thanks for poking around @alerque.

nybblr avatar May 16 '19 17:05 nybblr