diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-28 14:18:17 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-28 14:18:17 +0200 |
commit | dfd11b1bc155ae1fba9975a90c2dc83dc07697b4 (patch) | |
tree | 0dd150365a6ae1df4c4845518efafe02ab61cb77 /src/compiler.rs | |
parent | a3dd207e3b1ebcbcb6cec0f703a695e51ae4ece0 (diff) | |
download | markdown-rs-dfd11b1bc155ae1fba9975a90c2dc83dc07697b4.tar.gz markdown-rs-dfd11b1bc155ae1fba9975a90c2dc83dc07697b4.tar.bz2 markdown-rs-dfd11b1bc155ae1fba9975a90c2dc83dc07697b4.zip |
Fix jumps in `edit_map`
* Use resolve more often (e.g., heading (atx, setext))
* Fix to link whole phrasing (e.g., one big chunk of text in heading (atx,
setext), titles, labels)
* Replace `ChunkText`, `ChunkString`, with
`event.content_type: Option<ContentType>`
* Refactor to externalize `edit_map` from `label`
Diffstat (limited to 'src/compiler.rs')
-rw-r--r-- | src/compiler.rs | 37 |
1 files changed, 4 insertions, 33 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 11dea29..019a53a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -173,7 +173,6 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String { // let mut last_was_tag = false; let buffers: &mut Vec<Vec<String>> = &mut vec![vec![]]; let mut atx_opening_sequence_size: Option<usize> = None; - let mut atx_heading_buffer: Option<String> = None; let mut heading_setext_buffer: Option<String> = None; let mut code_flow_seen_data: Option<bool> = None; let mut code_fenced_fences_count: Option<usize> = None; @@ -265,7 +264,6 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String { | TokenType::HardBreakTrailingSpace | TokenType::HeadingAtx | TokenType::HeadingAtxSequence - | TokenType::HeadingAtxSpaceOrTab | TokenType::HeadingSetext | TokenType::HeadingSetextUnderline | TokenType::HtmlFlowData @@ -628,25 +626,8 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String { .expect("`atx_opening_sequence_size` must be set in headings"); buf_tail_mut(buffers).push(format!("</h{}>", rank)); atx_opening_sequence_size = None; - atx_heading_buffer = None; - } - // `HeadingAtxSpaceOrTab` is ignored after the opening sequence, - // before the closing sequence, and after the closing sequence. - // But it is used around intermediate sequences. - // `atx_heading_buffer` is set to `Some` by the first `HeadingAtxText`. - // `HeadingAtxSequence` is ignored as the opening and closing sequence, - // but not when intermediate. - TokenType::HeadingAtxSequence | TokenType::HeadingAtxSpaceOrTab => { - if let Some(buf) = atx_heading_buffer { - atx_heading_buffer = Some( - buf.to_string() - + &encode_opt( - &serialize(codes, &from_exit_event(events, index), false), - ignore_encode, - ), - ); - } - + } + TokenType::HeadingAtxSequence => { // First fence we see. if None == atx_opening_sequence_size { let rank = serialize(codes, &from_exit_event(events, index), false).len(); @@ -655,18 +636,8 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String { } } TokenType::HeadingAtxText => { - let result = resume(buffers); - - if let Some(ref buf) = atx_heading_buffer { - if !buf.is_empty() { - buf_tail_mut(buffers).push(encode_opt(buf, ignore_encode)); - atx_heading_buffer = Some("".to_string()); - } - } else { - atx_heading_buffer = Some("".to_string()); - } - - buf_tail_mut(buffers).push(encode_opt(&result, ignore_encode)); + let value = resume(buffers); + buf_tail_mut(buffers).push(value); } TokenType::HeadingSetextText => { heading_setext_buffer = Some(resume(buffers)); |