reStructuredText and Code Block Linter

6.2.5 · active · verified Sun Apr 12

rstcheck is a CLI application and Python library designed to check the syntax of reStructuredText (RST) documents and code blocks embedded within them. It leverages docutils for RST parsing and includes optional support for Sphinx and TOML configuration. The project follows semantic versioning and has an active release cadence, with the current stable version being 6.2.5.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `rstcheck` programmatically with the `rstcheck.check()` function to lint reStructuredText strings, both valid and invalid. It also shows how to invoke it as a command-line tool, which is its primary use case.

import rstcheck

rst_content_good = """
Example
=======

This is a valid reStructuredText document.

.. code:: python

    print('Hello, world!')
"""

rst_content_bad = """
Bad Example
===========

This document has bad RST syntax.

.. code:: python

    print('Missing quote)
"""

# Check good content
results_good = list(rstcheck.check(rst_content_good))
print(f"Good content issues: {results_good}")

# Check bad content
results_bad = list(rstcheck.check(rst_content_bad))
print(f"Bad content issues: {results_bad}")

# Alternatively, via CLI (requires saving to a file):
# Create a temporary file for CLI example
with open('bad_example.rst', 'w') as f:
    f.write(rst_content_bad)
import subprocess
result_cli = subprocess.run(['rstcheck', 'bad_example.rst'], capture_output=True, text=True)
print(f"\nCLI Output:\n{result_cli.stdout}{result_cli.stderr}")
import os
os.remove('bad_example.rst')

view raw JSON →