-
Notifications
You must be signed in to change notification settings - Fork 592
[reST] refactor #4212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[reST] refactor #4212
Conversation
b40f0f7
to
8817eaf
Compare
72e437b
to
ae329e0
Compare
Thanks a lot for taking care of this.
Example file having lots of these: https://raw.githubusercontent.com/giampaolo/psutil/refs/heads/master/HISTORY.rst. |
843a5bc
to
0607aca
Compare
ebfb8c4
to
c34db53
Compare
6bfcc32
to
5d0438e
Compare
Hello, @jrappen ! Good morning! And thank you for the invitation in sublimetext-io/docs.sublimetext.io#131. My name is Vic. I have been implementing these import sublime
import sublime_plugin
class VicsRstEncapsulateFieldCommand(sublime_plugin.TextCommand):
"""
If (conditions applied in keymap):
- we are in a reStructuredText source file, and
- all selections have some text selected
then wrap the selected text like this:
:selected text:
"""
def run(self, edit):
sel_list = self.view.sel()
# Replace each selection with edited string.
for rgn in reversed(sel_list):
selected_text = self.view.substr(rgn)
new_text = ':' + selected_text + ':'
self.view.replace(edit, rgn, new_text)
# De-select each selection, leaving cursor on right edge of its
# previous selection. This avoids the danger of a stray keystroke
# wiping out the new text.
for i, rgn in enumerate(sel_list):
del sel_list[i]
sel_list.add(sublime.Region(rgn.end()))
class VicsRstEncapsulateLiteralCommand(sublime_plugin.TextCommand):
"""
If (conditions applied in keymap):
- we are in a reStructuredText source file, and
- all selections have some text selected
then wrap the selected text like this:
``selected text``
"""
def run(self, edit):
sel_list = self.view.sel()
# Replace each selection with edited string.
for rgn in reversed(sel_list):
selected_text = self.view.substr(rgn)
new_text = '``' + selected_text + '``'
self.view.replace(edit, rgn, new_text)
# De-select each selection, leaving cursor on right edge of its
# previous selection. This avoids the danger of a stray keystroke
# wiping out the new text.
for i, rgn in enumerate(sel_list):
del sel_list[i]
sel_list.add(sublime.Region(rgn.end()))
class VicsRstEncapsulateInterpretedTextRoleCommand(sublime_plugin.TextCommand):
"""
If (conditions applied in keymap):
- we are in a reStructuredText source file, and
- all selections have some text selected
then wrap the selected text like this:
:role_name:`selected text`
"""
def run(self, edit, role_name):
sel_list = self.view.sel()
# Replace each selection with edited string.
for rgn in reversed(sel_list):
selected_text = self.view.substr(rgn)
new_text = f':{role_name}:`{selected_text}`'
self.view.replace(edit, rgn, new_text)
# De-select each selection, leaving cursor on right edge of its
# previous selection. This avoids the danger of a stray keystroke
# wiping out the new text.
for i, rgn in enumerate(sel_list):
del sel_list[i]
sel_list.add(sublime.Region(rgn.end())) // --------------------------------------------------------------------
// reStructuredText Tools
// --------------------------------------------------------------------
{
"keys": ["ctrl+alt+f"],
"command": "vics_rst_encapsulate_field",
"context":
[
{ "key": "selector", "operand": "text.restructuredtext"},
{ "key": "selection_empty", "operand": false, "match_all": true },
]
},
{
"keys": ["ctrl+alt+l"], // Lower-case 'L'
"command": "vics_rst_encapsulate_literal",
"context":
[
{ "key": "selector", "operand": "text.restructuredtext"},
{ "key": "selection_empty", "operand": false, "match_all": true },
]
},
{
"keys": ["ctrl+alt+t"],
"command": "vics_rst_encapsulate_interpreted_text_role",
"args": {
"role_name": "term"
},
"context":
[
{ "key": "selector", "operand": "text.restructuredtext"},
{ "key": "selection_empty", "operand": false, "match_all": true },
]
}, Use Case for
|
Not at all.
It's not in one place, but what the Sphinx doc guys did is they let the Docutils documentation handle the basics, and the Sphinx docs (e.g. Directives, Interpreted Text Roles, etc.) only documents things that Sphinx added (or significantly changed), which IMO, VERY much helps the reader understand what Sphinx contributed to the |
9afd1f3
to
3f8b966
Compare
fb4416a
to
b1042a2
Compare
https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#block-quotes |
@jrappen May I make a suggestion? Wherever you aren't already doing so, I suggest OR-ing in the following scope into the "context" conditions wherever they apply:
😄 I was just editing the header block comment of a significant Python, putting Thus...
It is my understanding that grouping using parentheses works, but now I can't find the documentation on it.... |
What is not working as expected? Can you give a code example? I don't understand what you want to do. |
I guess he want's reST highlighting in python documentation comments. This would require to remove various restrictions with regards to leading whitespace on the one hand and may cause confusion in python comments on the other hand. Even though RST is still used for Sphinx, I've also already seen Markdown. I wouldn't add highlighting in comments by default. |
For what it's worth, this maintainer of CPython confirms that the |
Confirmed, it's not the highlighting I am after, but the Key Bindings would be highly useful! Edit: ...and completions and whatever else is applicable. Not highlighting. |
To illustrate, this is in the documentation section of one of my Data Flow
---------
.. code-block:: text
Inputs Generated Source Files Output
----------- ---------------------- ----------------------
./docs/src/ \
./src/ >===> ./docs/intermediate/ ===> ./docs/build/<format>/
./examples/ /
Once ./docs/intermediate/ is built, you can use all the Sphinx output
formats, e.g.
- make html
- make latex
- make man
- make htmlhelp
- etc.
|
I won't be addressing this in this PR. |
It may be useful/worth thinking about options for RST to not be too restrictive with regards to leading whitespace, which would enable it being embedded in other syntaxes seemlessly. Markdown for instance ships an If reST would provide something similar, it would probably rather easy for end users to create a Python (Sphinx) syntax adding reST highlighting in documentation strings.
Well, that's what you need to embed a syntax for, normally, as completions, syntax-specific key bindings etc. rely on certain |
All FYI, I don't need the highlighting in Python comments at all, but the other functionality (Completions/Snippets and other utilities) are very welcome. Example: the 3 I submitted above. |
Note: In testing, I am finding this key-binding selector very helpful. (The 3 commands I submitted above require selections to be non-empty.)
|
@jrappen I just found a bug with the existing 5 back-ticks are actually legal in Docutils and simply represent a "literal backtick" character. The current highlighting in ST build 4200 does "literal" highlighting on only the first 4 and leaves the 5th one "dangling". If you replace the middle (3rd) backtick with any other character, the highlighting is done correctly. Hope this helps. |
Note
This PR is mainly meant to make future work easier, not necessarily
fix stuff now. If you have suggestions for stuff that should be fixed
now, leave a comment below.
current TODOs
Additions:
mapping.pair
while checking value formatfootnotes, citations)
jsonc, html, python, toml, yaml), compare [reStructuredText] Code-blocks are not handled #3158
targets
interpreted text
, optionallywith roles
lines
Fixes:
[RestructuredText] single quotes break link targets #1204
Changes:
section headings and their punctuation
scope naming guide
punctuation.definition.end
rules for inline itemsbefore
invalid.illegal.newline
compare [reST] Internal link labels should allow more character types #793
auto_complete_selector
defaultdirective names
References:
syntax don't get lost
Thanks to these contributors: