Lukasa / language-restructuredtext

A ReStructuredText syntax package for Atom
MIT License
27 stars 15 forks source link

Use of "<<" permanently turns on monospaced highlighting #71

Closed andy-maier closed 2 years ago

andy-maier commented 2 years ago

Consider the following example .rst file:

Paragraph 1

``monospaced``

.. code-block:: sh

    $ cat >py.sh <<EOT
    #!/bin/bash
    py=$(which python)
    $py "$@"
    EOT

``monospaced``

Paragraph 2

Atom when using this package highlights this incorrectly. Anything after the << gets highlighted in green (same as text in double backquotes). Usage of double backquotes after that does not reset this highlighting.

Screen shot how the above file is highlighted:

Screenshot 2021-12-14 at 11 40 46

When I remove one of the two < characters, the highlighting is correct again, so this is clearly triggered by the presence of two <<:

Screenshot 2021-12-14 at 11 43 25
Alhadis commented 2 years ago

👋 Hey mate, sorry for the slow response.

This is actually the fault of Atom's shell-script grammar: specifically, the rules responsible for matching here-docs. A workaround hack is to use .. as a here-doc delimiter instead of EOT:

.. code-block:: sh

    $ cat >py.sh <<..
    #!/bin/bash
    py=$(which python)
    $py "$@"
    ..
..

`Link <link.html>`_

This works because .. introduces a comment in reStructuredText, while the embedded shell-script continues behaving as if it were written like this:

#!/bin/sh
set -e

# Note the strange indentation below: this is what Atom's
# shell grammar sees when it highlights the "indented"
# code-sample in reStructuredText:
    cat >py.sh <<END
    #!/bin/bash
    py=$(which python)
    $py "$@"
END

This could've been fixed on Atom's end, had I responded before they announced the editor's retirement by end-of-year.