Skip to main content

mbr_core/
lib.rs

1//! mbr-core — the render core of mbr, the markdown browser.
2//!
3//! Markdown rendering, templates, configuration, the repository scan, search,
4//! the task/link/tag indexes and the embedded web assets. Everything here is
5//! pure or touches the filesystem only at its edges; there is no HTTP server,
6//! file watcher, CLI, GUI or static-site generator in this crate, and the
7//! compiler enforces it: those live in `mbr-server`, `mbr-ssg` and the `mbr`
8//! binary, which depend on this crate and never the other way round. This is
9//! what the QuickLook staticlib (`mbr-ffi`) and a mobile shell build on.
10//!
11//! The one optional subsystem is `media-metadata` (ffmpeg/pdfium probes and
12//! the video transcode/remux pipeline), because the repository scan itself
13//! reads media metadata when it is on.
14
15/// Returns a reqwest `ClientBuilder` pre-configured with bundled Mozilla root
16/// certificates. This avoids reliance on the system certificate store, which
17/// may be absent in sandboxed or minimal Linux environments (e.g. Nix builds).
18pub fn http_client_builder() -> reqwest::ClientBuilder {
19    use std::sync::Arc;
20    let tls_config = rustls::ClientConfig::builder_with_provider(Arc::new(
21        rustls::crypto::ring::default_provider(),
22    ))
23    .with_safe_default_protocol_versions()
24    .expect("safe default protocol versions")
25    .with_root_certificates(Arc::new(rustls::RootCertStore::from_iter(
26        webpki_roots::TLS_SERVER_ROOTS.iter().cloned(),
27    )))
28    .with_no_client_auth();
29    reqwest::Client::builder().use_preconfigured_tls(tls_config)
30}
31
32/// Build a reqwest HTTP client with bundled Mozilla root certificates.
33pub fn http_client(timeout: std::time::Duration) -> reqwest::Client {
34    http_client_builder()
35        .timeout(timeout)
36        .build()
37        .expect("failed to build HTTP client")
38}
39
40pub mod assets;
41pub mod attrs;
42pub mod audio;
43pub mod cache;
44pub mod change_event;
45pub mod chat;
46pub mod config;
47pub mod constants;
48pub mod contact;
49pub mod edit_auth;
50#[cfg(test)]
51mod editor_math_parity;
52#[cfg(test)]
53mod editor_parity;
54pub mod embedded_hljs;
55pub mod embedded_katex;
56pub mod embedded_pico;
57pub mod errors;
58pub mod flashcards;
59pub mod html;
60pub mod icons;
61pub mod link_index;
62pub mod link_transform;
63pub mod markdown;
64pub mod media;
65pub mod oembed;
66pub mod oembed_cache;
67pub mod page_context;
68pub mod page_errors;
69pub mod path_resolver;
70#[cfg(feature = "media-metadata")]
71pub mod pdf_metadata;
72pub mod readability;
73pub mod relationships;
74pub mod repo;
75pub mod search;
76pub mod sorting;
77pub mod tag_index;
78pub mod task_index;
79pub mod task_query;
80pub mod tasks;
81pub mod templates;
82#[cfg(test)]
83mod test_support;
84pub mod url_helpers;
85pub mod url_path;
86pub mod vault;
87pub mod vid;
88#[cfg(feature = "media-metadata")]
89pub mod video_metadata;
90#[cfg(feature = "media-metadata")]
91pub mod video_metadata_cache;
92#[cfg(feature = "media-metadata")]
93pub mod video_remux;
94#[cfg(feature = "media-metadata")]
95pub mod video_transcode;
96#[cfg(feature = "media-metadata")]
97pub mod video_transcode_cache;
98pub mod wikilink;
99pub mod wikilink_index;
100
101pub use config::{Config, RelationType, SortField, TagSource, find_root_dir};
102#[cfg(feature = "media-metadata")]
103pub use errors::MetadataError;
104#[cfg(feature = "media-metadata")]
105pub use errors::PdfMetadataError;
106pub use errors::{BuildError, ConfigError, MbrError, SearchError, TaskIndexError};
107pub use markdown::{MarkdownRenderResult, ParsedDocument};
108pub use pulldown_cmark::{
109    Alignment, BlockQuoteKind, CodeBlockKind, Event, HeadingLevel, Tag, TagEnd,
110};
111pub use search::{SearchEngine, SearchQuery, SearchResponse, SearchResult, SearchScope};
112pub use sorting::sort_files;
113pub use task_index::{FileTasks, TaskIndex};
114pub use task_query::{
115    DueBucket, DueFilter, IncludeFilter, TaskGroup, TaskMode, TaskQuery, TaskQueryResponse,
116    due_bucket, parse_task_query, run_query,
117};
118pub use tasks::{
119    Annotations, MarkerRule, Task, TaskKind, TaskPriority, TaskStatus, parse_marker_line,
120    parse_task_line, scan_source_tasks, scan_source_tasks_with_markers, set_marker,
121    strip_annotations,
122};
123#[cfg(feature = "media-metadata")]
124pub use video_transcode::TranscodeError;