Skip to main content

docs_pipeline/
lib.rs

1//! # docs-pipeline
2//!
3//! Markdown rendering and syntax highlighting pipeline for documentation
4//! sites, extracted from the Tachyon knowledge base renderer.
5//!
6//! ## Modules
7//!
8//! - [`markdown`] — markdown → HTML/plain-text/AST rendering with GFM,
9//!   wikilinks, admonitions, embeds, block references, TOC extraction, and
10//!   ammonia-based sanitization.
11//! - [`syntax`] — tree-sitter based syntax highlighting with per-language
12//!   cargo features (`lang-rust`, `lang-python`, …), themeable CSS output,
13//!   and rendered-HTML code block highlighting.
14//! - [`latex`] — KaTeX equation rendering with `$`/`$$` placeholder handling
15//!   that skips `<pre>`/`<code>` content.
16//! - [`embeds`] — whitelisted rich-media embed rendering (YouTube, Figma,
17//!   Gist, CodePen, tweets) as sandboxed iframes.
18//! - [`sanitize`] — standalone HTML sanitization.
19//! - [`types`] — render options, output formats, results, metadata, themes,
20//!   and supported languages.
21//! - [`error`] — the pipeline error type.
22//!
23//! ## Example
24//!
25//! ```
26//! use docs_pipeline::{render_markdown, extract_toc};
27//!
28//! let md = "# Getting Started\n\nSome **bold** text.";
29//! let html = render_markdown(md);
30//! assert!(html.contains("<strong>bold</strong>"));
31//!
32//! let toc = extract_toc(md);
33//! assert_eq!(toc.len(), 1);
34//! assert_eq!(toc[0].text, "Getting Started");
35//! ```
36//!
37//! ## Syntax highlighting example
38//!
39//! ```
40//! # #[cfg(feature = "lang-rust")] {
41//! use docs_pipeline::syntax::SyntaxHighlighter;
42//!
43//! let hl = SyntaxHighlighter::new();
44//! assert!(hl.is_language_supported("rust"));
45//! let html = hl.highlight_or_fallback("fn main() {}", "rust");
46//! assert!(html.contains("syntax-highlight"));
47//! # }
48//! ```
49
50#![forbid(unsafe_code)]
51#![deny(missing_docs)]
52
53pub mod embeds;
54pub mod error;
55pub mod latex;
56pub mod markdown;
57pub mod sanitize;
58pub mod syntax;
59pub mod types;
60
61// Re-export commonly used items at the crate root.
62pub use embeds::{count_embeds, embed_csp_policy, is_domain_whitelisted, render_embed};
63pub use error::{Error, Result};
64pub use latex::{LatexDocumentRenderer, LatexRenderer};
65pub use markdown::{
66    extract_inline_toc, extract_toc, extract_toc_from_html, render_markdown, strip_html_tags,
67    try_render_markdown, BlockReference, EmbedBlock, HtmlTocEntry, MarkdownParser, TocEntry,
68};
69pub use sanitize::sanitize_html;
70pub use syntax::{highlight_code_blocks, SyntaxHighlighter};
71pub use types::{
72    Language, MarkdownOptions, OutputFormat, RenderMetadata, RenderOptions, RenderResult,
73    RenderStats, SyntaxTheme,
74};