zestedesavoir / zmarkdown

Live demo: https://zestedesavoir.github.io/zmarkdown/
MIT License
226 stars 53 forks source link

Allow inverted ranges in hl_lines #415

Closed AmauryCarrade closed 4 years ago

AmauryCarrade commented 4 years ago

The parser won't crash if the range is entered inverted by the user, i.e. hl_lines=2-1 instead of hl_lines=1-2. In this example, lines 1 and 2 will be highlighted.

Fixes #414.

Notes

AmauryCarrade commented 4 years ago

Thanks for these detailed instructions! I added LaTeX support and tests according to what you said. I added a dedicated test in the LaTeX part to avoid cluttering the other one too much.

For the LaTeX part, I made the decision to keep invalid ranges as-is; as example, the following:

```python hl_lines=2-1,4-
def true():
    return False

True = true()

yields the following:

```latex
\begin{CodeBlock}[][1-2,4-]{python}
def true():
    return False

True = true()
\end{CodeBlock}

But I can easily remove such ranges if you think it's better (yielding only \begin{CodeBlock}[][1-2]{python}, in this example).


Edit: according to the diff, my editor reformatted the test JS files, removing lots of trailing spaces. It does not break any test as most of them are removed by the dedent tag. But I can revert these if you wish.

AmauryCarrade commented 4 years ago

Here we go. I probably missed something as the tests no longer pass. I'll check that. Everything's fine now.

StaloneLab commented 4 years ago

Woah, didn't think Babel would add that level of craziness into the machine. Anyway it's merged and ready for the next version of ZMarkdown (10.0.0). Thanks!

AmauryCarrade commented 4 years ago

I wasn't expecting this either. :D But it's harmless. Thanks!