From 079f6890a130894e63817a13f64af96e8c233669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20L=C3=B8vhaug?= Date: Sun, 15 Sep 2024 21:45:11 +0200 Subject: [PATCH 1/3] Make a link Regression on comment parsing --- src/md.pest | 35 +++++++++++++++++++---------------- src/nodes/word.rs | 2 +- src/parser.rs | 15 +++++++++------ 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/md.pest b/src/md.pest index 4f7a9bc..3f634a4 100644 --- a/src/md.pest +++ b/src/md.pest @@ -1,20 +1,21 @@ WHITESPACE_S = _{ " " | "\t" } // Characters -alt_char = _{ (!(NEWLINE | WHITESPACE_S | "[" | "]") ~ ANY)+ } -b_char = _{ (!(NEWLINE | comment | WHITESPACE_S | "**") ~ ANY)+ } -c_char = _{ (!(NEWLINE | WHITESPACE_S | "`") ~ ANY)+ } -c_line_char = _{ (!(NEWLINE | "```" | "~~~") ~ ANY)+ } -comment_char = _{ (!(NEWLINE | "-->") ~ ANY)+ } -digit = _{ '0'..'9' } -i_char = _{ (!(NEWLINE | comment | WHITESPACE_S | "_" | "*") ~ ANY)+ } -indent = { WHITESPACE_S* } -latex_char = _{ (!(NEWLINE | WHITESPACE_S | "$") ~ ANY)+ } -link_char = _{ (!(NEWLINE | WHITESPACE_S | "[" | "]" | "(" | ")") ~ ANY)+ } -p_char = _{ (!(NEWLINE | comment | code | bold_italic | italic | bold | strikethrough | latex | WHITESPACE_S) ~ ANY)+ } -s_char = _{ (!(NEWLINE | comment | WHITESPACE_S | "~~") ~ ANY)+ } -t_char = _{ (!(NEWLINE | comment | code | bold_italic | italic | bold | strikethrough | latex | WHITESPACE_S | "|") ~ ANY)+ } -wiki_link_char = _{ (!(NEWLINE | WHITESPACE_S | "|" | "[[" | "]]") ~ ANY)+ } +alt_char = _{ (!(NEWLINE | WHITESPACE_S | "[" | "]") ~ ANY)+ } +b_char = _{ (!(NEWLINE | comment | WHITESPACE_S | "**") ~ ANY)+ } +c_char = _{ (!(NEWLINE | WHITESPACE_S | "`") ~ ANY)+ } +c_line_char = _{ (!(NEWLINE | "```" | "~~~") ~ ANY)+ } +comment_char = _{ (!(NEWLINE | "-->") ~ ANY)+ } +digit = _{ '0'..'9' } +i_char = _{ (!(NEWLINE | comment | WHITESPACE_S | "_" | "*") ~ ANY)+ } +indent = { WHITESPACE_S* } +latex_char = _{ (!(NEWLINE | WHITESPACE_S | "$") ~ ANY)+ } +link_char = _{ (!(NEWLINE | WHITESPACE_S | "[" | "]" | "(" | ")") ~ ANY)+ } +p_char = _{ (!(NEWLINE | comment | code | bold_italic | italic | bold | strikethrough | latex | WHITESPACE_S | link) ~ ANY)+ } +s_char = _{ (!(NEWLINE | comment | WHITESPACE_S | "~~") ~ ANY)+ } +t_char = _{ (!(NEWLINE | comment | code | bold_italic | italic | bold | strikethrough | latex | WHITESPACE_S | "|") ~ ANY)+ } +wiki_link_char = _{ (!(NEWLINE | WHITESPACE_S | "|" | "[[" | "]]") ~ ANY)+ } +inline_link_char = _{ (!(NEWLINE | WHITESPACE_S | "<" | ">") ~ ANY)+ } // Words word = { @@ -36,6 +37,7 @@ strikethrough_word = { WHITESPACE_S* ~ s_char+ } wiki_link_alone = { wiki_link_char+ } wiki_link_data = { wiki_link_char+ } wiki_link_word = { (link_char | WHITESPACE_S)+ } +inline_link = { inline_link_char+ } // Prefixes task_open = { "- [ ] " } @@ -62,14 +64,15 @@ bold_italic = { code = { NEWLINE? ~ WHITESPACE_S* ~ ("`" ~ code_word+ ~ "`") | ("```" ~ code_word+ ~ "```") } code_line = { NEWLINE ~ (c_line_char | WHITESPACE_S)* } latex = { NEWLINE? ~ WHITESPACE_S* ~ !"\\" ~ "$"+ ~ WHITESPACE_S? ~ (latex_word | (NEWLINE ~ quote_prefix?))+ ~ "$"+ } -link = { NEWLINE? ~ WHITESPACE_S* ~ (link_line | wiki_link) } +link = { NEWLINE? ~ WHITESPACE_S* ~ (link_line | wiki_link | inline_link_wrapper) } link_line = _{ "[" ~ (link_word | NEWLINE)+ ~ "]" ~ "(" ~ link_data+ ~ ")" } +inline_link_wrapper = _{ "<" ~ inline_link ~ ">" } +wiki_link = _{ ("[[" ~ wiki_link_alone+ ~ "]]") | ("[[" ~ wiki_link_data+ ~ "|" ~ wiki_link_word+ ~ "]]") } normal = _{ word+ } o_list_counter = { digit+ ~ ". " } programming_language = { (!NEWLINE ~ ANY)+ } strikethrough = { NEWLINE? ~ WHITESPACE_S* ~ !"\\" ~ "~~" ~ !"~" ~ (strikethrough_word | (NEWLINE ~ quote_prefix?))+ ~ "~~" } t_normal = _{ t_word+ } -wiki_link = _{ ("[[" ~ wiki_link_alone+ ~ "]]") | ("[[" ~ wiki_link_data+ ~ "|" ~ wiki_link_word+ ~ "]]") } italic = { (NEWLINE? ~ WHITESPACE_S* ~ !"\\" ~ "*" ~ (italic_word | (NEWLINE ~ quote_prefix?))+ ~ "*") diff --git a/src/nodes/word.rs b/src/nodes/word.rs index cf0c4b2..f3172d1 100644 --- a/src/nodes/word.rs +++ b/src/nodes/word.rs @@ -48,7 +48,7 @@ impl From for WordType { MdParseEnum::Bold => WordType::Bold, MdParseEnum::Italic => WordType::Italic, MdParseEnum::Strikethrough => WordType::Strikethrough, - MdParseEnum::Link | MdParseEnum::WikiLink => WordType::Link, + MdParseEnum::Link | MdParseEnum::WikiLink | MdParseEnum::InlineLink => WordType::Link, MdParseEnum::BoldItalic => WordType::BoldItalic, MdParseEnum::Digit => WordType::ListMarker, diff --git a/src/parser.rs b/src/parser.rs index 75706d5..864663c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -143,7 +143,7 @@ fn parse_component(parse_node: ParseNode) -> Component { .dedup_by(|x, y| *x == ' ' && *y == ' ') .collect(); - if node.kind() == MdParseEnum::WikiLink { + if matches!(node.kind(), MdParseEnum::WikiLink | MdParseEnum::InlineLink) { let comp = Word::new(content.clone(), WordType::LinkData); words.push(comp); } @@ -165,7 +165,7 @@ fn parse_component(parse_node: ParseNode) -> Component { let word_type = WordType::from(node.kind()); let mut content = node.content().to_owned(); - if node.kind() == MdParseEnum::WikiLink { + if matches!(node.kind(), MdParseEnum::WikiLink | MdParseEnum::InlineLink) { let comp = Word::new(content.clone(), WordType::LinkData); words.push(comp); } @@ -207,7 +207,7 @@ fn parse_component(parse_node: ParseNode) -> Component { let word_type = WordType::from(node.kind()); let mut content = node.content().to_owned(); - if node.kind() == MdParseEnum::WikiLink { + if matches!(node.kind(), MdParseEnum::WikiLink | MdParseEnum::InlineLink) { let comp = Word::new(content.clone(), WordType::LinkData); words.push(comp); } @@ -232,7 +232,7 @@ fn parse_component(parse_node: ParseNode) -> Component { let word_type = WordType::from(node.kind()); let mut content = node.content().to_owned(); - if node.kind() == MdParseEnum::WikiLink { + if matches!(node.kind(), MdParseEnum::WikiLink | MdParseEnum::InlineLink) { let comp = Word::new(content.clone(), WordType::LinkData); words.push(comp); } @@ -279,7 +279,7 @@ fn parse_component(parse_node: ParseNode) -> Component { .collect(), }; - if node.kind() == MdParseEnum::WikiLink { + if matches!(node.kind(), MdParseEnum::WikiLink | MdParseEnum::InlineLink) { let comp = Word::new(content.clone(), WordType::LinkData); inner_words.push(comp); } @@ -324,7 +324,7 @@ fn parse_component(parse_node: ParseNode) -> Component { let word_type = WordType::from(word.kind()); let mut content = word.content().to_owned(); - if word.kind() == MdParseEnum::WikiLink { + if matches!(word.kind(), MdParseEnum::WikiLink | MdParseEnum::InlineLink) { let comp = Word::new(content.clone(), WordType::LinkData); inner_words.push(comp); } @@ -491,6 +491,7 @@ pub enum MdParseEnum { Indent, Italic, ItalicStr, + InlineLink, Link, LinkData, ListContainer, @@ -534,6 +535,7 @@ impl From for MdParseEnum { Rule::programming_language => Self::PLanguage, Rule::link_word | Rule::link_line | Rule::link | Rule::wiki_link_word => Self::Link, Rule::wiki_link_alone => Self::WikiLink, + Rule::inline_link | Rule::inline_link_wrapper => Self::InlineLink, Rule::o_list_counter | Rule::digit => Self::Digit, Rule::task_open => Self::TaskOpen, Rule::task_complete => Self::TaskClosed, @@ -591,6 +593,7 @@ impl From for MdParseEnum { | Rule::i_char | Rule::latex_char | Rule::quote_marking + | Rule::inline_link_char | Rule::s_char | Rule::WHITESPACE_S | Rule::wiki_link => todo!(), From 085819fcbe4dfbb6466676de7ca73e0ae26c1183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20L=C3=B8vhaug?= Date: Sun, 15 Sep 2024 21:47:07 +0200 Subject: [PATCH 2/3] Fix comment parsing --- src/md.pest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/md.pest b/src/md.pest index 3f634a4..5ea9b3c 100644 --- a/src/md.pest +++ b/src/md.pest @@ -66,7 +66,7 @@ code_line = { NEWLINE ~ (c_line_char | WHITESPACE_S)* } latex = { NEWLINE? ~ WHITESPACE_S* ~ !"\\" ~ "$"+ ~ WHITESPACE_S? ~ (latex_word | (NEWLINE ~ quote_prefix?))+ ~ "$"+ } link = { NEWLINE? ~ WHITESPACE_S* ~ (link_line | wiki_link | inline_link_wrapper) } link_line = _{ "[" ~ (link_word | NEWLINE)+ ~ "]" ~ "(" ~ link_data+ ~ ")" } -inline_link_wrapper = _{ "<" ~ inline_link ~ ">" } +inline_link_wrapper = _{ !comment ~ "<" ~ inline_link ~ ">" } wiki_link = _{ ("[[" ~ wiki_link_alone+ ~ "]]") | ("[[" ~ wiki_link_data+ ~ "|" ~ wiki_link_word+ ~ "]]") } normal = _{ word+ } o_list_counter = { digit+ ~ ". " } From 4ec1e88b29ebed885ecf1767fda1c2f2d62608d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20T=C3=B8n=20L=C3=B8vhaug?= Date: Mon, 16 Sep 2024 11:01:21 +0200 Subject: [PATCH 3/3] Spelling error --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fca212b..889c60a 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ Some key actions are not configurable. Like the following: > not get reassigned. > Actions can only be assigned to single characters. Space, fn keys, ctrl+key, -> backspace etc., will not take affect and the default will be in use. +> backspace etc., will not take effect and the default will be in use. ```toml # Keyboard actions