Skip to main content

max / docengine

2.4 KB · 72 lines History Blame Raw
1 //! Configurable markdown-to-HTML rendering with sanitization presets.
2 //!
3 //! Provides four rendering presets for different trust levels:
4 //! - **Permissive** -- full GFM (tables, footnotes, images, raw HTML). For trusted content.
5 //! - **Standard** -- GFM without images. For app text fields.
6 //! - **Strict** -- no images, no raw HTML, dangerous scheme filtering, nofollow. For UGC.
7 //! - **Sanitize-only** -- ammonia cleaning without markdown parsing. For external HTML.
8 //!
9 //! Optional features add document loading, TOML frontmatter, @mention resolution,
10 //! and quote attribution post-processing.
11
12 #[cfg(any(feature = "mentions", test))]
13 mod code_spans;
14 mod escape;
15 mod render;
16 mod sanitize;
17 mod text;
18 mod toc;
19
20 #[cfg(feature = "directives")]
21 mod directives;
22 #[cfg(feature = "doc-loader")]
23 mod doc_loader;
24 #[cfg(feature = "frontmatter")]
25 mod frontmatter;
26 #[cfg(feature = "mentions")]
27 mod mentions;
28 #[cfg(feature = "quotes")]
29 mod quotes;
30 #[cfg(feature = "media-urls")]
31 mod media_urls;
32
33 // Re-export core types
34 pub use render::{RenderResult, Renderer};
35 pub use sanitize::SanitizePreset;
36 pub use text::{extract_title, reading_time_minutes, strip_first_heading, word_count};
37 pub use toc::{TocEntry, extract_toc, render_toc_html};
38
39 // Re-export feature-gated types
40 #[cfg(feature = "directives")]
41 pub use directives::post_process_directives;
42 #[cfg(feature = "doc-loader")]
43 pub use doc_loader::{DocIndexEntry, DocLoader, DocLoaderConfig, DocPage, DocSearchEntry};
44 #[cfg(feature = "frontmatter")]
45 pub use frontmatter::{Frontmatter, parse_frontmatter};
46 #[cfg(feature = "mentions")]
47 pub use mentions::{extract_mentions, resolve_mentions};
48 #[cfg(feature = "quotes")]
49 pub use quotes::{QuoteAuthor, post_process_quotes};
50 #[cfg(feature = "media-urls")]
51 pub use media_urls::{img_to_video, rewrite_media_paths};
52
53 /// Render markdown with the permissive preset (GFM features, default ammonia).
54 pub fn render_permissive(markdown: &str) -> String {
55 Renderer::permissive().render(markdown)
56 }
57
58 /// Render markdown with the standard preset (GFM features, no images).
59 pub fn render_standard(markdown: &str) -> String {
60 Renderer::standard().render(markdown)
61 }
62
63 /// Render markdown with the strict preset (no images, no raw HTML, nofollow).
64 pub fn render_strict(markdown: &str) -> String {
65 Renderer::strict().render(markdown)
66 }
67
68 /// Sanitize HTML without markdown parsing.
69 pub fn sanitize_html(html: &str) -> String {
70 Renderer::sanitize_only().sanitize_html(html)
71 }
72