How to use color in text with ReStructured Text (rst2html.py) or how to insert HTML tags without blank lines?
I found this method working
First, you have the role.
.. role:: red
An example of using :red:`interpreted text`
It translates into as follows.
<p>An example of using <span class="red">interpreted text</span></p>
Now, you have the red class, you can use CSS for changing colors.
.red {
color:red;
}
How can I change the background colors of a table cell in reStructuredText?
Kludge it with javascript:
.. role:: gbg
.. raw:: html
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.gbg').parent().addClass('gbg-parent');
});
</script>
<style>
.gbg-parent {background-color:#00ff00;}
</style>
+-------+----------------+-------+---------+-------+---------+
| UTC+1 | (d-s) | UTC-6 | (zo) | UTC-7 | (za) |
+=======+================+=======+=========+=======+=========+
| 15:00 | :gbg:`avail` | 8:00 | | 7:00 | |
+-------+ +-------+---------+-------+ +
| 15:30 | | 8:30 | | 7:30 | |
+-------+----------------+-------+---------+-------+---------+
How can I change font using ReStructured Text with .. raw:: html?
I finally solved this by practically brute-force, but for anyone curious for this issue here is the update.
.. raw:: html
<style> .font {font-family:'Courier New'} </style>
And I can call this anywhere like my other method to change color.
sphinx, restructuredtext: set color for a single word
If you want to do this without being tied to html, try applying a different style than normal body text to your word.
In this example adapted from the rst2pdf manual, I apply the existing rubric style which is red in the backend that I am using:
Before red.
.. role:: rubric
I like color :rubric:`rubric`.
After red.
The actual look of the word will depend on how the style you choose is defined in the stylesheet that you use when generating your document.
If you want blue text, make a blue text style and derive it from the normal text style.
The stylsheet is backend-specific and you may be using the default.
To print the default for rst2pdf.py, do this (from the rst2pdf manual):
rst2pdf --print-stylesheet
Continuing the example for a rst2pdf stylesheet, add this to your stylesheet to have a blue text style:
bluetext:
parent: bodytext
textColor: blue
In the document you can reference this style to get a blue word.
Note this bit is generic, and should make blue text if you define a blue style in your html or whatever backend's stylesheet.
Before blue.
.. role:: bluetext
I like color :bluetext:`blue`.
After blue.
The generated pdf has the coloured words:
Applying CSS and roles for text blocks instead of inline spans in Sphinx
There are a number of ways to do this, but one of them is to use the class
directive:
.. class:: red
This is a paragraph.
This is another paragraph.
Most docutils HTML writers will put that into html output as a class html attribute, which you can then style with CSS.
In Sphinx, in particular, however, you may need to use rst-class
instead of class
in at least some cases. See: https://www.sphinx-doc.org/en/2.0/usage/restructuredtext/basics.html
Also, many block-level elements in RestructuredText take a :class:
parameter which does pretty much the same thing.
How to preserve spaces in hyperlinks when converting restructured text to html?
I don't know how you are grabbing the line from the file (or stdin), but you should convert the link related string to HTML entities. You can find more information in the following link Escaping HTML - Python Wiki.
Hope this help you.
create a role (font color) in sphinx that works with `make latexpdf`
Just add:
a 'source/_templates/layout.html' file with
{% extends "!layout.html" %}
{% block extrahead %}
<link rel="stylesheet" type="text/css"
href="{{ pathto('_static/custom.css', 1) }}" />
{% endblock %}a 'source/_static/custom.css' file with
@import url("default.css");
.red {
color: red;
}
You can now use a :red: role in your rst files. Don't forget the back tick and the clean target after html or css editions:
A :red:`red`text
$> make clean html
The global tree:
test-sphinx
├── Makefile
├── build
└── source
├── _static
│ └── custom.css
├── _templates
│ └── layout.html
├── conf.py
└── index.rst
An index.rst example:
TS test!
========
.. role:: red
This is :red:`just` a test …
Hope this help,
Antoine
How to make verbatim text inside a link in Restructured Text?
As far as I know and can find in the documentation you simply can't do this.
The same goes for trying to make a link bold or italic (which is what I was looking for).
Apparently it is possible (see the comment from @jJason S) below pointing to Format text in a link in reStructuredText
Related Topics
Bootstrap 3 Truncate Long Text Inside Rows of a Table in a Responsive Way
Why Can't I Use a Heading Tag Inside a P Tag and Style It with CSS
How to Vertical Align an Inline-Block in a Line of Text
Flex Child Is Growing Out of Parent
Table Columns, Setting Both Min and Max Width with CSS
Brackets Displays Wrongly for Right to Left Display Style
Image Overlay on Responsive Sized Images Bootstrap
Android: How to Add HTML Links Inside a Listview
Phonegap - How to Open External Link Inside The App
<Ol> with Numbers Another Color
Print When Textarea Has Overflow
Is There a Web Service for Converting HTML to Pdf
Svg Fill Animation for The Given Path
Emoji Rendered in Chrome Have Different Widths Than in Other Browsers
Disable Opacity on Child Element When Parent Element Has Opacity
How to Include Glyphicons in Bootstrap 3