QoL Fixes

This commit is contained in:
ef3d0c3e 2024-11-02 09:29:37 +01:00
parent 357c8a18bd
commit 6010024934
7 changed files with 25 additions and 21 deletions

View file

@ -377,9 +377,9 @@ impl RegexRule for CodeRule {
};
let mut code_content = if index == 0 {
util::escape_text('\\', "```", matches.get(4).unwrap().as_str())
util::escape_text('\\', "```", matches.get(4).unwrap().as_str(), false)
} else {
util::escape_text('\\', "``", matches.get(3).unwrap().as_str())
util::escape_text('\\', "``", matches.get(3).unwrap().as_str(), false)
};
if code_content.bytes().last() == Some(b'\n')
// Remove newline

View file

@ -222,7 +222,7 @@ impl RegexRule for GraphRule {
return reports;
}
Some(content) => {
let processed = util::escape_text('\\', "[/graph]", content.as_str());
let processed = util::escape_text('\\', "[/graph]", content.as_str(), true);
if processed.is_empty() {
report_err!(

View file

@ -329,7 +329,7 @@ impl RegexRule for MediaRule {
matches.get(2).unwrap(),
MediaRule::validate_uri(matches.get(2).unwrap().as_str()),
) {
(_, Ok(uri)) => util::escape_text('\\', ")", uri),
(_, Ok(uri)) => util::escape_text('\\', ")", uri, true),
(m, Err(err)) => {
report_err!(
&mut reports,

View file

@ -112,7 +112,7 @@ impl RegexRule for RawRule {
}
Some(content) => {
let processed =
util::escape_text('\\', "?}", content.as_str().trim_start().trim_end());
util::escape_text('\\', "?}", content.as_str().trim_start().trim_end(), true);
if processed.is_empty() {
report_warn!(

View file

@ -296,6 +296,7 @@ impl RegexRule for TexRule {
'\\',
["|$", "$"][index],
content.as_str().trim_start().trim_end(),
true,
);
if processed.is_empty() {

View file

@ -201,14 +201,14 @@ impl<'b> Parser for LangParser<'b> {
// Process the end of the semantics queue
Semantics::on_document_end(&state.shared.lsp, source.clone());
// Rule States
self.handle_reports(state.shared.rule_state.borrow_mut().on_scope_end(
&state,
&doc,
super::state::Scope::DOCUMENT,
));
if parent.is_none() {
// Rule States
self.handle_reports(state.shared.rule_state.borrow_mut().on_scope_end(
&state,
&doc,
super::state::Scope::DOCUMENT,
));
state.push(
&doc,
Box::new(DocumentEnd(Token::new(

View file

@ -159,18 +159,21 @@ pub fn escape_source(
///
/// If you need to create a source, do not use this function, use [`escape_source`] instead
/// as it will populate an offsets to get accurate diagnostics and semantics.
pub fn escape_text<S: AsRef<str>>(escape: char, token: &'static str, content: S) -> String {
pub fn escape_text<S: AsRef<str>>(
escape: char,
token: &'static str,
content: S,
trim: bool,
) -> String {
let mut processed = String::new();
let mut escaped = 0;
let mut token_it = token.chars().peekable();
for c in content
.as_ref()
.chars()
.as_str()
.trim_start()
.trim_end()
.chars()
{
let data = if trim {
content.as_ref().chars().as_str().trim_start().trim_end()
} else {
content.as_ref().chars().as_str()
};
for c in data.chars() {
if c == escape {
escaped += 1;
} else if escaped % 2 == 1 && token_it.peek().map_or(false, |p| *p == c) {