Sphinx can't generate link text as literal - python-sphinx

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?

Related

How do I use a different highlighter in R Bookdown?

I am trying to change the syntax highlighting color scheme in my book when rendering to a GitBook-style webpage. The color schemes available in Pandoc aren't very informative for my code (HTML/CSS/JavaScript). I can modify the CSS directly to change the color scheme, but the underlying problem seems to be that the highlighting-kate library used isn't doesn't do very descriptive parsing of these languages to produce effective color schemes.
The compiled book looks like it contains a highlight.js (HLJS) based plugin for Gitbook, but I can't figure out how to enable that so that I can drop in a hljs CSS file.
Is there anyway to utilize HLJS instead of Kate for code parsing? Or is there a good way to inject my own custom parsing into Pandoc's markdown rendering process?

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.

How to change the spacing between letters in a NSFont?

I'm trying to change the letter spacing in a NSFont (such as Gill Sans). Is this possible or will I need to load my own custom font?
Though I suppose fonts might specify some kerning hints, kerning is really an attribute of rendered text. So the answer to your question depends on how you're going to render your text to the screen.
If you're using NSAttributedString, you can look at the NSKernAttributeName attribute (see the Constants section in the documentation. If you're using CoreText and CFAttributedString, you can look at the kCTKernAttributeName attribute (see the Constants section in the documentation.
If you're using something else to render text, then the answer (if there is one; not all text rendering methods support advanced customization) will be dependent on that something else.

Html editor - Text to HTML convertor

I want to convert my text into HTML format, it would be just like this: that I just copy paste the text from word, pdf [with formatting & colors] to the editor and it will convert it into HTML tags, so that when I decode it again it would give me the same format that I have pasted.
I am mostly happy with PageBreeze but sometimes it destroys the formatting.
Are there any other editor suggestions?
Though I think it's a crude solution, you can try using the on-the-fly generated comment below, highlight, view source and copy it or pretty much any of the Rich Text Editor Javascript plugins out there such as RTE, the simplest I could find. (I'm not sure if those preserves copy-pasted formatting)
However, you won't be assured that any formatting (font/color) you get from here will be carried over to your website. In addition to HTML, CSS plays a huge part in styling, especially text-color, highlighting, spacing, etc.
I think in word you can do file >saveas > html
However it's going to be junky and nasty.
Your best option is to learn basic HTML (it really is super easy) and manually do it yourself.

Resources