diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler.rs | 18 | ||||
-rw-r--r-- | src/construct/code_text.rs | 6 | ||||
-rw-r--r-- | src/token.rs | 24 |
3 files changed, 13 insertions, 35 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 07f0d6b..67717e5 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -235,6 +235,7 @@ struct CompileContext<'a> { pub heading_setext_buffer: Option<String>, pub code_flow_seen_data: Option<bool>, pub code_fenced_fences_count: Option<usize>, + pub code_text_inside: bool, pub character_reference_kind: Option<CharacterReferenceKind>, pub expect_first_item: Option<bool>, pub media_stack: Vec<Media>, @@ -270,6 +271,7 @@ impl<'a> CompileContext<'a> { heading_setext_buffer: None, code_flow_seen_data: None, code_fenced_fences_count: None, + code_text_inside: false, character_reference_kind: None, expect_first_item: None, media_stack: vec![], @@ -391,9 +393,7 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String { let event = &events[index]; if event.event_type == EventType::Exit - && (event.token_type == Token::BlankLineEnding - || event.token_type == Token::CodeTextLineEnding - || event.token_type == Token::LineEnding) + && (event.token_type == Token::BlankLineEnding || event.token_type == Token::LineEnding) { let codes = codes_from_span(codes, &from_exit_event(events, index)); line_ending_inferred = Some(LineEnding::from_code(*codes.first().unwrap())); @@ -478,7 +478,6 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String { exit_map.insert(Token::CodeIndented, on_exit_code_flow); exit_map.insert(Token::CodeText, on_exit_code_text); exit_map.insert(Token::CodeTextData, on_exit_data); - exit_map.insert(Token::CodeTextLineEnding, on_exit_code_text_line_ending); exit_map.insert(Token::Data, on_exit_data); exit_map.insert(Token::Definition, on_exit_definition); exit_map.insert( @@ -638,6 +637,7 @@ fn on_enter_code_fenced(context: &mut CompileContext) { /// Handle [`Enter`][EventType::Enter]:[`CodeText`][Token::CodeText]. fn on_enter_code_text(context: &mut CompileContext) { + context.code_text_inside = true; context.tag("<code>".to_string()); context.buffer(); } @@ -992,6 +992,7 @@ fn on_exit_code_text(context: &mut CompileContext) { } } + context.code_text_inside = false; context.push(if trim { result[1..(result.len() - 1)].to_string() } else { @@ -1000,11 +1001,6 @@ fn on_exit_code_text(context: &mut CompileContext) { context.tag("</code>".to_string()); } -/// Handle [`Exit`][EventType::Exit]:[`CodeTextLineEnding`][Token::CodeTextLineEnding]. -fn on_exit_code_text_line_ending(context: &mut CompileContext) { - context.push(" ".to_string()); -} - /// Handle [`Exit`][EventType::Exit]:*. /// /// Resumes, and ignores what was resumed. @@ -1160,7 +1156,9 @@ fn on_exit_label_text(context: &mut CompileContext) { /// Handle [`Exit`][EventType::Exit]:[`LineEnding`][Token::LineEnding]. fn on_exit_line_ending(context: &mut CompileContext) { - if context.slurp_one_line_ending { + if context.code_text_inside { + context.push(" ".to_string()); + } else if context.slurp_one_line_ending { context.slurp_one_line_ending = false; } else { context.push(context.encode_opt(&serialize( diff --git a/src/construct/code_text.rs b/src/construct/code_text.rs index 6df61b8..039f4b2 100644 --- a/src/construct/code_text.rs +++ b/src/construct/code_text.rs @@ -69,8 +69,8 @@ //! //! * [`CodeText`][Token::CodeText] //! * [`CodeTextData`][Token::CodeTextData] -//! * [`CodeTextLineEnding`][Token::CodeTextLineEnding] //! * [`CodeTextSequence`][Token::CodeTextSequence] +//! * [`LineEnding`][Token::LineEnding] //! //! ## References //! @@ -139,9 +139,9 @@ fn between(tokenizer: &mut Tokenizer, code: Code, size_open: usize) -> StateFnRe match code { Code::None => (State::Nok, None), Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => { - tokenizer.enter(Token::CodeTextLineEnding); + tokenizer.enter(Token::LineEnding); tokenizer.consume(code); - tokenizer.exit(Token::CodeTextLineEnding); + tokenizer.exit(Token::LineEnding); ( State::Fn(Box::new(move |t, c| between(t, c, size_open))), None, diff --git a/src/token.rs b/src/token.rs index 2e5e2df..fd7999d 100644 --- a/src/token.rs +++ b/src/token.rs @@ -492,7 +492,7 @@ pub enum Token { /// * **Content model**: /// [`CodeTextData`][Token::CodeTextData], /// [`CodeTextSequence`][Token::CodeTextSequence], - /// [`CodeTextLineEnding`][Token::CodeTextLineEnding] + /// [`LineEnding`][Token::LineEnding] /// * **Construct**: /// [`code_text`][crate::construct::code_text] /// @@ -521,25 +521,6 @@ pub enum Token { /// ^ /// ``` CodeTextData, - /// Line ending in code (text). - /// - /// ## Info - /// - /// * **Context**: - /// [`CodeText`][Token::CodeText], - /// * **Content model**: - /// void - /// * **Construct**: - /// [`code_text`][crate::construct::code_text] - /// - /// ## Example - /// - /// ```markdown - /// > | a `b␊ - /// ^ - /// | c` d - /// ``` - CodeTextLineEnding, /// Code (text) sequence. /// /// ## Info @@ -1879,7 +1860,7 @@ pub enum Token { } /// List of void tokens, used to make sure everything is working good. -pub const VOID_TOKENS: [Token; 40] = [ +pub const VOID_TOKENS: [Token; 39] = [ Token::AttentionSequence, Token::AutolinkEmail, Token::AutolinkMarker, @@ -1896,7 +1877,6 @@ pub const VOID_TOKENS: [Token; 40] = [ Token::CodeFencedFenceSequence, Token::CodeFlowChunk, Token::CodeTextData, - Token::CodeTextLineEnding, Token::CodeTextSequence, Token::Data, Token::DefinitionDestinationLiteralMarker, |