Open In App

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

Last Updated : 29 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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




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


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.




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, 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.


Similar Reads

Create a GUI to convert CSV file into excel file using Python
Prerequisites: Python GUI – tkinter, Read csv using pandas CSV file is a Comma Separated Value file that uses a comma to separate values. It is basically used for exchanging data between different applications. In this, individual rows are separated by a newline. Fields of data in each row are delimited with a comma. Modules Needed Pandas: Python i
3 min read
How to save file with file name from user using Python?
Prerequisites: File Handling in PythonReading and Writing to text files in Python Saving a file with the user's custom name can be achieved using python file handling concepts. Python provides inbuilt functions for working with files. The file can be saved with the user preferred name by creating a new file, renaming the existing file, making a cop
5 min read
How to convert PDF file to Excel file using Python?
In this article, we will see how to convert a PDF to Excel or CSV File Using Python. It can be done with various methods, here are we are going to use some methods. Method 1: Using pdftables_api Here will use the pdftables_api Module for converting the PDF file into any other format. It's a simple web-based API, so can be called from any programmin
2 min read
How to convert CSV File to PDF File using Python?
In this article, we will learn how to do Conversion of CSV to PDF file format. This simple task can be easily done using two Steps : Firstly, We convert our CSV file to HTML using the PandasIn the Second Step, we use PDFkit Python API to convert our HTML file to the PDF file format. Approach: 1. Converting CSV file to HTML using Pandas Framework. P
3 min read
How to create a duplicate file of an existing file using Python?
In this article, we will discuss how to create a duplicate of the existing file in Python. Below are the source and destination folders, before creating the duplicate file in the destination folder. After a duplicate file has been created in the destination folder, it looks like the image below. For automating of copying and removal of files in Pyt
5 min read
How to convert a PDF file to TIFF file using Python?
This article will discover how to transform a PDF (Portable Document Format) file on your local drive into a TIFF (Tag Image File Format) file at the specified location. We'll employ Python's Aspose-Words package for this task. The aspose-words library will be used to convert a PDF file to a TIFF file. Aspose-Words: Aspose-Words for Python is a pot
3 min read
Read Html File In Python Using Pandas
In Python, Pandas is a powerful library commonly used for data manipulation and analysis. While it's primarily used for working with structured data such as CSV files, Excel spreadsheets, and databases, it's also capable of reading HTML files and extracting tabular data from them. In this article, we'll explore how to read an HTML file in Python us
5 min read
PYGLET – Opening file using File Location
In this article we will see how we can open a file using file location object in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set t
3 min read
Python - Copy contents of one file to another file
Given two text files, the task is to write a Python program to copy contents of the first file into the second file. The text files which are going to be used are second.txt and first.txt: Method #1: Using File handling to read and append We will open first.txt in 'r' mode and will read the contents of first.txt. After that, we will open second.txt
2 min read
Python program to reverse the content of a file and store it in another file
Given a text file. The task is to reverse as well as stores the content from an input file to an output file. This reversing can be performed in two types. Full reversing: In this type of reversing all the content gets reversed. Word to word reversing: In this kind of reversing the last word comes first and the first word goes to the last position.
2 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg