Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed Jun 20, 2024
1 parent aa854b3 commit b402a68
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 143 deletions.
3 changes: 1 addition & 2 deletions src/parser/link_url/parse_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ fn iauthority(input: &str) -> IResult<&str, (&str, &str, bool), CustomError<&str
let (input, port) = opt(recognize(tuple((char(':'), take_while(is_digit)))))(input)?;
let userinfo = userinfo.unwrap_or("");
let port = port.unwrap_or("");
let len = userinfo.len()
.saturating_add(port.len());
let len = userinfo.len().saturating_add(port.len());

if let Some(out) = i.get(0..len) {
Ok((input, (out, host, is_ipv6_or_future)))
Expand Down
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pub mod is_emoji;
pub mod link_url;
pub mod parse_from_text;
pub mod utils;
pub mod unicode_ranges;
pub mod utils;

pub use crate::parser::link_url::LinkDestination;

Expand Down
9 changes: 3 additions & 6 deletions src/parser/parse_from_text/base_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Debug;

// Base utility parsers, used by both text and markdown parsers
use nom::{
bytes::complete::{tag, is_not},
bytes::complete::{is_not, tag},
error::{ErrorKind, ParseError},
sequence::delimited,
IResult,
Expand Down Expand Up @@ -71,11 +71,8 @@ pub(crate) fn direct_delimited<'a>(
return Err(nom::Err::Error(CustomError::NoElement));
}
let tag_str: &str = tag_str.unwrap();
let result: IResult<&str, &str> = delimited(
tag(tag_str),
is_not(tag_str),
tag(tag_str),
)(input);
let result: IResult<&str, &str> =
delimited(tag(tag_str), is_not(tag_str), tag(tag_str))(input);
if result.is_ok() {
let (input, content) = result.unwrap();
break (input, content, tag_str);
Expand Down
2 changes: 1 addition & 1 deletion src/parser/unicode_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// NOTE that they are sorted.
// --Farooq fkz riseup.net
// farooqkz testrun.org
pub const UNICODE_WHITESPACE_RANGES: [RangeInclusive<u32>; 339] =[
pub const UNICODE_WHITESPACE_RANGES: [RangeInclusive<u32>; 339] = [
0x21..=0x2f,
0x3a..=0x40,
0x5b..=0x60,
Expand Down
14 changes: 7 additions & 7 deletions src/parser/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::ops::RangeInclusive;
use super::unicode_ranges::UNICODE_PUNCTUATION_RANGES;
use std::ops::RangeInclusive;

#[derive(Debug, PartialEq, Eq)]
enum FindRangeResult<'a> {
Expand Down Expand Up @@ -82,19 +82,19 @@ pub(crate) fn is_white_space(c: char) -> bool {
}

pub(crate) fn is_unicode_white_space(c: char) -> bool {
is_white_space(c) ||
matches!(c as u32,
is_white_space(c)
|| matches!(c as u32,
0x20 |
0xa0 |
0x1680..=0x1680 |
0x2000..=0x200a |
0x202f..=0x202f |
0x205f..=0x205f |
0x3000..=0x3000)
// These ranges are extracted from unicode DB using
// the script /scripts/extract_unicode_whitespace_ranges.py
// -- Farooq fkz riseup.net
// farooqkz testrun.org
// These ranges are extracted from unicode DB using
// the script /scripts/extract_unicode_whitespace_ranges.py
// -- Farooq fkz riseup.net
// farooqkz testrun.org
}

pub(crate) fn is_unicode_punctuation(c: char) -> bool {
Expand Down
120 changes: 0 additions & 120 deletions src/parser/utils.rs.orig

This file was deleted.

6 changes: 2 additions & 4 deletions tests/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ fn link_with_username() {
let Ok((rest, link_destination)) = LinkDestination::parse(link) else {
panic!("Parsing {} as link failed", link);
};

assert!(link_destination.punycode.is_none());
assert_eq!(rest.len(), 0);
assert_eq!(link_destination.scheme, "https");
assert_eq!(link_destination.target, "https://[email protected]");
assert_eq!(link_destination.hostname, Some("example.com"));

}

#[test]
Expand All @@ -68,7 +67,7 @@ fn link_with_username_and_password() {
let Ok((rest, link_destination)) = LinkDestination::parse(link) else {
panic!("Parsing {} as link failed", link);
};

assert!(link_destination.punycode.is_none());
assert_eq!(rest.len(), 0);
assert_eq!(link_destination.scheme, "https");
Expand Down Expand Up @@ -189,7 +188,6 @@ fn generic_schemes() {
);
}


#[test]
fn dclogin_link() {
let link = "dclogin://[email protected]?p=L%265j%3A%40g%3C3%5C%5Crr&v=1";
Expand Down
6 changes: 4 additions & 2 deletions tests/text_to_ast/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,13 @@ fn extensive_italics() {
("_ foo bar_", vec![Text("_ foo bar_")]),
("foo_bar_", vec![Text("foo_bar_")]),
("a_\"foo\"_", vec![Text("a_\"foo\"_")]),
("foo-_(bar)_", vec![Text("foo-"), Italics(vec![Text("(bar)")])]),
(
"foo-_(bar)_",
vec![Text("foo-"), Italics(vec![Text("(bar)")])],
),
];

for (input, output) in input_output.iter() {
assert_eq!(parse_markdown_text(input), *output);
}

}

0 comments on commit b402a68

Please sign in to comment.