SublimeText Markdown Extended add Roman Number Highlighting

In this question, I've inquired about how to highlight more than one markdown list punctuation item. I now want to extend the highlighting to roman numbers as well, because those are supported by Pandoc's extensions, which I use to create PDFs from markdown source.

In the Markdown Extended syntax definition, in line 1180, I've inserted the following regex:

^\s{0,4}([0-9]+|[ivxlcdm]+|[IVXLCDM]+)\.(?=\s\w)

Now it looks like this:

list-paragraph:
- match: \G\s+(?=\S) push: - meta_scope: meta.paragraph.list.markdown - match: ^\s*$ pop: true - match: '^\s{0,4}([*+-])(?=\s)' scope: punctuation.definition.list_item.markdown - match: '^\s{0,4}([0-9]+|[ivxlcdm]+|[IVXLCDM]+)\.(?=\s\w)' captures: 1: punctuation.definition.list_item.markdown punctuation.definition.list_item.number.markdown 2: punctuation.definition.list_item.markdown - include: inline

I understand, that this doesn't take validity of the roman numbers into account, but I'm going to type them correctly anyway, so I con't care i it highlights other invalid roman numbers as well. Also once a list in markdown starts with a valid number, usually i., the numbering in automatically calculated by Pandoc, when it creates the PDF, so that one could type i. 10 times, and it would still be roman numbers from 1 to 10 in the PDF.

I checked this regular expression with the Online regex tester and debugger. The mode I used is mg, because I read the following on the SublimeText websites:

Regexes are only ever run against a single line of text at a time.

g makes the matching going on after finding a match.m makes the matching consider ^ as beginning of the line and $ as the end of the line.

This is what I understand SublimeText does internally.

My test text is the following:

## Normal Equation
When the number of features for an $x^{(i)}$ of the training data is not too high, maybe lower than $9000$, an alternative way to [gradient descent](#gradient-descent-algorithm) for solving the optimization problem of the [cost function](#cost-function), using the normal equation, is feasible.
The vector $\theta$, which contains the coefficients for the hypothesis function can be optimized in one step using the following formula:
$$\theta = (X^T X)^{-1} X^T y$$
Where $X$ is a matrix, is constructed as follows:
+as
+ as
-as
-asa
* asas
* asas
asas
1.
2. 1212
3. 1212
qqq
I. asas
II. asa
III. asa
qqq
i. sa
ii. 1212
iii. asas
asdasd *asasas* 1. sadqwqe. *This is fat text!* **double** ewwrew ass a as as asa aas asasasas 1. ewr34 43543

The test of the regex is completely successful, it highlights exactly as I want it to. However, when I paste it into the syntax definition of Markdown Extended, roman numbers stay white, are not highlighted.

Example screenshot:

screenshot of sublimetext not highlighting roman numbers

So I don't know what's wrong with the regex. How do I need to change it, to also include roman numbers (not necessarily correct, valid roman numbers)?

Additional Info

  • SublimeText version: 3103
  • OS: Xubuntu 14.04

1 Answer

The regex itself works fine, but is never triggered in numbered lists. You also have to adapt the regex in line 693 to '^[ ]{0,3}([0-9]+|[ivxlcdm]+|[IVXLCDM]+)(\.)(?=\s)'. In this line the list-paragraph context is pushed. However you should be aware, that this will also be highlighted (and is already highlighted):

1. ...
ii. ...

If want to avoid this you could add a context list-paragraph-roman and push that for roman numbers.

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like