mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-15 06:52:23 +00:00
* Add craft-wordmodel: WordCraft's document model without its editing code WordCraft's crates/doc (wordcraft-doc, at 07f97737) moved as it is, so the DOCX, RTF, ODT and other text-format crates can read into and write from one model. Module paths, type names and serde attributes are unchanged: an app that re-exports the crate keeps its native file format. Left in the app: range editing (edit.rs), IME text and equation editing. Not model, and already in craft-libs: code pages (craft-rtf), the ZIP entry-count check (craft-opc), the compound-file guard (craft-cfb). The paragraph walks moved to walk.rs and the unit helpers of wordcraft-geom to geom.rs. * craft-wordmodel: math_tree, the arguments of an equation node and a walk over its runs The DOCX reader and writer walk an equation's runs. The walk and the child accessors it uses were in WordCraft's equation editor (math_edit.rs), which stays in the app; they are structure, not editing. * craft-wordmodel: keep the document operations (edit.rs) with the model The DOCX and RTF readers use them: alternative-format chunks are merged into a document with adopt_blocks, and a reader formats ranges with format_range and inserts objects. They operate on the document, not on a view, so they belong beside it. The tests that drove them come back with them; the paragraph walks stay in walk.rs and edit re-exports them. base64 0.23, as WordCraft and craft-offcrypto use. * Add craft-flow: the flow model the text formats map to, on craft-wordmodel WordCraft's crates/formats/src/model (07f97737) moved as it is: Flow, FBlock, Para, Inline, Fmt, tables and cells, pictures, to_doc and from_doc, picture sniffing, colours, base64 and the Dropped report. Only the paths changed (wordcraft_doc is craft_wordmodel); the report helpers are public so the format crates can call them; the image re-encoding helper stays with WordCraft's RTF writer. * Add craft-markdown: Markdown read and written, on craft-flow WordCraft's crates/formats/src/markdown (07f97737) with its 35 tests, moved onto craft-flow and craft-wordmodel. Character references come from craft-html. The table cell budget lives in craft-flow, which names it in its warning. Two test lines that wrote plain text through WordCraft's txt module stay in WordCraft.
49 lines
1.7 KiB
Rust
49 lines
1.7 KiB
Rust
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
|
// The code came from an app whose lints allow this.
|
|
#![allow(clippy::type_complexity)]
|
|
//! Markdown: a CommonMark subset plus GitHub tables and strikethrough.
|
|
//!
|
|
//! Import: ATX and setext headings, paragraphs with soft/hard breaks, block quotes (→ Quote
|
|
//! style), fenced and indented code (→ one Code paragraph per line), thematic breaks (→ a
|
|
//! bottom-border paragraph), bullet and ordered lists (nested by indentation), GFM pipe tables,
|
|
//! and inlines: emphasis/strong (the CommonMark delimiter algorithm), `~~strike~~`, code spans,
|
|
//! inline links, autolinks, images (`data:` URIs become pictures, others their alt text),
|
|
//! backslash escapes, entities, HTML comments (`<!-- ... -->`), `<br>` and `<a id>` anchors.
|
|
//!
|
|
//! Export writes the same constructs; pictures become `` placeholders.
|
|
|
|
#[cfg(doctest)]
|
|
#[doc = include_str!("../README.md")]
|
|
struct ReadmeExamples;
|
|
|
|
use std::collections::HashMap;
|
|
use std::sync::Arc;
|
|
|
|
use craft_wordmodel::table::{MAX_COLS, MAX_ROWS};
|
|
use craft_wordmodel::{Align, Document};
|
|
|
|
use craft_flow::{self as model, Cell, FBlock, FTable, Fmt, Inline, Kind, ListInfo, Para, make_img};
|
|
|
|
mod blocks;
|
|
mod export;
|
|
mod inlines;
|
|
|
|
pub use craft_flow::MAX_TABLE_CELLS;
|
|
|
|
/// The text of an entity body (`amp`, `#38`, `#x26`).
|
|
fn decode_entity(body: &str) -> Option<String> {
|
|
craft_html::decode_entity(body).map(String::from)
|
|
}
|
|
|
|
pub use blocks::{Refs, import, import_on, parse};
|
|
pub use export::escape;
|
|
pub use export::export;
|
|
#[cfg(test)]
|
|
use export::{escape_line_start, inlines_md, table_md, write_blocks};
|
|
pub use inlines::parse_inlines;
|
|
|
|
#[cfg(test)]
|
|
use blocks::split_row;
|
|
#[cfg(test)]
|
|
mod tests;
|