MCPcopy
hub / github.com/django/django / parse_rst

Function parse_rst

django/contrib/admindocs/utils.py:60–92  ·  view source on GitHub ↗

Convert the string from reST to an XHTML fragment.

(text, default_reference_context, thing_being_parsed=None)

Source from the content-addressed store, hash-verified

58
59
60def parse_rst(text, default_reference_context, thing_being_parsed=None):
61 """
62 Convert the string from reST to an XHTML fragment.
63 """
64 overrides = {
65 "doctitle_xform": True,
66 "initial_header_level": 3,
67 "default_reference_context": default_reference_context,
68 "link_base": reverse("django-admindocs-docroot").rstrip("/"),
69 "raw_enabled": False,
70 "file_insertion_enabled": False,
71 }
72 thing_being_parsed = thing_being_parsed and "<%s>" % thing_being_parsed
73 # Wrap ``text`` in some reST that sets the default role to
74 # ``cmsreference``, then restores it.
75 source = """
76.. default-role:: cmsreference
77
78%s
79
80.. default-role::
81"""
82 # In docutils < 0.22, the `writer` param must be an instance. Passing a
83 # string writer name like "html" is only supported in 0.22+.
84 writer_instance = docutils.writers.get_writer_class("html")()
85 parts = docutils.core.publish_parts(
86 source % text,
87 source_path=thing_being_parsed,
88 destination_path=None,
89 writer=writer_instance,
90 settings_overrides=overrides,
91 )
92 return mark_safe(parts["fragment"])
93
94
95#

Calls 2

reverseFunction · 0.90
mark_safeFunction · 0.90