Change language

reStructuredText | .rst file to HTML file using Python for documentation

| |

reStructuredText — it is a file format for text data that is mainly used by Python-based communities to develop documentation in a simple way similar to other tools like Javadoc for Java. Most Python-based software and library documents are written using reStructuredText, and therefore important to study when working in any organization.

Like Python, RST syntax is also sensitive to indentation.

Sample reStructuredText code:
Some basic HTML syntax and rendering are shown below.

gfg
usage syntax HTML rendering
Heading *****
Heading
*****

Heading

italic * italic * italic
bold ** bold ** bold
link ’gfg "python.engineering" ’
verbatim ’’ Some text or code’’

 Some text or code 

restructured.rst

************************* *****
This is example of rst on GFG
****** *************************

 
* Python.Engineering in italic *

 
** Python.Engineering in bold **

 
’Gfg website "www. python.engineering" ’

  
’’ Python.Engineering in vebatim’’

Save the file with the extension .rst .

Python code:

Below is the Python code for converting files. rst to HTML files.  docutils — it is a predefined library loaded during Python installation. The publish_file method is used to convert the first to HTML, passing the filenames as parameters.

import docutils.core

 
docutils.core.publish_file (

source_path = "restructured.rst" ,

destination_path = " Output.html " ,

writer_name = " html " )

output.html
After running the Python code, the HTML file will be generated in the same directory as as the first file. HTML is more complex than normal human-written HTML because it is generated automatically. The following image shows the HTML rendering of the reStructuredText shown above.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically