QoL Fixes
This commit is contained in:
parent
357c8a18bd
commit
6010024934
7 changed files with 25 additions and 21 deletions
|
@ -377,9 +377,9 @@ impl RegexRule for CodeRule {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut code_content = if index == 0 {
|
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 {
|
} 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')
|
if code_content.bytes().last() == Some(b'\n')
|
||||||
// Remove newline
|
// Remove newline
|
||||||
|
|
|
@ -222,7 +222,7 @@ impl RegexRule for GraphRule {
|
||||||
return reports;
|
return reports;
|
||||||
}
|
}
|
||||||
Some(content) => {
|
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() {
|
if processed.is_empty() {
|
||||||
report_err!(
|
report_err!(
|
||||||
|
|
|
@ -329,7 +329,7 @@ impl RegexRule for MediaRule {
|
||||||
matches.get(2).unwrap(),
|
matches.get(2).unwrap(),
|
||||||
MediaRule::validate_uri(matches.get(2).unwrap().as_str()),
|
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)) => {
|
(m, Err(err)) => {
|
||||||
report_err!(
|
report_err!(
|
||||||
&mut reports,
|
&mut reports,
|
||||||
|
|
|
@ -112,7 +112,7 @@ impl RegexRule for RawRule {
|
||||||
}
|
}
|
||||||
Some(content) => {
|
Some(content) => {
|
||||||
let processed =
|
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() {
|
if processed.is_empty() {
|
||||||
report_warn!(
|
report_warn!(
|
||||||
|
|
|
@ -296,6 +296,7 @@ impl RegexRule for TexRule {
|
||||||
'\\',
|
'\\',
|
||||||
["|$", "$"][index],
|
["|$", "$"][index],
|
||||||
content.as_str().trim_start().trim_end(),
|
content.as_str().trim_start().trim_end(),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
if processed.is_empty() {
|
if processed.is_empty() {
|
||||||
|
|
|
@ -201,14 +201,14 @@ impl<'b> Parser for LangParser<'b> {
|
||||||
// Process the end of the semantics queue
|
// Process the end of the semantics queue
|
||||||
Semantics::on_document_end(&state.shared.lsp, source.clone());
|
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() {
|
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(
|
state.push(
|
||||||
&doc,
|
&doc,
|
||||||
Box::new(DocumentEnd(Token::new(
|
Box::new(DocumentEnd(Token::new(
|
||||||
|
|
|
@ -159,18 +159,21 @@ pub fn escape_source(
|
||||||
///
|
///
|
||||||
/// If you need to create a source, do not use this function, use [`escape_source`] instead
|
/// 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.
|
/// 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 processed = String::new();
|
||||||
let mut escaped = 0;
|
let mut escaped = 0;
|
||||||
let mut token_it = token.chars().peekable();
|
let mut token_it = token.chars().peekable();
|
||||||
for c in content
|
let data = if trim {
|
||||||
.as_ref()
|
content.as_ref().chars().as_str().trim_start().trim_end()
|
||||||
.chars()
|
} else {
|
||||||
.as_str()
|
content.as_ref().chars().as_str()
|
||||||
.trim_start()
|
};
|
||||||
.trim_end()
|
for c in data.chars() {
|
||||||
.chars()
|
|
||||||
{
|
|
||||||
if c == escape {
|
if c == escape {
|
||||||
escaped += 1;
|
escaped += 1;
|
||||||
} else if escaped % 2 == 1 && token_it.peek().map_or(false, |p| *p == c) {
|
} else if escaped % 2 == 1 && token_it.peek().map_or(false, |p| *p == c) {
|
||||||
|
|
Loading…
Reference in a new issue