mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 08:35:28 +00:00
update escapes removing logic
This commit is contained in:
parent
ca29f68f69
commit
84167ad745
10 changed files with 18 additions and 45 deletions
|
|
@ -81,15 +81,15 @@ impl Tags {
|
||||||
reference::render_links(buffer, base, link_color, links);
|
reference::render_links(buffer, base, link_color, links);
|
||||||
|
|
||||||
// Cleanup unformatted escape chars
|
// Cleanup unformatted escape chars
|
||||||
for escapes in ESCAPES {
|
for e in ESCAPE_ENTRIES {
|
||||||
for escape in *escapes {
|
let mut cursor = buffer.start_iter();
|
||||||
let mut cursor = buffer.start_iter();
|
while let Some((mut match_start, mut match_end)) =
|
||||||
while let Some((mut match_start, mut match_end)) =
|
cursor.forward_search(e, TextSearchFlags::CASE_INSENSITIVE, None)
|
||||||
cursor.forward_search(escape, TextSearchFlags::CASE_INSENSITIVE, None)
|
{
|
||||||
{
|
if match_end.backward_cursor_positions(1) {
|
||||||
buffer.delete(&mut match_start, &mut match_end);
|
buffer.delete(&mut match_start, &mut match_end)
|
||||||
cursor = match_end;
|
|
||||||
}
|
}
|
||||||
|
cursor = match_end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,10 +103,8 @@ impl Tags {
|
||||||
s = reference::strip_tags(&s);
|
s = reference::strip_tags(&s);
|
||||||
s = strike::strip_tags(&s);
|
s = strike::strip_tags(&s);
|
||||||
s = underline::strip_tags(&s);
|
s = underline::strip_tags(&s);
|
||||||
for escapes in ESCAPES {
|
for e in ESCAPE_ENTRIES {
|
||||||
for escape in *escapes {
|
s = s.replace(e, &e[1..]);
|
||||||
s = s.replace(escape, "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
})
|
})
|
||||||
|
|
@ -118,17 +116,12 @@ pub fn format_header_fragment(value: &str) -> GString {
|
||||||
Uri::escape_string(&value.to_lowercase().replace(" ", "-"), None, true)
|
Uri::escape_string(&value.to_lowercase().replace(" ", "-"), None, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const ESCAPES: &[&[&str]] = &[
|
const ESCAPE_ENTRIES: &[&str] = &[
|
||||||
&["\\\n"],
|
"\\\n", "\\\\", "\\>", "\\`", "\\!", "\\[", "\\]", "\\(", "\\)", "\\*", "\\#", "\\~", "\\_",
|
||||||
bold::ESCAPES,
|
|
||||||
// same with pre
|
|
||||||
// code::ESCAPES,
|
|
||||||
header::ESCAPES,
|
|
||||||
// same with bold and reference
|
|
||||||
// list::ESCAPES,
|
|
||||||
pre::ESCAPES,
|
|
||||||
quote::ESCAPES,
|
|
||||||
reference::ESCAPES,
|
|
||||||
strike::ESCAPES,
|
|
||||||
underline::ESCAPES,
|
|
||||||
];
|
];
|
||||||
|
#[test]
|
||||||
|
fn test_escape_entries() {
|
||||||
|
for e in ESCAPE_ENTRIES {
|
||||||
|
assert_eq!(e.len(), 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ use regex::Regex;
|
||||||
|
|
||||||
const REGEX_BOLD: &str = r"\*\*(?P<text>[^*]+)\*\*";
|
const REGEX_BOLD: &str = r"\*\*(?P<text>[^*]+)\*\*";
|
||||||
|
|
||||||
pub const ESCAPES: &[&str] = &["\\*"]; // same with list
|
|
||||||
|
|
||||||
pub struct Bold(TextTag);
|
pub struct Bold(TextTag);
|
||||||
|
|
||||||
impl Bold {
|
impl Bold {
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,6 @@ use syntax::Syntax;
|
||||||
|
|
||||||
const REGEX_CODE: &str = r"(?s)```[ \t]*(?P<alt>.*?)\n(?P<data>.*?)```";
|
const REGEX_CODE: &str = r"(?s)```[ \t]*(?P<alt>.*?)\n(?P<data>.*?)```";
|
||||||
|
|
||||||
// same with pre
|
|
||||||
// pub const ESCAPES: &[&str] = &["\\`"];
|
|
||||||
|
|
||||||
struct Entry {
|
struct Entry {
|
||||||
alt: Option<String>,
|
alt: Option<String>,
|
||||||
data: String,
|
data: String,
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
const REGEX_HEADER: &str = r"(?m)^(?P<level>#{1,6})\s+(?P<title>.*)$";
|
const REGEX_HEADER: &str = r"(?m)^(?P<level>#{1,6})\s+(?P<title>.*)$";
|
||||||
|
|
||||||
pub const ESCAPES: &[&str] = &["\\#"];
|
|
||||||
|
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
h1: TextTag,
|
h1: TextTag,
|
||||||
h2: TextTag,
|
h2: TextTag,
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,6 @@ use regex::Regex;
|
||||||
const REGEX_LIST: &str =
|
const REGEX_LIST: &str =
|
||||||
r"(?m)^(?P<level>[ \t]*)\*[ \t]+(?:(?P<state>\[[ xX]\])[ \t]+)?(?P<text>.*)";
|
r"(?m)^(?P<level>[ \t]*)\*[ \t]+(?:(?P<state>\[[ xX]\])[ \t]+)?(?P<text>.*)";
|
||||||
|
|
||||||
// same with bold and reference
|
|
||||||
// pub const ESCAPES: &[&str] = &["\\*","\\[","\\]"];
|
|
||||||
|
|
||||||
struct State(bool);
|
struct State(bool);
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,6 @@ const REGEX_PRE: &str = r"`(?P<text>[^`]+)`";
|
||||||
const TAG_FONT: &str = "monospace"; // @TODO
|
const TAG_FONT: &str = "monospace"; // @TODO
|
||||||
const TAG_SCALE: f64 = 0.9;
|
const TAG_SCALE: f64 = 0.9;
|
||||||
|
|
||||||
pub const ESCAPES: &[&str] = &["\\`"]; // same with code
|
|
||||||
|
|
||||||
pub struct Pre(TextTag);
|
pub struct Pre(TextTag);
|
||||||
|
|
||||||
impl Pre {
|
impl Pre {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ use regex::Regex;
|
||||||
|
|
||||||
const REGEX_QUOTE: &str = r"(?m)>\s*(?P<text>.*)$";
|
const REGEX_QUOTE: &str = r"(?m)>\s*(?P<text>.*)$";
|
||||||
|
|
||||||
pub const ESCAPES: &[&str] = &["\\>"];
|
|
||||||
|
|
||||||
pub struct Quote(TextTag);
|
pub struct Quote(TextTag);
|
||||||
|
|
||||||
impl Quote {
|
impl Quote {
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ const REGEX_IMAGE: &str = r"!\[(?P<alt>[^\]]*)\]\((?P<url>[^\)]+)\)";
|
||||||
const REGEX_IMAGE_LINK: &str =
|
const REGEX_IMAGE_LINK: &str =
|
||||||
r"\[(?P<is_img>!)\[(?P<alt>[^\]]*)\]\((?P<img_url>[^\)]+)\)\]\((?P<link_url>[^\)]+)\)";
|
r"\[(?P<is_img>!)\[(?P<alt>[^\]]*)\]\((?P<img_url>[^\)]+)\)\]\((?P<link_url>[^\)]+)\)";
|
||||||
|
|
||||||
pub const ESCAPES: &[&str] = &["\\!", "\\[", "\\]", "\\(", "\\)"];
|
|
||||||
|
|
||||||
struct Reference {
|
struct Reference {
|
||||||
uri: Uri,
|
uri: Uri,
|
||||||
alt: String,
|
alt: String,
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ use regex::Regex;
|
||||||
|
|
||||||
const REGEX_STRIKE: &str = r"~~(?P<text>.+?)~~";
|
const REGEX_STRIKE: &str = r"~~(?P<text>.+?)~~";
|
||||||
|
|
||||||
pub const ESCAPES: &[&str] = &["\\~"];
|
|
||||||
|
|
||||||
pub struct Strike(TextTag);
|
pub struct Strike(TextTag);
|
||||||
|
|
||||||
impl Strike {
|
impl Strike {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ use regex::Regex;
|
||||||
|
|
||||||
const REGEX_UNDERLINE: &str = r"\b_(?P<text>[^_]+)_\b";
|
const REGEX_UNDERLINE: &str = r"\b_(?P<text>[^_]+)_\b";
|
||||||
|
|
||||||
pub const ESCAPES: &[&str] = &["\\_"];
|
|
||||||
|
|
||||||
pub struct Underline(TextTag);
|
pub struct Underline(TextTag);
|
||||||
|
|
||||||
impl Underline {
|
impl Underline {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue