Skip to content

[reST] refactor#4212

Draft
jrappen wants to merge 1 commit intosublimehq:masterfrom
jrappen:fix-rest
Draft

[reST] refactor#4212
jrappen wants to merge 1 commit intosublimehq:masterfrom
jrappen:fix-rest

Conversation

@jrappen
Copy link
Copy Markdown
Collaborator

@jrappen jrappen commented Apr 9, 2025

Note

⚠️ This PR is a work-in-progress. If you have suggestions for stuff that
should be fixed, leave a comment below.

Additions:

  • correctly hightlight directive options and their values as
    mapping.pair while checking value format
  • default keymap
  • symbol index now lists explicit and implicit hyperlink
    targets (sections, footnotes, citations)
  • highlight embedded python and raw-code directives (css, js, json,
    jsonc, html, python, toml, yaml), compare [reStructuredText] Code-blocks are not handled #3158
  • explicit hyperlink targets and anonymous explicit hyperlink
    targets
  • correctly highlight grid tables with optional inline markup
  • correctly highlight inline interpreted text, optionally
    with roles
  • correctly highlight substitution definitions
  • completions with strict scope limits
  • indentation settings based upon official docs
  • neg. tests for comments
  • highlight empty comments and section separators between empty
    lines
  • add metadata to enable folding
  • added window command to make selections a literal command
  • added window command to make selections an interpreted text role

Fixes:

  • line blocks (with optional inline markup)
  • footnotes and citations
  • pop explicit markup blocks before the next explicit markup block
  • correctly highlight (valid) comments as block comments
  • do not highlight paragraphs starting with ... as comments
  • include inline markup within block quotes
  • allowed symbols for heading markers, compare [reStructuredText] Headers using some of the supported characters aren't highlighted #2894
  • inline internal targets may contain symbol characters, compare
    [RestructuredText] single quotes break link targets #1204
  • inline hyperlink references
  • section headings:
    • with overline and underline
    • with underline only
    • optional inset when with overline and underline
  • literal blocks:
    • meta scope
    • literal blocks with expanded form
    • literal blocks with partially minimized form
    • literal blocks with fully minimized form
    • literal blocks with quoted form
  • enumerated lists
  • field lists
  • punctuation of inline substitution references
  • tests for embedded python
  • inline literal for single backtick

Changes:

  • the syntax file now uses branching to correctly highlight
    section headings and their punctuation
  • scope names have been adjusted with regard to the syntax
    scope naming guide
  • match punctuation.definition.end rules for inline items
    before invalid.illegal.newline
  • pop line blocks on empty line
  • pop explicit markup blocks before next explicit markup block
  • moved some rules from block-quote-block context to literal-block
  • removed inline markup from literal blocks
  • updated list of allowed characters for internal link labels,
    compare [reST] Internal link labels should allow more character types #793
  • changed auto_complete_selector default
  • re-ordered test file to match order of syntax file
  • include linebreak in match for first line of directives
  • differentiate known (constant.language) and unknown (constant.other)
    directive names

BREAKING CHANGES:

  • this pull request requires py3.13 and Sublime Text v4201+

References:

Thanks to these contributors:

@jrappen jrappen force-pushed the fix-rest branch 5 times, most recently from b40f0f7 to 8817eaf Compare April 14, 2025 19:05
@jrappen jrappen force-pushed the fix-rest branch 8 times, most recently from 72e437b to ae329e0 Compare May 4, 2025 19:26
@giampaolo

This comment was marked as resolved.

@jrappen jrappen force-pushed the fix-rest branch 2 times, most recently from 843a5bc to 0607aca Compare May 19, 2025 12:51
@jrappen jrappen force-pushed the fix-rest branch 3 times, most recently from ebfb8c4 to c34db53 Compare May 24, 2025 15:53
@jrappen jrappen force-pushed the fix-rest branch 8 times, most recently from 6bfcc32 to 5d0438e Compare May 26, 2025 13:55
@vwheeler63

This comment was marked as resolved.

@vwheeler63
Copy link
Copy Markdown
Contributor

vwheeler63 commented Jul 2, 2025

@jrappen More syntax bugs:

  • I think I found a good one for you. I just encountered this. I don't understand why that whole section is blue and underlined. I'm guessing a run-away regex?

    .. _sometext:
    
    Subsection heading
    ******************
    
    .. note:
      more text

  • With inline literals within a paragraph that span across a line break:

    Some text ``inline
    literal`` more text.

    image

@sublimehq sublimehq deleted a comment from vwheeler63 Jul 4, 2025
@sublimehq sublimehq deleted a comment from vwheeler63 Jul 4, 2025
@sublimehq sublimehq deleted a comment from vwheeler63 Jul 4, 2025
@sublimehq sublimehq deleted a comment from vwheeler63 Jul 4, 2025
@sublimehq sublimehq deleted a comment from vwheeler63 Jul 4, 2025
@sublimehq sublimehq deleted a comment from vwheeler63 Jul 4, 2025
@sublimehq sublimehq deleted a comment from vwheeler63 Jul 4, 2025
@jrappen

This comment was marked as resolved.

@vwheeler63

This comment was marked as resolved.

@vwheeler63

This comment was marked as resolved.

@jrappen

This comment was marked as resolved.

@vwheeler63

This comment was marked as resolved.

@vwheeler63

This comment was marked as resolved.

@vwheeler63
Copy link
Copy Markdown
Contributor

vwheeler63 commented Nov 20, 2025

@jrappen

Also as a reminder, the https://sphinx-themes.org/sample-sites/furo/kitchen-sink/ web page has several sub-pages that by clicking the "eye" icon, you can get to the .rst source code. And they are real, production-quality reST examples of a wide variety of reST formatting, that if I were you, I would be using for test files for syntax-highlighting and formatting tests!

You're also welcome to use the docs at LVGL User Documentation for some production-quality .rst docs to use for testing.

@jrappen

This comment was marked as resolved.

@vwheeler63

This comment was marked as resolved.

@jrappen
Copy link
Copy Markdown
Collaborator Author

jrappen commented Nov 22, 2025

Excluded punctuation from explicit hyperlink target symbols in latest force-push.

@jrappen
Copy link
Copy Markdown
Collaborator Author

jrappen commented Dec 12, 2025

Added requested custom window commands.

@vwheeler63

This comment was marked as resolved.

@vwheeler63
Copy link
Copy Markdown
Contributor

Hi, @jrappen !

I finally got around to putting this branch in my Packages/RestructuredText/ directory and a few things still aren't working correctly. I have found 2 so far and they are below.

  1. This seems to be being triggered by the link target above the title:

    image
  2. Given this external link target

    .. _Format Specification Mini-Language:  https://docs.python.org/3/library/string.html#formatspec

    the link reference is still displayed un-highlighted with the hyphen (which is legal):

    image

    whereas if I make it into a space, it IS highlighted:

    image

@giampaolo
Copy link
Copy Markdown

giampaolo commented Mar 25, 2026

Hi @jrappen. In my own override of the RsT syntax I'm using this:

    # class directive
    - match: '^(\s*)((\.\.)\s+class(::))\s+(?:\w+\.)*(\w+)'
      captures:
        2: meta.other.directive.restructuredtext
        3: punctuation.definition.directive.restructuredtext
        4: punctuation.separator.key-value.restructuredtext
        5: entity.name.class.restructuredtext
      push:
        - match: '^(?!\1\s+)(?=\s*\S+)'
          pop: true
        - include: inline

    # method directive
    - match: '^(\s*)((\.\.)\s+method(::))\s+(?:\w+\.)*(\w+)'
      captures:
        2: meta.other.directive.restructuredtext
        3: punctuation.definition.directive.restructuredtext
        4: punctuation.separator.key-value.restructuredtext
        5: entity.name.function.restructuredtext
      push:
        - match: '^(?!\1\s+)(?=\s*\S+)'
          pop: true
        - include: inline

    # function directive
    - match: '^(\s*)((\.\.)\s+function(::))\s+(?:\w+\.)*(\w+)'
      captures:
        2: meta.other.directive.restructuredtext
        3: punctuation.definition.directive.restructuredtext
        4: punctuation.separator.key-value.restructuredtext
        5: entity.name.function.restructuredtext
      push:
        - match: '^(?!\1\s+)(?=\s*\S+)'
          pop: true
        - include: inline

    # data directive
    - match: '^(\s*)((\.\.)\s+data(::))\s+(?:\w+\.)*(\w+)'
      captures:
        2: meta.other.directive.restructuredtext
        3: punctuation.definition.directive.restructuredtext
        4: punctuation.separator.key-value.restructuredtext
        5: entity.name.constant.restructuredtext
      push:
        - match: '^(?!\1\s+)(?=\s*\S+)'
          pop: true
        - include: inline

    # attribute directive
    - match: '^(\s*)((\.\.)\s+attribute(::))\s+(?:\w+\.)*(\w+)'
      captures:
        2: meta.other.directive.restructuredtext
        3: punctuation.definition.directive.restructuredtext
        4: punctuation.separator.key-value.restructuredtext
        5: entity.name.attribute.restructuredtext
      push:
        - match: '^(?!\1\s+)(?=\s*\S+)'
          pop: true
        - include: inline

With this I can highlight all the functions / methods / classes / attributes / CONSTANTs.

image

But most importantly, with this I can navigate the symbols of the .rst doc (show_overlay -> goto -> @).

Do you think you can integrate it into your work?

@jrappen
Copy link
Copy Markdown
Collaborator Author

jrappen commented Mar 25, 2026

Appreciate the feedback, will take another look later tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

5 participants