Sublime syntax: Parse two consecutive lines

97 views Asked by At

With the .sublime-syntax format, how would you match the following:

This is a title
===============

This is valid Markdown and AsciiDoc, and maybe also reStructuredText.

How would you match this as a section heading? This is a title here, without knowing the next line, could also be the beginning of a paragraph, hence the challenging ambiguity: at this point, you can't make it part of a heading scope.

2

There are 2 answers

1
Keith Hall On BEST ANSWER

This is currently not possible, which is why the Markdown syntax definition that ships with ST can only scope the underline characters as a heading, and not the heading text itself.

There is a feature request for multiline match support in .sublime-syntax files here: https://github.com/SublimeTextIssues/Core/issues/1693

1
Jan On

You could use

^(.+)[\n\r](?=^=+$)

This matches a line only if the next line only consists of = and nothing else.
You'll need the multiline flag here, see a demo on regex101.com. This is set via (?m) at the very start of the pattern in Sublime, see the image below.

Sublime regex with multiline