Related Articles

Related Articles

reStructuredText | .rst file to HTML file using Python for Documentations
  • Last Updated : 21 Jan, 2019

Introduction to .rst file (reStructuredText):

reStructuredText is a file format for Textual data majorly used by Python based communities to develop documentation in an easy way similar to other tools like Javadoc for Java. Most of the docs of Python-based software and libraries are written using reStructuredText and hence it’s important to learn it when contributing to any organization.

Like Python, RST syntax is also sensitive to Indentation.

Example code of reStructuredText:
Some basic syntax and their HTML rendering are given below.

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

Heading

italic *italic* italic
bold **bold** bold
link `gfg<www.geeksforgeeks.org>` gfg
verbatim ``Some text or code``



Some text or code

restructured.rst

filter_none

edit
close

play_arrow

link
brightness_4
code

******************************
This is example of rst on GFG
******************************
  
*GeeksforGeeks in italic*
  
**GeeksforGeeks in bold**
  
`Gfg website<www.geeksforgeeks.org>`
  
``GeeksforGeeks in vebatim``

chevron_right


Save the file with .rst extension.

Python Code :

Following is the Python code to convert .rst files to HTML files. docutils is a predefined library downloaded while Python is installed. publish_file method is used to convert rst to html by passing file names as parameters.

filter_none

edit
close

play_arrow

link
brightness_4
code

import docutils.core
  
docutils.core.publish_file(
    source_path ="restructured.rst",
    destination_path ="Output.html",
    writer_name ="html")

chevron_right


Output.html
After running the python code, a HTML file would be made in the same directory as of rst file. The code of HTML is complicated than normal HTML code written by a person since it’s auto generated. The following image shows HTML rendering of reStructuredText shown above.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :