Skip to content
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

fix #17260 render \ properly in nim doc, rst2html #17315

Merged
merged 12 commits into from
Mar 24, 2021

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Mar 10, 2021

/cc @a-mr

before PR:

https://nim-lang.github.io/Nim/system.html#addEscapedChar%2Cstring%2Cchar
image

after PR:

image

note 1

the fix for this should not be controversial:

`/x` (`/` not followed by a backtick)
`//` (ditto, the `/` is paired)

note 2

the fix for this is more controversial but IMO is the correct approach:
I'm treating this as legal:

`/` (`/` followed by a backtick)

because:

Interpreted text is text that is meant to be related, indexed, linked, summarized, or otherwise processed, but the text itself is typically left alone. Interpreted text is enclosed by single backquote characters:

The RST spec does not cover escaping in interpreted text explicitly but the idea is mostly clear.
The code role is not really documented about that behavior

## see `system.[]=` # no need to render a backtick inside the backtick pair

for simpler doc links (nim-lang/RFCs#125) this also shouldn't be a problem:

## see `system.[]=`_

note 3

for the rare cases where we'll want to show a backtick character in docs (outside of code blocks/runnableExamples where this works fine), eg to distinguish case from `case` , we should use markdown syntax:

foo1 ``` ` ``` # strips leading and trailing space and we end up with a single backtick rendered
foo2 ``` `` ``` # ditto, we end up with 2 backticks
foo2 ```` ``` ```` # ditto, we end up with 3 backticks

it's flexible and has saner escaping semantics (just increase the number of surrounding backticks)

future work

| A1 header    | A2 \| not fooled
| :---         | ----:       |
| C1           | C2 **bold** | ignored |
| D1 `code \|` | D2          | also ignored
| E1 \| text   |
|              | F2 without pipe
not in table

there are workarounds until this is addressed, eg:
split the rendered pipe in 2:

`x` \| `y`

or using a different unicode char for the pipe https://stackoverflow.com/a/43070960/1426932

@timotheecour timotheecour force-pushed the pr_fix_17260_rst_escape branch from a4e5e12 to c6a4287 Compare March 10, 2021 02:03
@timotheecour timotheecour changed the title fix #17260 render \a properly in nim doc fix #17260 render \a properly in nim doc, rst2html Mar 10, 2021
@timotheecour timotheecour changed the title fix #17260 render \a properly in nim doc, rst2html fix #17260 render \ properly in nim doc, rst2html Mar 10, 2021
@timotheecour timotheecour added the TODO: followup needed remove tag once fixed or tracked elsewhere label Mar 10, 2021
@timotheecour timotheecour marked this pull request as ready for review March 10, 2021 03:34
@timotheecour timotheecour reopened this Mar 10, 2021
@timotheecour timotheecour force-pushed the pr_fix_17260_rst_escape branch from 9c32c60 to 062a77c Compare March 10, 2021 07:05
@a-mr
Copy link
Contributor

a-mr commented Mar 10, 2021

I don't understand your vigor for exact replicating Markdown behavior.

Using code as the default role is fine. (the fact that python rst2html has title-reference, which is italic text, as the default role makes little sense to me.) But it means we should be able input backticks there with \`.

backticks are rarely needed, eg we can use:

The cases when we need a standalone \ are much more rare. We can just use double ticks for that rare case:

``\``

is what users will expect (and in fact nim docs already uses it even though, prior to this PR, it didn't render properly, eg see addEscapedChar docs)

You are a little cunning here. This bug that you showed was actually introduced in double backtick elimination in d447c0f , previously it was rendered OK with double backticks.

unblocks #17259 and #17258

For the time being you can just use double backticks wherever a backslash is present.

@Araq
Copy link
Member

Araq commented Mar 11, 2021

after PR:

What? It's much worse after your PR. Why would there be double backslashes? o.O

@a-mr
Copy link
Contributor

a-mr commented Mar 11, 2021

@Araq
it's just that @timotheecour stumbled upon a bad example accidentally. The original text was written in this confusing way in 8caf257 indeed.

The essence of this PR is that after the recent double-backtick elimination any changed markup containing backslashes got broken because backslashes are interpreted differently in single backticks. So @timotheecour tries to hotfix that. Which is also dangerous because there can exist markup in single backticks that relies on old behavior.

@Araq
Copy link
Member

Araq commented Mar 11, 2021

So undo the commits that use single backticks everywhere.

@konsumlamm
Copy link
Contributor

So undo the commits that use single backticks everywhere.

Why not just undo the changes where it breaks something? That should only be a few changes (most of the time, backticks are used around variable names). IMO it's not worth it to sacrifice using single backticks.

@timotheecour
Copy link
Member Author

timotheecour commented Mar 11, 2021

What? It's much worse after your PR. Why would there be double backslashes? o.O

@Araq I don't understand this comment. The double backslashes in the rendered html are correct.
In fact it matches 1.4 docs: https://nim-lang.org/docs/system.html#addEscapedChar%2Cstring%2Cchar
image

There is a double backslash because addEscapedChar adds a backslash to something like \n, otherwise it'd be indistinguishable from \n.

replaces \n by \\n # correct: after this PR, as well as in 1.4 docs
replaces n by \n # incorrect: in devel docs
replaces \n by \n # incorrect (following your suggestion of no double backslashes) => nothing replaced

whether this should written in the doc comment as

## replaces `\n` by `\\n` (as enabled by this PR)
or
## replaces ``\n`` by ``\\n`` (as was needed in 1.4 to get the desired html, but still possible after this PR)

is a different question, but your suggestion that there should be no double backslashes here is incorrect.

The original text was written in this confusing way in 8caf257 indeed.

I don't see how the original text (in the rendered html) from 8caf257 was confusing, it conveys exactly what the proc does. This is consistent with other uses in the manual and elsewhere in that \n means newline, and \\n means backslash followed by n (total 2 chars)

This was referenced Mar 11, 2021
@Araq
Copy link
Member

Araq commented Mar 11, 2021

@Araq I don't understand this comment. The double backslashes in the rendered html are correct.

Ok, ok, I take it back. That doesn't mean that I can review this, I cannot, I have no idea what changed and why.

lib/packages/docutils/rst.nim Outdated Show resolved Hide resolved
@narimiran
Copy link
Member

narimiran commented Mar 16, 2021

The example from the addEscapedChar documentation should also be added to nimdoc/rst1html/source/rst_examples.rst — once the escaping is fixed, we don't want to have those regressions again.

@timotheecour timotheecour force-pushed the pr_fix_17260_rst_escape branch from 062a77c to fa3a8dc Compare March 19, 2021 08:27
@timotheecour
Copy link
Member Author

timotheecour commented Mar 19, 2021

PTAL, I'm now honoring these:

``foo`` # double backtick behavior unchanged
`fo\a\\b\`o` # single backtick now renders as: fo\a\\b`o (the backtick is escaped, but not the other backslashes)

The example from the addEscapedChar documentation should also be added to

I've added tests to tests/stdlib/trstgen.nim; before this PR, there were no tests for interpreted text or inline literals

@timotheecour timotheecour requested review from Araq and ringabout March 19, 2021 18:16
@Araq Araq requested a review from narimiran March 21, 2021 09:42
@Araq
Copy link
Member

Araq commented Mar 21, 2021

@narimiran's turn.

@timotheecour
Copy link
Member Author

ping @narimiran

@narimiran narimiran merged commit 1590d14 into nim-lang:devel Mar 24, 2021
@timotheecour timotheecour deleted the pr_fix_17260_rst_escape branch March 24, 2021 18:22
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
a-mr added a commit to a-mr/Nim that referenced this pull request Mar 26, 2021
@metagn metagn removed the TODO: followup needed remove tag once fixed or tracked elsewhere label Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nim doc/rst2html renders \v, \\, etc incorrectly
6 participants