Skip to content

Commit

Permalink
Support CRLF Newline (#5)
Browse files Browse the repository at this point in the history
Additionally to simple space, tab and Unix new line (\n) also support
Windows new line (\r\n) wherever whitespaces are supported
  • Loading branch information
kelko authored Oct 18, 2022
1 parent 5f17878 commit f7f9509
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "html-streaming-editor"
version = "0.7.0"
version = "0.7.1"
edition = "2021"
authors = [":kelko: <kelko@me.com>"]
repository = "https://github.com/kelko/html-streaming-editor"
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn build_css_path<'a>(
parser! {
pub grammar grammar() for str {
rule whitespace()
= quiet!{[' ' | '\n' | '\t']+}
= quiet!{([' ' | '\n' | '\t'] / "\r\n")+}
rule pipeline_marker()
= whitespace()? "|" whitespace()?
rule assign_marker()
Expand Down
16 changes: 16 additions & 0 deletions src/parsing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ fn parse_pipeline_with_newlines_and_whitespaces() {
);
}

#[test]
fn parse_pipeline_with_crlf_newlines() {
let parsed = super::grammar::pipeline("EXTRACT-ELEMENT{a}\r\n| REMOVE-ELEMENT{b}");
assert_eq!(
parsed,
Ok(ElementProcessingPipeline::new(vec![
ElementProcessingCommand::ExtractElement(CssSelectorList::new(vec![
CssSelectorPath::single(CssSelector::for_element("a"))
])),
ElementProcessingCommand::RemoveElement(CssSelectorList::new(vec![
CssSelectorPath::single(CssSelector::for_element("b"))
])),
]))
);
}

#[test]
fn parse_extract_element() {
let parsed = super::grammar::element_processing_command("EXTRACT-ELEMENT{a}");
Expand Down

0 comments on commit f7f9509

Please sign in to comment.