#! /usr/bin/env python # Copyright 2024 Tomas Brabec # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. try: import locale locale.setlocale(locale.LC_ALL, '') except: pass import docutils.frontend import docutils.utils import docutils.parsers settings = docutils.frontend.OptionParser().get_default_values() parser_class = docutils.parsers.get_parser_class('restructuredtext') parser = parser_class() option_parser = docutils.frontend.OptionParser( components=(parser,), read_config_files=True, description='') settings = option_parser.parse_args() document = docutils.utils.new_document('', settings) text = ''' My title ======== 1st paragraph 2nd paragraph - a - b ''' parser.parse(text, document) print(document.pformat())