marshallward / vim-restructuredtext

Syntax file for reStructuredText on Vim.
26 stars 12 forks source link

Incorrect highlighting of lines following embedded directive #53

Open smackesey opened 4 years ago

smackesey commented 4 years ago

The lines following a directive embedded in a definition list definition are not correctly highlighted. See screenshot:

highlight

The "yada yada yada" should not be highlighted as if it were part of the directive, as it is not at the indentation level to include it in the directive.

marshallward commented 4 years ago

Thanks for reporting this, I can reproduce it.

This has been a longstanding problem (see #3, probably others), but fortunately we have found a way to fix it in literal blocks (see this example file).

The method has not yet been extended to code blocks and other but it should be use the same technique to fix this.

marshallward commented 4 years ago

These are mostly notes to myself, but might be helpful to anyone interested.

Directives are going through the "old" methods, which rely on the rstExplicitMarkup = ^\s*\.\.\_s match to begin any directive. The disadvantage is that we then discard this leading whitespace in subsequent matches and are unable to align.

Some steps were taken to address this in .. code:: directives (rstCodeBlock), but were always somewhat incomplete and were never extended to more general directives (rstExDirective).

This was revised in the rstLiteralBlock region by tracking this whitespace (in a \z group, followed by a \@<= to do a back-match) and using it in the end match. One of the reasons we could tackle this separately is because it never relied on rstExplicitMarkup.

The technique ought to work in other groups, but would need to be applied in some way which either modifies, replaces, or abandons the rstExplicitMarkup match.

Some decisions need to be made here, but it should be possible to resolve all of these cases in the same way.

(Also worth noting that use of \@<= is generally discouraged because of bad performance, so something to watch out for if this is ever addressed.)