Skip to content

Commit

Permalink
correct formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed May 29, 2024
1 parent ebc50da commit 073d1a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum Element<'a> {
/// [label](#tag)
LabelledTag {
label: Vec<Element<'a>>,
tag: &'a str
tag: &'a str,
},
/// Represents a linebreak - \n
Linebreak,
Expand Down
23 changes: 10 additions & 13 deletions src/parser/parse_from_text/text_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ use nom::{
streaming::take_till1,
},
character::complete::char,
combinator::{peek, recognize, verify, consumed},
sequence::{tuple, delimited},
combinator::{consumed, peek, recognize, verify},
sequence::{delimited, tuple},
AsChar, IResult, Offset, Slice,
};

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

fn linebreak(input: &str) -> IResult<&str, char, CustomError<&str>> {
char('\n')(input)
Expand Down Expand Up @@ -123,22 +120,22 @@ fn labelled_tag(input: &str) -> IResult<&str, Element, CustomError<&str>> {
let (input, label) = delimited(
char('['),
take_while1(|c| !matches!(c, '[' | ']')),
char(']')
char(']'),
)(input)?;
let elements: Vec<Element> = parse_only_text(label);
let (input, tag) = delimited(
char('('),
take_while1(|c| !matches!(c, '(' | ')')),
char(')')
char(')'),
)(input)?;
let (_, (consumed, _output)) = consumed(hashtag)(tag)?;
if consumed == tag {
Ok((
input,
Element::LabelledTag {
label: elements,
tag: consumed,
}
input,
Element::LabelledTag {
label: elements,
tag: consumed,
},
))
} else {
Err(nom::Err::Error(CustomError::UnexpectedContent))
Expand Down
2 changes: 1 addition & 1 deletion tests/text_to_ast/text_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn labelled_hashtag() {
Tag("#world"),
]
);

let input_bold = "[**Hello**](#hi) ";
assert_eq!(
parse_only_text(input_bold),
Expand Down

0 comments on commit 073d1a3

Please sign in to comment.