diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/Cargo.lock b/Cargo.lock index d430cbb..90a9e32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,7 +181,7 @@ checksum = "377af281d8f23663862a7c84623bc5dcf7f8c44b13c7496a590bdc157f941a43" dependencies = [ "proc-macro2", "quote", - "syn 2.0.16", + "syn 2.0.58", "synstructure", ] @@ -289,6 +289,7 @@ name = "jotdown" version = "0.3.2" dependencies = [ "databake", + "serde", ] [[package]] @@ -405,9 +406,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -444,22 +445,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.152" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 1.0.107", + "syn 2.0.58", ] [[package]] @@ -486,9 +487,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.16" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -503,7 +504,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.16", + "syn 2.0.58", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 012cf4e..9f74482 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,3 +46,4 @@ parser = [] [dependencies] databake = { version = "0.1.7", features = ["derive"] } +serde = { version = "1.0.197", features = ["derive"] } diff --git a/bench/criterion/Cargo.toml b/bench/criterion/Cargo.toml index f54283e..4ab7544 100644 --- a/bench/criterion/Cargo.toml +++ b/bench/criterion/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dev-dependencies] criterion = { version = "0.4", default-features = false } bench-input = { path = "../input" } -jotdown = { path = "../../" } +jotdown = { path = "../../", features = ["html", "parser"] } [[bench]] name = "criterion" diff --git a/examples/jotdown_wasm/Cargo.toml b/examples/jotdown_wasm/Cargo.toml index 3593138..b675931 100644 --- a/examples/jotdown_wasm/Cargo.toml +++ b/examples/jotdown_wasm/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/hellux/jotdown" crate-type = ["cdylib"] [dependencies] -jotdown = { path = "../../" } +jotdown = { path = "../../", features = ["parser"] } wasm-bindgen = { version = "0.2", default-features = false } [dependencies.web-sys] diff --git a/jotdown b/jotdown new file mode 100755 index 0000000..fc42398 Binary files /dev/null and b/jotdown differ diff --git a/src/attr.rs b/src/attr.rs index ffe178e..19a3d3e 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -1,4 +1,5 @@ use databake::Bake; +use serde::{Deserialize, Serialize}; use crate::CowStr; use std::{borrow::Cow, fmt}; @@ -35,7 +36,7 @@ pub fn valid(src: &str) -> usize { /// Stores an attribute value that supports backslash escapes of ASCII punctuation upon displaying, /// without allocating. -#[derive(Clone, Debug, Eq, PartialEq, Bake)] +#[derive(Clone, Debug, Eq, PartialEq, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] pub struct AttributeValue<'s> { raw: CowStr<'s>, @@ -123,9 +124,9 @@ impl<'s> Iterator for AttributeValueParts<'s> { // Attributes are relatively rare, we choose to pay 8 bytes always and sometimes an extra // indirection instead of always 24 bytes. #[allow(clippy::box_vec)] -#[derive(Clone, PartialEq, Eq, Default, Bake)] +#[derive(Clone, PartialEq, Eq, Default, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] -pub struct Attributes<'s>(pub Option)]>>); +pub struct Attributes<'s>(#[serde(borrow)] pub Option)]>>); impl<'s> Attributes<'s> { /// Create an empty collection. diff --git a/src/lib.rs b/src/lib.rs index ae87054..12b1051 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,7 @@ mod lex; pub use attr::{AttributeValue, AttributeValueParts, Attributes}; use databake::Bake; +use serde::{Deserialize, Serialize}; type CowStr<'s> = std::borrow::Cow<'s, str>; @@ -203,7 +204,7 @@ impl<'s> AsRef> for &Event<'s> { /// multiple events. [`Container`] elements are represented by a [`Event::Start`] followed by /// events representing its content, and finally a [`Event::End`]. Atomic elements without any /// inside elements are represented by a single event. -#[derive(Debug, Clone, PartialEq, Eq, Bake)] +#[derive(Debug, Clone, PartialEq, Eq, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] pub enum Event<'s> { /// Start of a container. @@ -251,7 +252,7 @@ pub enum Event<'s> { /// - inline, may only contain inline elements, /// - block leaf, may only contain inline elements, /// - block container, may contain any block-level elements. -#[derive(Debug, Clone, PartialEq, Eq, Bake)] +#[derive(Debug, Clone, PartialEq, Eq, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] pub enum Container<'s> { /// A blockquote element. @@ -406,7 +407,7 @@ impl<'s> Container<'s> { } /// Alignment of a table column. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] pub enum Alignment { Unspecified, @@ -416,7 +417,7 @@ pub enum Alignment { } /// The type of an inline span link. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] pub enum SpanLinkType { /// E.g. `[text](url)` @@ -428,7 +429,7 @@ pub enum SpanLinkType { } /// The type of an inline link. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] pub enum LinkType { /// E.g. `[text](url)`. @@ -440,7 +441,7 @@ pub enum LinkType { } /// The type of a list. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] pub enum ListKind { /// A bullet list. @@ -456,7 +457,7 @@ pub enum ListKind { } /// Numbering type of an ordered list. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] pub enum OrderedListNumbering { /// Decimal numbering, e.g. `1)`. @@ -472,7 +473,7 @@ pub enum OrderedListNumbering { } /// Style of an ordered list. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)] #[databake(path = jotdown)] pub enum OrderedListStyle { /// Number is followed by a period, e.g. `1.`. diff --git a/tests/afl/Cargo.toml b/tests/afl/Cargo.toml index 70e156b..ff67fd6 100644 --- a/tests/afl/Cargo.toml +++ b/tests/afl/Cargo.toml @@ -6,7 +6,7 @@ default-run = "main" [dependencies] afl = "0.11" -jotdown = { path = "../../", features = ["deterministic"] } +jotdown = { path = "../../", features = ["deterministic", "html", "parser"] } html5ever = "0.26" [[bin]] diff --git a/tests/html-ref/Cargo.toml b/tests/html-ref/Cargo.toml index b46b4cc..5f712af 100644 --- a/tests/html-ref/Cargo.toml +++ b/tests/html-ref/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -jotdown = { path = "../.." } +jotdown = { path = "../..", features = ["html", "parser"] } [lib] name = "test_html_ref" diff --git a/tests/html-ref/ref.rs b/tests/html-ref/ref.rs deleted file mode 100644 index 8b13789..0000000 --- a/tests/html-ref/ref.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/html-ut/Cargo.toml b/tests/html-ut/Cargo.toml index f372f86..0d3f14d 100644 --- a/tests/html-ut/Cargo.toml +++ b/tests/html-ut/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -jotdown = { path = "../.." } +jotdown = { path = "../..", features = ["html", "parser"] } [lib] name = "test_html_ut" diff --git a/tests/html-ut/ut/footnotes.rs b/tests/html-ut/ut/footnotes.rs deleted file mode 100644 index 19a1eb5..0000000 --- a/tests/html-ut/ut/footnotes.rs +++ /dev/null @@ -1,66 +0,0 @@ -use crate::compare; - -// Footnote references may appear within a footnote. -#[test] -fn test_1c8325a() { - let src = r##"[^a] - -[^a]: a[^b][^c] -[^b]: b -"##; - let expected = r##"

1

-
-
-
    -
  1. -

    a23↩︎︎

    -
  2. -
  3. -

    b↩︎︎

    -
  4. -
  5. -

    ↩︎︎

    -
  6. -
-
-"##; - compare!(src, expected); -} - -// Footnote references in unreferenced footnotes are ignored. -#[test] -fn test_9eab5c8() { - let src = r##"para - -[^a]: a[^b][^c] -[^b]: b -"##; - let expected = r##"

para

-"##; - compare!(src, expected); -} - -// Footnotes may appear within footnotes. -#[test] -fn test_041f54c() { - let src = r##"[^b] -[^a] - -[^a]: [^b]: inner -"##; - let expected = r##"

1 -2

-
-
-
    -
  1. -

    inner↩︎︎

    -
  2. -
  3. -

    ↩︎︎

    -
  4. -
-
-"##; - compare!(src, expected); -} diff --git a/tests/html-ut/ut/lists.rs b/tests/html-ut/ut/lists.rs deleted file mode 100644 index 6230f6a..0000000 --- a/tests/html-ut/ut/lists.rs +++ /dev/null @@ -1,27 +0,0 @@ -use crate::compare; - -#[test] -fn test_fefa2dc() { - let src = r##"1. item - -para -"##; - let expected = r##"
    -
  1. -item -
  2. -
-

para

-"##; - compare!(src, expected); -} - -// Only single letter alphabetic list markers. -#[test] -fn test_2a0aa95() { - let src = r##"word. Continuing paragraph. -"##; - let expected = r##"

word. Continuing paragraph.

-"##; - compare!(src, expected); -} diff --git a/tests/html-ut/ut/mod.rs b/tests/html-ut/ut/mod.rs deleted file mode 100644 index 6fea8e3..0000000 --- a/tests/html-ut/ut/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod footnotes; -mod lists; -mod raw_blocks; diff --git a/tests/html-ut/ut/raw_blocks.rs b/tests/html-ut/ut/raw_blocks.rs deleted file mode 100644 index 6f7c8ee..0000000 --- a/tests/html-ut/ut/raw_blocks.rs +++ /dev/null @@ -1,24 +0,0 @@ -use crate::compare; - -#[test] -fn test_bf9dbab() { - let src = r##"```=html - - -``` - -paragraph - -```=html - - -``` -"##; - let expected = r##" - -

paragraph

-
-
-"##; - compare!(src, expected); -}