Fix bug with style
This commit is contained in:
parent
6266e7373b
commit
d4d8acfb97
5 changed files with 39 additions and 11 deletions
|
@ -379,7 +379,12 @@ impl RegexRule for CodeRule {
|
|||
let mut code_content = if index == 0 {
|
||||
util::escape_text('\\', "```", matches.get(4).unwrap().as_str(), false)
|
||||
} 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')
|
||||
// Remove newline
|
||||
|
|
|
@ -116,9 +116,16 @@ impl RuleState for CustomStyleState {
|
|||
let mut reports = vec![];
|
||||
|
||||
self.toggled.iter().for_each(|(style, token)| {
|
||||
let paragraph = document.last_element::<Paragraph>().unwrap();
|
||||
let paragraph_end = paragraph
|
||||
.content
|
||||
let container = std::cell::Ref::filter_map(document.content().borrow(), |content| {
|
||||
content.last().and_then(|last| last.as_container())
|
||||
})
|
||||
.ok();
|
||||
if container.is_none() {
|
||||
return;
|
||||
}
|
||||
let paragraph_end = container
|
||||
.unwrap()
|
||||
.contained()
|
||||
.last()
|
||||
.map(|last| {
|
||||
(
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::compiler::compiler::Compiler;
|
||||
use crate::compiler::compiler::Target;
|
||||
use crate::document::document::Document;
|
||||
use crate::document::document::DocumentAccessors;
|
||||
use crate::document::element::ElemKind;
|
||||
use crate::document::element::Element;
|
||||
use crate::lsp::semantic::Semantics;
|
||||
|
@ -22,8 +21,6 @@ use std::cell::RefCell;
|
|||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::paragraph::Paragraph;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Style {
|
||||
location: Token,
|
||||
|
@ -96,9 +93,17 @@ impl RuleState for StyleState {
|
|||
} // Style not enabled
|
||||
let token = token.as_ref().unwrap();
|
||||
|
||||
let paragraph = document.last_element::<Paragraph>().unwrap();
|
||||
let paragraph_end = paragraph
|
||||
.content
|
||||
let container =
|
||||
std::cell::Ref::filter_map(document.content().borrow(), |content| {
|
||||
content.last().and_then(|last| last.as_container())
|
||||
})
|
||||
.ok();
|
||||
if container.is_none() {
|
||||
return;
|
||||
}
|
||||
let paragraph_end = container
|
||||
.unwrap()
|
||||
.contained()
|
||||
.last()
|
||||
.map(|last| {
|
||||
(
|
||||
|
@ -277,6 +282,8 @@ impl RegexRule for StyleRule {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use elements::paragraph::Paragraph;
|
||||
|
||||
use crate::elements::text::Text;
|
||||
use crate::parser::langparser::LangParser;
|
||||
use crate::parser::parser::Parser;
|
||||
|
|
|
@ -216,6 +216,12 @@ impl<'b> Parser for LangParser<'b> {
|
|||
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() {
|
||||
|
|
|
@ -329,6 +329,9 @@ mod tests {
|
|||
"Unescaped \\\\\\\\]".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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue