1

Following naive snippet highlights such headers:

syn match asciidoctorH1 "^\_s*\n\a.*\n====*"
syn match asciidoctorH2 "^\_s*\n\a.*\n----*"

hi link asciidoctorH1 Title
hi link asciidoctorH2 Title

But for asciidoc(tor) it is incorrect. The issue is in length of the dashes -- it should be exactly the same as text above it:

correct:

test header
===========

he world
--------

incorrect (shouldn't be highlighted):

test header
=======

he world
-----------

Basically, is there a way to find the length of the text above dashes and apply it to dashes? Or any other way to do it?

enter image description here

  • Not really, it looks for the way to add underlines to text, which is kind of simple. – Maxim Kim Nov 29 '19 at 16:20
  • @BLayer, I didn't think it was related but I am not an expert so don't take my comments too close. – Maxim Kim Nov 29 '19 at 16:44
  • Never mind. I didn't post it to start a debate. – B Layer Nov 29 '19 at 16:48
2

You're running into the limitations of the regular expression-based syntax highlighting here. Though you can refer to previously matched text (:help /\1), you cannot assert on the same number of characters or modify (turn all characters into literal = matches) with it. The only option I see would be enumerating all likely lengths separately:

syn match asciidoctorH1 "^\_s*\n\a.\{3}\n=\{4}$\|^\_s*\n\a.\{4}\n=\{5}$\|..."

That probably won't perform well, though :-(

| improve this answer | |
  • I was hoping there is a way and it was just me not able to find the right way to do it. Enumeration would be too much for that, probably I will just highlight headers no matter what number of dashes there are. – Maxim Kim Nov 29 '19 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.