Skip to content

Commit

Permalink
add labelled hashtags
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed May 29, 2024
1 parent f631e41 commit ebc50da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
17 changes: 7 additions & 10 deletions src/parser/parse_from_text/text_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::hashtag_content_char_ranges::hashtag_content_char;
use super::Element;
use nom::{
bytes::{
complete::{tag, take, take_while, take_while1, is_not},
complete::{tag, take, take_while, take_while1},
streaming::take_till1,
},
character::complete::char,
Expand All @@ -14,7 +14,10 @@ use nom::{
AsChar, IResult, Offset, Slice,
};

use super::base_parsers::CustomError;
use super::{
parse_only_text,
base_parsers::CustomError,
};

fn linebreak(input: &str) -> IResult<&str, char, CustomError<&str>> {
char('\n')(input)
Expand Down Expand Up @@ -122,13 +125,7 @@ fn labelled_tag(input: &str) -> IResult<&str, Element, CustomError<&str>> {
take_while1(|c| !matches!(c, '[' | ']')),
char(']')
)(input)?;
println!("Label: {label}");
let mut remaining = label;
let mut elements: Vec<Element> = vec![];
while let Ok((remaining, elm)) = parse_text_element(label, None) {
elements.push(elm);
}
println!("Elements: {:?}", elements);
let elements: Vec<Element> = parse_only_text(label);
let (input, tag) = delimited(
char('('),
take_while1(|c| !matches!(c, '(' | ')')),
Expand Down Expand Up @@ -159,7 +156,7 @@ pub(crate) fn parse_text_element(
// Also as this is the text element parser,
// text elements parsers MUST NOT call the parser for markdown elements internally
{
println!("{:?}", labelled_tag(input));
//println!("{:?}", labelled_tag(input));
}
if let Ok((i, elm)) = labelled_tag(input) {
Ok((i, elm))
Expand Down
19 changes: 2 additions & 17 deletions tests/text_to_ast/text_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ fn labelled_hashtag() {
label: vec![Text("Hello")],
tag: "#hello",
},
Text(" "),
Tag("#world"),
]
);
Expand All @@ -193,28 +194,12 @@ fn labelled_hashtag() {
parse_only_text(input_bold),
vec![
LabelledTag {
label: vec![Bold(vec![Text("Hello")])],
label: vec![Text("**Hello**")],
tag: "#hi",
},
Text(" ")
]
);

let input_bold_and_italic = "Hello this is a [_labeled_ **hashtag**](#tag)";
assert_eq!(
parse_only_text(input_bold_and_italic),
vec![
Text("Hello this is a "),
LabelledTag {
label: vec![
Italics(vec![Text("labeled")]),
Text(" "),
Bold(vec![Text("hashtag")]),
],
tag: "#tag",
}
]
);
}

#[test]
Expand Down

0 comments on commit ebc50da

Please sign in to comment.