Fix bug with style

This commit is contained in:
ef3d0c3e 2024-11-03 10:10:36 +01:00
parent 6266e7373b
commit d4d8acfb97
5 changed files with 39 additions and 11 deletions

View file

@ -379,7 +379,12 @@ 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(), false) util::escape_text('\\', "```", matches.get(4).unwrap().as_str(), false)
} else { } else {
util::escape_text('\\', "``", matches.get(3).unwrap().as_str(), !matches.get(3).unwrap().as_str().contains('\n')) util::escape_text(
'\\',
"``",
matches.get(3).unwrap().as_str(),
!matches.get(3).unwrap().as_str().contains('\n'),
)
}; };
if code_content.bytes().last() == Some(b'\n') if code_content.bytes().last() == Some(b'\n')
// Remove newline // Remove newline

View file

@ -116,9 +116,16 @@ impl RuleState for CustomStyleState {
let mut reports = vec![]; let mut reports = vec![];
self.toggled.iter().for_each(|(style, token)| { self.toggled.iter().for_each(|(style, token)| {
let paragraph = document.last_element::<Paragraph>().unwrap(); let container = std::cell::Ref::filter_map(document.content().borrow(), |content| {
let paragraph_end = paragraph content.last().and_then(|last| last.as_container())
.content })
.ok();
if container.is_none() {
return;
}
let paragraph_end = container
.unwrap()
.contained()
.last() .last()
.map(|last| { .map(|last| {
( (

View file

@ -1,7 +1,6 @@
use crate::compiler::compiler::Compiler; use crate::compiler::compiler::Compiler;
use crate::compiler::compiler::Target; use crate::compiler::compiler::Target;
use crate::document::document::Document; use crate::document::document::Document;
use crate::document::document::DocumentAccessors;
use crate::document::element::ElemKind; use crate::document::element::ElemKind;
use crate::document::element::Element; use crate::document::element::Element;
use crate::lsp::semantic::Semantics; use crate::lsp::semantic::Semantics;
@ -22,8 +21,6 @@ use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use super::paragraph::Paragraph;
#[derive(Debug)] #[derive(Debug)]
pub struct Style { pub struct Style {
location: Token, location: Token,
@ -96,9 +93,17 @@ impl RuleState for StyleState {
} // Style not enabled } // Style not enabled
let token = token.as_ref().unwrap(); let token = token.as_ref().unwrap();
let paragraph = document.last_element::<Paragraph>().unwrap(); let container =
let paragraph_end = paragraph std::cell::Ref::filter_map(document.content().borrow(), |content| {
.content content.last().and_then(|last| last.as_container())
})
.ok();
if container.is_none() {
return;
}
let paragraph_end = container
.unwrap()
.contained()
.last() .last()
.map(|last| { .map(|last| {
( (
@ -277,6 +282,8 @@ impl RegexRule for StyleRule {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use elements::paragraph::Paragraph;
use crate::elements::text::Text; use crate::elements::text::Text;
use crate::parser::langparser::LangParser; use crate::parser::langparser::LangParser;
use crate::parser::parser::Parser; use crate::parser::parser::Parser;

View file

@ -216,6 +216,12 @@ impl<'b> Parser for LangParser<'b> {
doc.source(), doc.source(),
))), ))),
); );
} else {
self.handle_reports(state.shared.rule_state.borrow_mut().on_scope_end(
&state,
&doc,
super::state::Scope::PARAGRAPH,
));
} }
if path.is_some() { if path.is_some() {

View file

@ -329,6 +329,9 @@ mod tests {
"Unescaped \\\\\\\\]".to_string() "Unescaped \\\\\\\\]".to_string()
); );
assert_eq!(escape_text('\\', ")", "A\\)B\\", true), "A)B".to_string(),); assert_eq!(escape_text('\\', ")", "A\\)B\\", true), "A)B".to_string(),);
assert_eq!(escape_text('\\', ")", "A\\)B\\\\", false), "A)B\\".to_string(),); assert_eq!(
escape_text('\\', ")", "A\\)B\\\\", false),
"A)B\\".to_string(),
);
} }
} }