dioxus_nox_markdown/lib.rs
1//! **⚠️ Disclaimer:** This crate was entirely generated by AI (Claude) as part of a
2//! personal learning project. It has not been battle-tested in production and may
3//! contain bugs or unsound abstractions. Use at your own risk and exercise extreme
4//! caution before depending on it in anything that matters.
5//!
6//! # Security
7//!
8//! Raw HTML in markdown is a potential XSS vector. This crate provides three
9//! rendering policies via [`HtmlRenderPolicy`](types::HtmlRenderPolicy):
10//!
11//! - **`Escape`** (default) — HTML tags are rendered as visible text. Safe for
12//! all inputs including untrusted user content.
13//! - **`Sanitized`** — HTML is cleaned with the [`ammonia`](https://docs.rs/ammonia)
14//! crate, stripping `<script>`, `<iframe>`, event handlers, etc. while keeping
15//! safe formatting tags. Requires the `sanitize` Cargo feature.
16//! - **`Trusted`** — HTML is injected directly into the DOM with **no sanitization**.
17//! Only use when you fully control the markdown source. **This is an XSS vector
18//! if used with user-generated content.**
19//!
20//! When in doubt, use the default `Escape` policy. If you need HTML rendering
21//! with user content, enable the `sanitize` feature and use `Sanitized`.
22
23pub mod components;
24pub mod context;
25pub mod highlight;
26pub mod hooks;
27pub mod ime_proxy;
28pub mod inline_editor;
29pub mod inline_tokens;
30pub mod interop;
31pub mod parser;
32pub mod reveal_engine;
33pub mod types;
34pub mod viewport;
35
36#[cfg(test)]
37mod tests;
38
39/// Prelude — import everything for typical consumer usage.
40pub mod prelude {
41 pub use crate::components::*;
42 pub use crate::context::{
43 CursorContext, MarkdownContext, MarkdownHandle, use_cursor_context, use_markdown_context,
44 use_markdown_handle,
45 };
46 pub use crate::highlight::{
47 HighlightResult, generate_theme_css, highlight_code, supported_languages,
48 wrap_with_line_numbers,
49 };
50 pub use crate::hooks::{use_debounced_parse, use_heading_index, use_viewport_height};
51 pub use crate::ime_proxy::ImeProxy;
52 pub use crate::inline_editor::InlineEditor;
53 pub use crate::parser::{index_to_line_col, parse_document, parse_document_with_policy};
54 pub use crate::types::{
55 ActiveBlockInputEvent, BlockEntry, CursorPosition, HeadingEntry, HtmlRenderPolicy, Layout,
56 LivePreviewVariant, Mode, Orientation, ParseOptions, ParseState, ParsedDoc, Selection,
57 SourceMap, SourceMapEntry, VimAction, VimMode, VimState,
58 };
59 pub use crate::viewport::EditorViewport;
60}
61
62/// Compound component namespace — `use dioxus_nox_markdown::markdown;` then `markdown::Root { ... }`.
63pub mod markdown {
64 pub use crate::components::{
65 Content, Divider, Editor, ModeBar, ModeTab, Preview, Root, Toolbar, ToolbarButton,
66 ToolbarSeparator,
67 };
68 pub use crate::ime_proxy::ImeProxy;
69 pub use crate::inline_editor::InlineEditor;
70 pub use crate::viewport::EditorViewport;
71}