guidedoc_defaults ================= .. rust:crate:: guidedoc_defaults :synopsis: The built-in pieces Guidedog assembles around the engine: the registry of readers and renderers (registry), typed read options for the built-in readers (rst_options, sphinx_options, myst_options), and the highlighters that connect gd-highlight to the renderers (HtmlHighlighter, TypstHighlighter). The built-in pieces Guidedog assembles around the engine: the registry of readers and renderers (:rust:fn:`registry `), typed read options for the built-in readers (:rust:fn:`rst_options `, :rust:fn:`sphinx_options `, :rust:fn:`myst_options `), and the highlighters that connect ``gd-highlight`` to the renderers (:rust:struct:`HtmlHighlighter `, :rust:struct:`TypstHighlighter `). .. code-block:: rust let registry = guidedoc_defaults::registry(); let mut ws = guidedoc::Workspace::new(); let html = guidedoc::convert_text(&mut ws, ®istry, "myst", "html", "# Hello\n"); assert!(html.expect("converts").contains("Hello")); .. rubric:: Structs .. rust:struct:: pub struct HtmlHighlighter Highlights code blocks as the HTML Pygments writes for Sphinx, with its short CSS classes. The language resolves as Sphinx resolves it: ``default`` is Python (or a Python console session), falling back to plain text when the code does not lex as Python; ``guess`` guesses; an unknown language is plain text, escaped as Pygments escapes it. One value keeps a reusable buffer, so a renderer that highlights many blocks does not allocate per block. It is not ``Sync``: give each rendering thread its own. .. rubric:: Implementations .. rust:impl:: impl HtmlHighlighter :noindex: :for: HtmlHighlighter .. rust:method:: pub fn new() -> HtmlHighlighter Creates a highlighter with an empty buffer. .. rubric:: Trait Implementations .. rust:impl:: impl Highlighter for HtmlHighlighter :noindex: :for: HtmlHighlighter :trait: Highlighter .. rust:method:: fn highlight(&self, language: &str, code: &str, out: &mut Emitter<'_>) -> bool :noindex: .. rust:struct:: pub struct TypstHighlighter Highlights code blocks as Typst data for the book template's ``gd-highlight`` function, so books draw code with Guidedog's colours rather than Typst's. It declines (returns ``false``) plain text and languages it does not know, so the renderer keeps Typst's own raw block for those. Like :rust:struct:`HtmlHighlighter `, one value reuses its buffer and belongs to one thread. .. rubric:: Implementations .. rust:impl:: impl TypstHighlighter :noindex: :for: TypstHighlighter .. rust:method:: pub fn new() -> TypstHighlighter Creates a highlighter with an empty buffer. .. rubric:: Trait Implementations .. rust:impl:: impl Highlighter for TypstHighlighter :noindex: :for: TypstHighlighter :trait: Highlighter .. rust:method:: fn highlight(&self, language: &str, code: &str, out: &mut Emitter<'_>) -> bool :noindex: .. rust:struct:: pub struct ReaderSettings The settings of the built-in readers for converting one file, kept together so read options can borrow them: Docutils' settings for ``rst``, Sphinx's for ``sphinx``, and MyST with the Sphinx layer's directives and roles for ``myst``. .. rubric:: Fields .. rust:field:: pub rst: guidedoc_rst::Settings The ``rst`` reader's settings. .. rust:field:: pub sphinx: guidedoc_sphinx::Config The ``sphinx`` reader's configuration. .. rust:field:: pub myst: guidedoc_commonmark::Settings The ``myst`` reader's settings, with the Sphinx layer as their extension. .. rubric:: Implementations .. rust:impl:: impl ReaderSettings :noindex: :for: ReaderSettings .. rust:method:: pub fn with_config(config: guidedoc_sphinx::Config) -> Self Settings whose Sphinx layer (for ``sphinx`` and ``myst``) uses ``config``. .. rust:method:: pub fn for_source() -> Self Settings for writing source again (the ``rst`` renderer): no smart quotes, so the text keeps the quotes and dashes it was written with. .. rust:method:: pub fn options(&self, reader: &str) -> ReadOptions<'_> The read options for reader ``reader``, borrowing these settings; other readers (``commonmark``) get the defaults. .. rubric:: Trait Implementations .. rust:impl:: impl Default for ReaderSettings :noindex: :for: ReaderSettings :trait: Default .. rust:method:: fn default() -> Self :noindex: The readers' defaults; MyST reads ``{doc}``, ``{ref}`` and directives as Sphinx does. .. rubric:: Functions .. rust:function:: pub fn myst_options(settings: &guidedoc_commonmark::Settings) -> ReadOptions<'_> Read options for the ``myst`` reader with ``settings`` (from ``guidedoc_commonmark::Settings::default()`` or ``guidedoc_sphinx::myst_settings``); the options borrow the settings. The ``commonmark`` reader takes no settings. .. rust:function:: pub fn registry() -> Registry The built-in registry: readers ``rst``, ``sphinx``, ``commonmark`` (pure CommonMark 0.31.2) and ``myst`` (MyST Markdown); renderers ``html``, ``typst`` (Typst source), ``text``, and ``rst`` (reStructuredText). Building it allocates two small vectors; keep one per program or thread and reuse it. .. rust:function:: pub fn rst_options(settings: &guidedoc_rst::Settings) -> ReadOptions<'_> Read options for the ``rst`` reader with ``settings`` (start from ``guidedoc_rst::default_settings()``); the options borrow the settings. Settings travel with their type, so another reader refuses them with ``core.read.settings_type`` instead of misreading them. .. rust:function:: pub fn sphinx_options(config: &guidedoc_sphinx::Config) -> ReadOptions<'_> Read options for the ``sphinx`` reader with ``config`` (start from ``guidedoc_sphinx::Config::default()``); the options borrow the configuration.