Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace xmlparser by htmlparser #485

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ members = [
resolver = "2"

[workspace.dependencies]
htmlparser = { version = "0.1" }
similar-asserts = { version = "1.6" }
4 changes: 2 additions & 2 deletions packages/mrml-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ travis-ci = { repository = "jdrouet/mrml", branch = "main" }
[features]
default = ["json", "parse", "print", "render"]
json = ["dep:serde", "dep:serde_json", "indexmap/serde"]
parse = ["dep:xmlparser", "dep:thiserror"]
parse = ["dep:htmlparser", "dep:thiserror"]
print = ["dep:enum_dispatch"]
render = ["dep:enum-as-inner", "dep:thiserror"]
async = ["dep:async-trait"]
Expand All @@ -39,7 +39,7 @@ http-loader-ureq = ["dep:ureq", "http-loader-base"]
async-trait = { version = "0.1", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
xmlparser = { version = "0.13", optional = true }
htmlparser = { workspace = true, optional = true }
indexmap = { version = "2.6", default-features = false }
rustc-hash = { version = "2.0", default-features = false }
thiserror = { version = "1.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/lib/html-compare/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ repository = "https://github.com/jdrouet/mrml"
colored = "2.0"
css-compare = { path = "../css-compare", version = "0.1" }
similar-asserts = { workspace = true }
htmlparser = "0.1"
htmlparser = { workspace = true }
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_attributes/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::MjAttributesChild;
use crate::mj_attributes_all::NAME as MJ_ALL;
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_attributes_class/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::{MjAttributesClass, MjAttributesClassAttributes};
use crate::prelude::hash::Map;
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_attributes_element/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::MjAttributesElement;
use crate::prelude::hash::Map;
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_body/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::MjBodyChild;
use crate::comment::Comment;
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_breakpoint/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::MjBreakpointAttributes;
#[cfg(feature = "async")]
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_font/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::MjFontAttributes;
#[cfg(feature = "async")]
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_head/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::MjHeadChild;
use crate::comment::Comment;
Expand Down
4 changes: 2 additions & 2 deletions packages/mrml-core/src/mj_include/body/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::{MjIncludeBody, MjIncludeBodyAttributes, MjIncludeBodyChild, MjIncludeBodyKind};
use crate::comment::Comment;
Expand Down Expand Up @@ -366,7 +366,7 @@ impl crate::prelude::parser::AsyncParseElement<MjIncludeBody> for AsyncMrmlParse

#[cfg(test)]
mod tests {
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use crate::mj_include::body::{MjIncludeBody, MjIncludeBodyKind};
use crate::prelude::parser::memory_loader::MemoryIncludeLoader;
Expand Down
4 changes: 2 additions & 2 deletions packages/mrml-core/src/mj_include/head/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::{MjIncludeHead, MjIncludeHeadAttributes, MjIncludeHeadChild, MjIncludeHeadKind};
use crate::comment::Comment;
Expand Down Expand Up @@ -325,7 +325,7 @@ impl MjIncludeHeadKind {

#[cfg(test)]
mod tests {
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use crate::mj_include::head::{MjIncludeHead, MjIncludeHeadKind};
use crate::prelude::parser::memory_loader::MemoryIncludeLoader;
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_raw/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::MjRawChild;
use crate::comment::Comment;
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mj_style/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::MjStyleAttributes;
#[cfg(feature = "async")]
Expand Down
2 changes: 1 addition & 1 deletion packages/mrml-core/src/mjml/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use xmlparser::StrSpan;
use htmlparser::StrSpan;

use super::{Mjml, MjmlAttributes, MjmlChildren};
use crate::mj_body::NAME as MJ_BODY;
Expand Down
6 changes: 3 additions & 3 deletions packages/mrml-core/src/prelude/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::marker::PhantomData;

use xmlparser::{StrSpan, Tokenizer};
use htmlparser::{StrSpan, Tokenizer};

use self::loader::IncludeLoaderError;
use super::hash::Map;
Expand Down Expand Up @@ -56,12 +56,12 @@ pub enum Error {
/// The input string should be smaller than 4GiB.
#[error("size limit reached in {origin}")]
SizeLimit { origin: Origin },
/// Errors detected by the `xmlparser` crate.
/// Errors detected by the `htmlparser` crate.
#[error("unable to parse next template in {origin}")]
ParserError {
origin: Origin,
#[source]
source: xmlparser::Error,
source: htmlparser::Error,
},
/// The Mjml document must have at least one element.
#[error("unable to find mjml element")]
Expand Down
10 changes: 6 additions & 4 deletions packages/mrml-core/src/prelude/parser/token.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::Display;

use xmlparser::{StrSpan, Token};
use htmlparser::{StrSpan, Token};

use super::MrmlCursor;

Expand Down Expand Up @@ -47,6 +47,8 @@ impl<'a> From<Token<'a>> for Span {
| Token::ElementStart { span, .. }
| Token::EmptyDtd { span, .. }
| Token::EntityDeclaration { span, .. }
| Token::ConditionalCommentStart { span, .. }
| Token::ConditionalCommentEnd { span, .. }
| Token::ProcessingInstruction { span, .. } => span.into(),
Token::Text { text } => text.into(),
}
Expand Down Expand Up @@ -82,19 +84,19 @@ impl<'a> MrmlToken<'a> {
})),
Token::Comment { text, span } => Ok(MrmlToken::Comment(Comment { span, text })),
Token::ElementEnd {
end: xmlparser::ElementEnd::Close(prefix, local),
end: htmlparser::ElementEnd::Close(prefix, local),
span,
} => Ok(MrmlToken::ElementClose(ElementClose {
span,
prefix,
local,
})),
Token::ElementEnd {
end: xmlparser::ElementEnd::Empty,
end: htmlparser::ElementEnd::Empty,
span,
} => Ok(MrmlToken::ElementEnd(ElementEnd { span, empty: true })),
Token::ElementEnd {
end: xmlparser::ElementEnd::Open,
end: htmlparser::ElementEnd::Open,
span,
} => Ok(MrmlToken::ElementEnd(ElementEnd { span, empty: false })),
Token::ElementStart {
Expand Down
Loading