Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate regex and once_cell dependencies. #514

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ doc = false

[dependencies]
typed-arena = "2.0.2"
regex = "1"
once_cell = "1.19.0"
entities = "1.0.1"
unicode_categories = "0.1.1"
memchr = "2"
Expand Down
19 changes: 14 additions & 5 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use crate::nodes::{
};
use crate::parser::{Options, Plugins};
use crate::scanners;
use once_cell::sync::Lazy;
use regex::Regex;
use std::borrow::Cow;
use std::cell::Cell;
use std::collections::{HashMap, HashSet};
use std::io::{self, Write};
use std::str;
use unicode_categories::UnicodeCategories;

use crate::adapters::HeadingMeta;

Expand Down Expand Up @@ -102,11 +101,21 @@ impl Anchorizer {
/// assert_eq!("ticks-arent-in".to_string(), anchorizer.anchorize(source.to_string()));
/// ```
pub fn anchorize(&mut self, header: String) -> String {
static REJECTED_CHARS: Lazy<Regex> =
Lazy::new(|| Regex::new(r"[^\p{L}\p{M}\p{N}\p{Pc} -]").unwrap());
fn is_permitted_char(&c: &char) -> bool {
c == ' '
|| c == '-'
|| c.is_letter()
|| c.is_mark()
|| c.is_number()
|| c.is_punctuation_connector()
}

let mut id = header.to_lowercase();
id = REJECTED_CHARS.replace_all(&id, "").replace(' ', "-");
id = id
.chars()
.filter(is_permitted_char)
.map(|c| if c == ' ' { '-' } else { c })
.collect();

let mut uniq = 0;
id = loop {
Expand Down
3 changes: 1 addition & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,7 @@ pub struct RenderOptions {
///
/// options.render.full_info_string = true;
/// let html = markdown_to_html("``` rust extra info\nfn hello();\n```\n", &options);
/// let re = regex::Regex::new(r#"data-meta="extra info""#).unwrap();
/// assert!(re.is_match(&html));
/// assert!(html.contains(r#"data-meta="extra info""#));
/// ```
#[builder(default)]
pub full_info_string: bool,
Expand Down
Loading