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

Added escape for Sphinx characters to default value #49

Merged
merged 1 commit into from May 1, 2024

Conversation

RobertoRoos
Copy link

Helps to fix #15

(".//section/dl/dd/p", 'Default:'),
(".//section/dl/dd/p/code/span", '420'),
(".//section/dl/dd/p/code/span", "'*.rst"),
(".//section/dl/dd/p/code/span", r"\['\*.rst',"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this look like in the rendered HTML (both HTML source, and in a browser) please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result from the test method:
image

In HTML (formatting mine):

<p>
Default:
<code class="docutils literal notranslate">
<span class="pre">'*.rst</span> 
<span class="pre">_txt_</span> 
<span class="pre">**strong**</span> 
<span class="pre">*italic*</span> 
<span class="pre">\`\`code\`\`'</span>
</code>
</p>

else:
arg.append(f"Default: {entry['default']}")
# Put the default value in a literal block - but escape backticks already in the string
default_str = str(entry['default']).replace('`', r'\`')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small problem: the

\`

is displayed in the webbrowser literally. I haven't been able to property escape it in Sphinx to display it properly in a literal block.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, actually in plain Sphinx this works fine. The following is rendered as expected:

Demo code: ``hi``

Demo code: `````

Demo code: ``\```

Demo code: ```hi```

Demo code: ````hi````

Demo code: ``meta: ``hi````

image

@ashb ashb merged commit eefe10b into sphinx-doc:main May 1, 2024
10 of 11 checks passed
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.

parser with [*] in any string causes sphinx warning for Inline emphasis start-string without end-string
2 participants