Files
llvm-project/lldb/docs/_ext/lldb_setting.py
Nerixyz b9077c8e6a [lldb][Docs] Fix presentation of some default values (#192239)
There were two bugs with the display of default values:

1. If a default value contains a backtick, that would render
incorrectly. For example
[`disassembly-format`](https://lldb.llvm.org/use/settings.html#disassembly-format).
Fixed by doing the wrapping when we generate the Markdown instead of
when parsing the directive. MyST will already parse the content of the
directive as Markdown. We can escape backticks inside the string by
changing the fence. Markdown can take any number of backticks at the
start as long as they match the amount at the end
([spec](https://spec.commonmark.org/0.31.2/#code-spans)).
2. When the docs were built on Windows, UTF-8 was not correctly picked
up, because the default encoding isn't utf8 there.
[`separator`](https://lldb.llvm.org/use/settings.html#separator) was one
example (renders correctly on the Website but not on my machine).
2026-04-15 16:03:18 +02:00

55 lines
1.5 KiB
Python

from docutils.parsers.rst import directives
from docutils import nodes
from sphinx import addnodes
from sphinx.application import Sphinx
from sphinx.directives import ObjectDescription
from sphinx.util.docfields import Field, GroupedField
import llvm_slug
# Example:
# ```{lldbsetting} dwim-print-verbosity
# :type: "enum"
#
# The verbosity level used by dwim-print.
#
# :enum none: Use no verbosity when running dwim-print.
# :enum expression: Use partial verbosity when running dwim-print - display a message when `expression` evaluation is used.
# :enum full: Use full verbosity when running dwim-print.
# :default: none
# ```
class LLDBSetting(ObjectDescription):
option_spec = {
"type": directives.unchanged,
}
doc_field_types = [
Field("default", label="Default", has_arg=False, names=("default",)),
GroupedField("enum", label="Enumerations", names=("enum",)),
]
def handle_signature(self, sig: str, signode: addnodes.desc_signature):
typ = self.options.get("type", None)
desc = addnodes.desc_name(text=sig)
desc += nodes.inline(
"",
typ,
classes=[
"lldb-setting-type",
f"lldb-setting-type-{llvm_slug.make_slug(typ)}",
],
)
signode["ids"].append(sig)
signode += desc
def setup(app: Sphinx):
app.add_directive("lldbsetting", LLDBSetting)
return {
"version": "0.1",
"parallel_read_safe": True,
"parallel_write_safe": True,
}