0

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.

eepp
  • 7,255
  • 1
  • 38
  • 56

2 Answers2

0

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

Jan
  • 42,290
  • 8
  • 54
  • 79
  • Yes, it works for searching, because you can expect some waiting time when searching since it is a punctual operation. But because syntax highlighting is something that is triggered every time you type and potentially scroll, the lexer has optimizations which make it faster but need multiline matching to be disabled. – eepp Jan 25 '18 at 21:45
0

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

Keith Hall
  • 15,362
  • 3
  • 53
  • 71