reST: handle some more corner cases, add an actual test file
ClosedPublic

Authored by mosra on Aug 24 2019, 1:33 PM.

Details

Summary

I'm writing reST quite a lot and finally got to the point where I had to submit a patch :) While doing so, I discovered there was an unmerged https://phabricator.kde.org/D7245 which lacked a test file. This one *does* have a test file but compared to the other patch doesn't add the default / Sphinx directives / roles since I don't personally have any use for these. Adding everyone involved with the other patch as a reviewer here, hope that's okay :)

  • Both .. code-block:: and .. code:: are valid, the former is a Sphinx thing, while .. code :: is a reStructuredText builtin.
  • Directives, interpreted text roles and fields can contain : in the name. Used very often by Sphinx and CMake docs. Until now, things like .. py:function:: were treated as comments. Colons in field names are *not* handled by this patch, as the handling in the highlighting file is non-trivial, I am completely new to this and thus have a fear of breaking things :)
  • A .. alone on a line is a comment too, doesn't need to be followed by a space. This also makes it work for multi-line comments where the first line is just a ...
  • Highlighting default interpreted text role (single backticks) similarly to named roles.

The CMake test was the only place testing for reST highlighting, referencing the umerged https://phabricator.kde.org/D7245, updated it accordingly and removed the patch reference since the problems shown there are fixed by this patch.

The test for reST contains some additional things like block quotes, lists, definition lists etc., which are currently not highlighted (but e.g. Markdown highlighter handles them). This test data might be useful for further improvements to the highlighter.

Test Plan

Look at the HTML output of the test file, plus compare the before/after CMake highlighting.

Diff Detail

Repository
R216 Syntax Highlighting
Lint
Lint Skipped
Unit
Unit Tests Skipped
mosra created this revision.Aug 24 2019, 1:33 PM
Restricted Application added projects: Kate, Frameworks. · View Herald TranscriptAug 24 2019, 1:33 PM
Restricted Application added subscribers: kde-frameworks-devel, kwrite-devel. · View Herald Transcript
mosra requested review of this revision.Aug 24 2019, 1:33 PM

Nice, can you increase the "version" number in the language xml element such that we uniquely can identify the version? This is helpful, since older versions of Kate allow to download updates via the settings dialog.

mosra updated this revision to Diff 64515.Aug 24 2019, 8:31 PM

Bumped the version.

cullmann accepted this revision.Aug 25 2019, 6:37 PM

Feel free to push this.
(if you have no commit rights, please provide name + mail address, then we push)

This revision is now accepted and ready to land.Aug 25 2019, 6:37 PM
mosra updated this revision to Diff 64694.Aug 26 2019, 7:09 PM

Hmm, actually during use I discovered that the newly added "default role" was marking everything after the backticks as a role... and the test file was crafted in a way that didn't make that visible. Sorry for submitting too fast :)

Updated the patch to fix this (adding an explicit DefaultRole now), also adapting the test file and outputs. And unified the regexps between directives and roles to handle the internal colons the same in both cases.

I don't have commit rights, the name + e-mail I'm using is Vladimír Vondruš <mosra@centrum.cz>. Thank you!

cullmann accepted this revision.Aug 26 2019, 7:36 PM

Looks better, right. thanks!

This revision was automatically updated to reflect the committed changes.