surf_parse/lib.rs
1//! `surf-parse` — parser for the SurfDoc format.
2//!
3//! SurfDoc is a markdown superset with typed block directives, embedded data,
4//! and presentation hints. This crate provides the foundational parser that
5//! turns `.surf` (or `.md`) source text into a structured `SurfDoc` tree.
6//!
7//! # Quick start
8//!
9//! ```
10//! let result = surf_parse::parse("# Hello\n\n::callout[type=info]\nHi!\n::\n");
11//! assert!(result.diagnostics.is_empty());
12//! assert_eq!(result.doc.blocks.len(), 2);
13//! ```
14
15pub mod attrs;
16pub mod blocks;
17pub mod error;
18pub mod inline;
19pub mod parse;
20pub mod render_html;
21pub mod render_md;
22#[cfg(feature = "terminal")]
23pub mod render_term;
24pub mod types;
25pub mod validate;
26
27pub use error::*;
28pub use parse::parse;
29pub use types::*;
30
31pub use render_html::{PageConfig, SiteConfig, PageEntry, extract_site, render_site_page};
32
33impl SurfDoc {
34 /// Render this document as standard CommonMark markdown (no `::` markers).
35 pub fn to_markdown(&self) -> String {
36 render_md::to_markdown(self)
37 }
38
39 /// Render this document as an HTML fragment with `surfdoc-*` CSS classes.
40 pub fn to_html(&self) -> String {
41 render_html::to_html(self)
42 }
43
44 /// Render this document as a complete HTML page with SurfDoc discovery metadata.
45 pub fn to_html_page(&self, config: &PageConfig) -> String {
46 render_html::to_html_page(self, config)
47 }
48
49 /// Render this document as ANSI-colored terminal text.
50 #[cfg(feature = "terminal")]
51 pub fn to_terminal(&self) -> String {
52 render_term::to_terminal(self)
53 }
54
55 /// Validate this document and return any diagnostics.
56 pub fn validate(&self) -> Vec<crate::error::Diagnostic> {
57 validate::validate(self)
58 }
59}