techy 0.1.2

A fast, extensible LaTeX parser for Rust
Documentation
<!-- rustdoc sidebar customization for the techy workspace documentation.

     Injected into every generated page via the `html-in-header` rustdoc flag
     (wired up in `.cargo/config.toml`; build with `cargo docs`). It
     restructures the sidebar into two top-level sections: "Guide" (the
     narrative pages, pinned on top) and "API" (the workspace crates and
     everything rustdoc generates for them), and it removes rustdoc's own
     "Crates" list (which would also list dependencies from stale doc builds).

     Maintenance:
       - adding a guide chapter (markdown page in `docs/` plus a module under
         `guide` in `techy/src/lib.rs`): add it to GUIDE_PAGES below, in
         reading order;
       - adding a workspace crate: add it (with its package name) to CRATES below.

     On docs.rs (which reads this file through `rustdoc-args` in the
     `[package.metadata.docs.rs]` section of each crate's `Cargo.toml`), each crate is
     documented separately, under `https://docs.rs/<package>/<version>/`, so
     links into another crate go to that crate's docs.rs pages, at the version
     segment of the current page (the workspace crates share one version).

     This relies only on coarse, stable parts of rustdoc's page structure (the
     `rustdoc-vars` meta tag, `.sidebar-elems`, `#rustdoc-toc`,
     `#rustdoc-modnav`); if a toolchain update changes those, the sidebar
     degrades to rustdoc's default rendering rather than breaking.
-->
<style>
/* Fallback (and anti-flash) rule: hide rustdoc's "Crates" list even before
   the script below removes it from the DOM. */
.sidebar-elems ul.block.crate,
.sidebar-elems h3:has(+ ul.block.crate) {
    display: none;
}

/* Top-level sidebar section headers ("Guide", "API"): small-caps labels. */
.sidebar h3.techy-nav-h {
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    margin: 1.1rem 0 0.35rem;
    padding-top: 0.7rem;
    border-top: 1px solid var(--sidebar-border-color);
}
.sidebar .techy-guide-nav h3.techy-nav-h {
    border-top: none;
    padding-top: 0;
    margin-top: 0.5rem;
}

/* Demote rustdoc's own sidebar headings ("Sections", "Crate Items", ...) so
   they read as subordinate to the two section labels above. */
.sidebar .techy-api-nav h3,
.sidebar .techy-guide-nav h3:not(.techy-nav-h) {
    font-size: 1rem;
}

/* Highlight the guide chapter being read and the current crate (rustdoc's
   `li.current` already sets the font weight; add the background it uses for
   its own current-crate entry). */
.sidebar .techy-guide-nav li.current a,
.sidebar ul.techy-crates li.current a {
    background-color: var(--sidebar-current-link-background-color);
}
</style>
<script>
/* Registered from the <head>; runs at DOMContentLoaded, i.e. after rustdoc's
   deferred main.js has finished building the sidebar. */
document.addEventListener("DOMContentLoaded", () => {
    "use strict";
    /* Guide chapters in reading order: [path under techy/guide/, title]. */
    const GUIDE_PAGES = [
        ["", "Overview"],
        /* User Guide */
        ["introduction/", "Introduction"],
        ["language_syntax/", "Language syntax"],
        ["node_trees/", "Node trees"],
        ["specs/", "Defining macros, environments, and specials"],
        ["parsing/", "Running the parser"],
        ["learn_by_example/", "Learn techy by example"],
        /* Developer Guide */
        ["concepts_overview/", "Concepts overview"],
        ["parsing_model/", "The parsing model"],
        ["construct_parsers/", "Custom construct parsers"],
        ["custom_lang/", "Defining a custom language"],
        ["integration/", "Integration: tooling, embedding, and bindings"],
        ["serialize/", "Serializing parses"],
        ["panics/", "List of panicking items"],
        ["pylatexenc_migration/", "Migrating from pylatexenc"],
        /* AI Guide */
        ["ai_guide/", "AI guide"],
        ["ai_guide_definitions/", "AI guide: definitions"],
        ["ai_guide_trees/", "AI guide: node trees"],
        ["ai_guide_custom_lang/", "AI guide: custom languages"],
        ["ai_guide_embedding/", "AI guide: embedding"],
        ["ai_guide_serialize/", "AI guide: serialization"],
        ["ai_guide_pylatexenc/", "AI guide: pylatexenc migration"],
    ];
    /* The workspace crates: the entry points of the "API" section, as
       [crate name in paths, package name on docs.rs]. */
    const CRATES = [["techy", "techy"], ["techy_derive", "techy-derive"]];

    const vars = document.querySelector("meta[name='rustdoc-vars']");
    const elems = document.querySelector("nav.sidebar .sidebar-elems");
    if (!vars || !elems) {
        return; /* source view, help/settings page, or unexpected layout */
    }
    const rootPath = vars.getAttribute("data-root-path") || "./";
    const currentCrate = vars.getAttribute("data-current-crate");
    /* On docs.rs the path is /<package>/<version>/<crate>/...; a local
       build keeps every workspace crate in one doc tree. */
    const docsRsVersion = window.location.hostname === "docs.rs"
        ? window.location.pathname.split("/")[2]
        : null;
    /* URL of `path` inside the documentation of crate `name`. */
    const href = (name, path) => {
        if (docsRsVersion && name !== currentCrate) {
            const entry = CRATES.find(([crate]) => crate === name);
            const pkg = entry ? entry[1] : name;
            return "https://docs.rs/" + pkg + "/" + docsRsVersion + "/" +
                name + "/" + path;
        }
        return new URL(rootPath + name + "/" + path, window.location.href).href;
    };

    const sectionHeader = text => {
        const h = document.createElement("h3");
        h.className = "techy-nav-h";
        h.textContent = text;
        return h;
    };
    const linkItem = (url, text) => {
        const a = document.createElement("a");
        a.href = url;
        a.textContent = text;
        const item = document.createElement("li");
        item.appendChild(a);
        return item;
    };

    /* Drop rustdoc's own "Crates" list (it lists every crate in the doc
       bundle, including stale dependency builds); the CSS above already
       hides it. The curated CRATES list below replaces it. */
    for (const crateList of elems.querySelectorAll("ul.block.crate")) {
        const heading = crateList.previousElementSibling;
        if (heading && heading.tagName === "H3") {
            heading.remove();
        }
        crateList.remove();
    }

    /* Everything rustdoc put in the sidebar becomes the "API" section... */
    const api = document.createElement("section");
    api.className = "techy-api-nav";
    while (elems.firstChild) {
        api.appendChild(elems.firstChild);
    }

    /* ...preceded by the pinned "Guide" section. */
    const guide = document.createElement("section");
    guide.className = "techy-guide-nav";
    guide.appendChild(sectionHeader("Guide"));
    const chapters = document.createElement("ul");
    chapters.className = "block";
    let onGuidePage = false;
    for (const [sub, title] of GUIDE_PAGES) {
        const url = href("techy", "guide/" + sub + "index.html");
        const item = linkItem(url, title);
        if (new URL(url).pathname === window.location.pathname) {
            item.className = "current";
            onGuidePage = true;
        }
        chapters.appendChild(item);
    }
    guide.appendChild(chapters);

    /* The workspace crates, current one highlighted. */
    const crates = document.createElement("ul");
    crates.className = "block techy-crates";
    for (const [name] of CRATES) {
        const item = linkItem(href(name, "index.html"), name);
        if (name === currentCrate) {
            item.className = "current";
        }
        crates.appendChild(item);
    }

    if (onGuidePage) {
        /* On a guide page, keep the page outline under "Guide" (the location
           header and the module-items index just duplicate the chapter list)
           and reduce "API" to the crate list. */
        const toc = api.querySelector("#rustdoc-toc");
        if (toc) {
            for (const child of Array.from(toc.children)) {
                const keep = child.classList.contains("top-toc") ||
                    (child.nextElementSibling !== null &&
                        child.nextElementSibling.classList.contains("top-toc"));
                if (!keep) {
                    child.remove();
                }
            }
            guide.appendChild(toc);
        }
        api.textContent = "";
    }

    elems.appendChild(guide);
    elems.appendChild(sectionHeader("API"));
    elems.appendChild(crates);
    elems.appendChild(api);
});
</script>