-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Literal block continues too far after bullet #56
Comments
Thanks, this is a longstanding problem with many of the blocks, due to difficulties with counting whitespace in VimL. This is now resolved for literal blocks, e.g.:
but the technique does not get correctly passed through all such structures, including lists, and needs to be ported to many of the other blocks. Unfortunately this will take some structural rewrites and hasn't happened yet. But thanks for raising this and hopefully some time will be found to return to the problem. |
It looks like the issue is that there is no special handling of lists, which are treated as regular text. So the line is handled as if it is a block beginning at column 0, and the two indents are part of the same block. So it is at least "working" in that sense. (Edit: to clarify, the following would be correctly highlighted if the list element were removed.)
(I am not sure why it was working prior to 796536c but I recall we used to start comparing whitespace at the first indented line, which was incorrect, rather that the line prior to indentation) If one could start the offset calculation from the first non-blank character after the list token then this should probably work. I don't know how aware one needs to be that they are inside a list element, however. I will keep looking. |
Thanks; I appreciate your taking a look at this. |
I made an attempt to fix this, but cannot yet resolve it. Currently we begin the block by looking for leading spaces, specifically this:
which lets us save the whitespace into This fails because the
I'm now forced to include this dash into the criterion for terminating the block, which is not what I want. The closest I got was to use two groups before and after the slash, e.g.:
and then replace the
which works great for lists, but now requires a redundant space for non-list blocks. What I really want is some ability to replace, say, Any suggestions would be appreciated here. |
I don't have much experience writing syntax files. I have the start of an idea, but I don't know how it might interact with the rest of the syntax logic. I adjusted the syn region rstLiteralBlock matchgroup=rstDelimiter
\ start='\(^\z(\s*\)\(-\z( \)\z( *\)\)\?.*\)\@<=::\n\s*\n' skip='^\s*$' end='^\(\z1\z2\z2\z3\s\+\)\@!'
\ contains=@NoSpell I've not done much testing with this, since I don't know if it's the right idea. |
Sorry for the very long delay, I finally got around to testing this and it appears to work well. I think the idea of using the subsequent space to replace the token is a very clever idea. It should not be difficult to replace If you'd like to submit this then I'm happy to merge it. But otherwise I can make the modification. |
Also I am unsure how to adapt this trick to enumerated lists, since this relies on the token being exactly one space, but this is better than what is currently being used. |
|
Actually, disregard that last issue. It seems that this was already happening with the current syntax file and is unrelated to the problem of literal blocks in list tokens. |
I'm happy to leave the actual commit in your hands, once you are happy with the results. I think I can extend the idea to include enumerated lists. A bullet list item is a single bullet character followed by at least one space. Enumerated lists have a lot more cases, but they all boil down to one or more "digits" (or letters or The bullet idea works because we know the bullet consumes exactly one character. If we could know a priori how many characters are in an enumeration list item before the single space, we could handle it the same way. Consider the case of a single-digit number followed by a period:
This has two characters before the single space. We can match on either the bullet case or this one-digit enumeration case as follows:
Since both branches of the In essence, this divides the cases into equivalence classes based on the number of non-space characters are found before the single space. In the example below, I'm handling only the hyphen as a bullet character and the case of "digits+period" for enumerations, but if this idea appeals to you, the other cases could be added. For a given number of non-space characters, only one Examples of n characters before the single space:
Here is an example that works for the hyphen-bullet and anything up to four digits followed by a period. It is quite possibly the most awful-looking Vimscript I've ever written. It deserves a page of comments providing explanation and/or apology :-) syn region rstLiteralBlock matchgroup=rstDelimiter
\ start='\(^\z(\s*\)\(-\z( \)\|\d\.\z( \)\|\d\d\.\z( \)\|\d\d\d\.\z( \)\|\d\d\d\d\.\z( \)\)\?\z( *\).*\)\@<=::\n\s*\n'
\ skip='^\s*$'
\ end='^\(\z1\z2\z2\z3\z3\z3\z4\z4\z4\z4\z5\z5\z5\z5\z5\z6\z6\z6\z6\z6\z6\z7\s\+\)\@!'
\ contains=@NoSpell By an interesting coincidence, the |
This is incredibly impressive, and (I think?) I can see how it would work, but it is pretty complex and might be too much work for what it is trying to achieve. If there is some simple way of identifying and grabbing the length of the enumerator, then it ought to be enough to manage the use case. |
Yes, in its current form it can make you cross-eyed to look at it. The source could be tidied up a good bit with some helper variables or functions to construct the regex, and as mentioned it would need some commenting. I think it's likely to work reasonably well (meaning I hope it's not overly slow to execute, and it fixes the erroneous highlighting for the practical cases). Unfortunately I have no idea how to build an |
This fixes literal block highlighting as explained in the ticket's example below: - A bullet with literal following:: Correctly highlighted literal Incorrectly highlighted as literal Correctly unhighlighted.
Literal block highlighting extends too far when the block is contained within a bullet, e.g.:
As I understand it from https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#bullet-lists, the indentation level for the body of the bullet is determined by the first non-whitespace character after the bullet character (starting at
A bullet with
above). The subsequent literal block must be indented relative to that, and that literal block should end when the additional indentation is removed (at the lineIncorrectly highlighted as literal
).Using the latest vim-restructuredtext, the line
Incorrectly highlighted as literal
is highlighted as a literal block.Using the
rst2html
command fromdocutils <https://docutils.sourceforge.io/>
, the above reStructuredText renders correctly as:Literal block highlighting worked correctly for such cases before 796536c.
The text was updated successfully, but these errors were encountered: