| 1 |
.. include:: ../header.rst |
| 2 |
|
| 3 |
============================================== |
| 4 |
Writing HTML (CSS) Stylesheets for Docutils_ |
| 5 |
============================================== |
| 6 |
|
| 7 |
:Author: Lea Wiemann |
| 8 |
:Contact: [email protected] |
| 9 |
:Date: $Date: 2024-09-10 17:30:31 +0200 (Di, 10. Sep 2024) $ |
| 10 |
:Revision: $Revision: 9923 $ |
| 11 |
:Copyright: This document has been placed in the public domain. |
| 12 |
|
| 13 |
.. _Docutils: https://docutils.sourceforge.io/ |
| 14 |
|
| 15 |
|
| 16 |
The look of Docutils' HTML output is customizable via CSS stylesheets. |
| 17 |
The default stylesheets can be found in the |
| 18 |
``docutils/writers/html*/`` directories of the ``html4css1`` and |
| 19 |
``html-base`` writers in the Docutils installation. Use the front-end |
| 20 |
command (``rst2html`` or ``rst2html5``) with the |
| 21 |
``--help`` option and look at the description of the ``--stylesheet-path`` |
| 22 |
command-line option for the exact machine-specific location. |
| 23 |
|
| 24 |
To customize the look of HTML documents, you can override the settings |
| 25 |
of the default stylesheet in your own stylesheet. Specify both, the |
| 26 |
default stylesheet and your stylesheet to the ``--stylesheet`` or |
| 27 |
``--stylesheet-path`` command line option (or the corresponding |
| 28 |
settings in a configuration_ file), e.g. :: |
| 29 |
|
| 30 |
rst2html --stylesheet=html4css1.css,transition-stars.css |
| 31 |
|
| 32 |
This is the preferable approach if you want to embed the stylesheet(s), as |
| 33 |
this ensures that an up-to-date version of ``html4css1.css`` is embedded. |
| 34 |
|
| 35 |
Alternatively, copy the default style sheet to the same place as your |
| 36 |
output HTML files will go and place a new file (e.g. called |
| 37 |
``my-docutils.css``) in the same directory and use the following |
| 38 |
template:: |
| 39 |
|
| 40 |
/* |
| 41 |
:Author: Your Name |
| 42 |
:Contact: Your Email Address |
| 43 |
:Copyright: This stylesheet has been placed in the public domain. |
| 44 |
|
| 45 |
Stylesheet for use with Docutils. [Optionally place a more |
| 46 |
detailed description here.] |
| 47 |
*/ |
| 48 |
|
| 49 |
@import url(html4css1.css); |
| 50 |
|
| 51 |
/* Your customizations go here. For example: */ |
| 52 |
|
| 53 |
h1, h2, h3, h4, h5, h6, p.topic-title { |
| 54 |
font-family: sans-serif } |
| 55 |
|
| 56 |
For help on the CSS syntax, see, e.g., the `W3C Specification`_, the |
| 57 |
`WDG's guide to Cascading Style Sheets`__, or the `MDN Web Docs`__. |
| 58 |
|
| 59 |
.. _W3C Specification: https://www.w3.org/Style/CSS/#specs |
| 60 |
__ http://www.htmlhelp.com/reference/css/ |
| 61 |
__ https://developer.mozilla.org/en-US/docs/Web/CSS |
| 62 |
|
| 63 |
It is important that you do not edit a copy of ``html4css1.css`` |
| 64 |
directly because ``html4css1.css`` may be updated with a new |
| 65 |
release of Docutils. |
| 66 |
|
| 67 |
Also make sure that you import ``html4css1.css`` (using "``@import |
| 68 |
url(html4css1.css);``") because the definitions contained in the |
| 69 |
default stylesheet are required for correct rendering (margins, |
| 70 |
alignment, etc.). |
| 71 |
|
| 72 |
If you think your stylesheet is fancy and you would like to let others |
| 73 |
benefit from your efforts, you are encouraged to post the stylesheet to the |
| 74 |
Docutils-users_ mailing list. It might find its place in the `stylesheet |
| 75 |
collection`_ in the Docutils Sandbox_. |
| 76 |
|
| 77 |
If you decide to share your stylesheet with other users of Docutils, |
| 78 |
please keep website-specific customizations not applicable to |
| 79 |
Docutils' HTML code in a separate stylesheet. |
| 80 |
|
| 81 |
.. base for relative links is /docutils/docs/howto/ |
| 82 |
|
| 83 |
.. _Docutils-users: ../user/mailing-lists.html#docutils-users |
| 84 |
.. _configuration: ../user/config.rst |
| 85 |
.. _sandbox: ../../../sandbox |
| 86 |
.. _stylesheet collection: ../../../sandbox/stylesheets/ |
| 87 |
|
| 88 |
|
| 89 |
.. Emacs settings |
| 90 |
|
| 91 |
Local Variables: |
| 92 |
mode: indented-text |
| 93 |
mode: rst |
| 94 |
indent-tabs-mode: nil |
| 95 |
sentence-end-double-space: t |
| 96 |
fill-column: 70 |
| 97 |
End: |