-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #140
- Loading branch information
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ mod sel_html; | |
mod sel_image; | ||
mod sel_link; | ||
mod sel_list_item; | ||
mod sel_paragraph; | ||
mod sel_section; | ||
|
||
pub use api::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::matcher::StringMatcher; | ||
use crate::parsing_iter::ParsingIterator; | ||
use crate::select::base::Selector; | ||
use crate::select::{ParseResult, SELECTOR_SEPARATOR}; | ||
use crate::tree::Paragraph; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct ParagraphSelector { | ||
matcher: StringMatcher, | ||
} | ||
|
||
impl ParagraphSelector { | ||
pub fn read(iter: &mut ParsingIterator) -> ParseResult<Self> { | ||
iter.require_char(':')?; | ||
iter.require_whitespace_or(SELECTOR_SEPARATOR, "P:")?; | ||
let matcher = StringMatcher::read(iter, SELECTOR_SEPARATOR)?; | ||
Ok(Self { matcher }) | ||
} | ||
} | ||
|
||
impl<'a> Selector<'a, &'a Paragraph> for ParagraphSelector { | ||
fn matches(&self, paragraph: &'a Paragraph) -> bool { | ||
self.matcher.matches_inlines(¶graph.body) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
[given] | ||
md = ''' | ||
Hello, world. | ||
> Paragraph within a block quote. | ||
This paragraph has _inline_ **formatting**. | ||
''' | ||
|
||
|
||
[expect."all"] | ||
cli_args = ["P:"] | ||
output = ''' | ||
Hello, world. | ||
----- | ||
Paragraph within a block quote. | ||
----- | ||
This paragraph has _inline_ **formatting**. | ||
''' | ||
|
||
|
||
[expect."all but with explicit all-matcher"] | ||
cli_args = ["P: *"] | ||
output = ''' | ||
Hello, world. | ||
----- | ||
Paragraph within a block quote. | ||
----- | ||
This paragraph has _inline_ **formatting**. | ||
''' | ||
|
||
|
||
[expect."select within a block quote"] | ||
cli_args = ["P: block"] | ||
output = ''' | ||
Paragraph within a block quote. | ||
''' | ||
|
||
|
||
[expect."matcher ignores inline formatting"] | ||
cli_args = ["P: has inline"] | ||
# The markdown is "has _inline_", but the emphasis formatting is ignored for matching. It's still used for output. | ||
output = ''' | ||
This paragraph has _inline_ **formatting**. | ||
''' | ||
|
||
|
||
[expect."no colon after p"] | ||
cli_args = ["P *"] | ||
expect_success = false | ||
output = ''' | ||
''' | ||
|
||
|
||
[expect."space before colon"] | ||
cli_args = ["P : *"] | ||
expect_success = false | ||
output = ''' | ||
''' |