How to render whitespace explicitly in sphinx documentation? - whitespace

I'm one of the maintainers of sqlfluff, and I'd like to replicate similar pattern and anti-pattern examples to the flake8 documentation here: https://www.flake8rules.com/rules/E101.html
At the moment the default styling for code-block sections in rst files doesn't show whitespace as explicit characters, which is normally great - but not very useful if the mixture of whitespace is what you want to show.
Is there a way in rst code-block sections to render whitespace similar to the render whitespace settings in common code editors (similar to this SO question)?
An ideal answer would be to do this natively, but I'm also open to potential options in extending sphinx (although it would be useful to have some pointers on how to do that), or other creative workarounds.

Related

Sphinx can't generate link text as literal

With Markdown, I can simply:
[`a link with monospace font`](https://www.example.com)
a link with monospace font
Note how the above line is properly rendered by SO's MD renderer: the link text is in code (monospace) syntax.
I'm trying to achieve the same with reST:
I've tried to do this in reST with
```a link with monospace font`` <https://www.example.com>`_
But that breaks the linking, I get a monospaced text with a link with monospace font and then a link with https://www.example.com as the link text.
The problem seems to be Docutil's lack of support for nested inline markup. Frankly, I don't understand how's that possible. Docutils ToDo lists a discussion from 2001! We're in 2022! Not only this really basic feature is missing, but my impression is also that there's no real interest in ever implementing it.
I don't think the different workarounds are reasonable for such a simple feature.
Pandoc has an open bug for the exact same problem/
How can I get an HTML link test rendered as a literal without any workaround when using reStructuredText?

Markdown to markdown but undo hard wraps

Can pandoc be used to take a (pandoc) markdown file that is hard wrapped and reflow the text and use one line for paragraph, but otherwise don't change anything? Usecase would be to take hardwrapped text and transform it so an online textbox doesn't mess it up when pasting.
It depends a little in your definition of "doesn't change anything else", but --wrap=none is probably the option that you are after. Pandoc's Markdown output is opinionated, so it may not do exactly what you want.

BlockComposer.ShowText() doesnt have an option to draw underline text?

I'm using blockComposer.ShowText("foo") to build texts but how to do an underline?
I don't see enough examples on underline text, how do you all make one?
Text decorations (underline, line-through, overline) haven't been supported yet: they are generally considered an ugly and discouraged typographic habit, so that even the PDF spec doesn't natively support them (it all ends up with cosmetic graphic lines placed somewhere near the text glyphs).
It's not that tough job to add them... I simply avoided them in abhorrence, but I fear there shall come the day when I am forced to deal with this ;) ... maybe in forthcoming 0.2.0 version?

Bold code in rst

How can I get code (monospace) text that is bold in rst (I'm using Sphinx)? Anything in :: seems to be rendered literally, as with ``, so ``**bold**`` doesn't work.
In general, nested inline markup is not possible in reStructuredText. There are more or less ugly workarounds, such as using raw HTML. Like this:
.. raw:: html
<div>Some stuff <pre>some <b>bold</b> text</pre>...</div>
Actually using raw for code is a very bad thing to do as it ignores the beautiful Pygments highlighting and complicates things to extreme. First thing to do is to play with different Pygments highlighting styles. You can find a functional demo here. Then you may set the appropriate highlighting in conf.py. If none of the styles make the desired part of your code bold, you may consider creating your own Pygments theme, which is unfamiliar territory for me, but shouldn't be that hard.
There is third thing to try though, you could look up the class of the word you need to highlight and add a rule to your CSS. Pygments produce this seemingly gibberish classes like nv, ls, etc for every type of the highlighted words. But keep in mind, that every instance of this type will be highlighted. If your chosen word is a class definition - all class definitions will be highlighted.
Only if none of these options apply should you consider using something as atrocious as raw, because every time someone uses raw, Sphinx dies a little. Do you really want Sphinx to die?
Most likely restructured text does not support formatting options you are asking for.
However you are free to add your own :: admonition directives which have custom CSS styling over them.
Example for a custom block and CSS styling. RST:
.. admonition:: foobar
My custom text here
CSS:
.admonition-foobar {
font-weight: bold;
}

text highlight in markdown

Within a Markdown editor I want to support text highlight, not in the sense of code highlighting, but the type of highlighting people do on books.
In code oriented sites people can use backquotes for a grey background, normally inline code within a paragraph. However on books there is the marker pen for normal text within a paragraph. That is the classical black text on yellow background.
Is there any syntax within Markdown (or its variants) to specify that the user want that type of highlight? I want to preserve the backquotes syntax for code related marking, but also want a way to enable highlighted user text
My first thought is just using double backquotes, since triple backquotes are reserved for code blocks. I am just wondering if other implementations have already decided a syntax for it... I would also appreciate if someone could justify if this is a very bad idea.
As the markdown documentation states, it is fine to use HTML if you need a feature that is not part of Markdown.
HTML5 supports
<mark>Marked text</mark>
Else you can use span as suggested by Rad Lexus
<span style="background-color: #FFFF00">Marked text</span>
I'm late to the party but it seems like a couple of markdown platforms (Quilt & iA Writer) are using a double equal to show highlighting.
==highlight==
Typora is also using double equal for highlighting. It would be nice it that becomes a CommonMark standard, as mentioned by DirtyF. It would be nice for those who use it frequently, since it is only 4 repeated chars: ==highlight==
If you want the option to use multiple editors, it may be best to stick with <mark>highlight</mark> for now, as answered by Matthias.
Here is the latest spec from CommonMark, "which attempts to specify Markdown syntax unambiguously". Currently "highlighting" is not included.
Editors using ==highlight== from comments mentioned previously:
Typora
Obsidian
Quilt
IA Writer
Feel free to add to this list.
You can use the Grave accent (backtick) ` to highlight text in markdown
Highlighted text
Also works with VS Code extension markdownlint
Grey-colored Higlighting Solution
A possible solution is to use the <code> element:
This solution works really well on git/github, because git/github doesn't allow css styling.
OBS!:
Using the code-element for highlighting is not semantic.
However, it is a possible solution for adding grey-colored highlighting to text in markdown.
Markdown/HTML
<code> <i>This text will be italic</i> <b>this text will be bold</b> </code>
Output
This text will be italic this text will be bold
Roam markdown uses double-caret: ^^highlight^^. Andrew Shell's answer mentions double-equals.
The accepted and clearly correct answer is <mark> from Matthias above, but I thought I had seen carets in some other flavor of markdown. Maybe not. I want to transform my ^^highlights^^ to <mark>highlights</mark> in pandoc conversion to html, and somehow ended up here...
Probably best bet is just use html e.g
<pre><b>Hello</b> is higlighted</pre>
Hello is higlighted
Remember nearly all html is valid in markdown too.

Resources