diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-29 10:26:39 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-29 10:26:39 +0200 |
commit | 7721f210c16e19b1c2af90f69130386b89bb5104 (patch) | |
tree | c47ff3d9c974ccd0c81a2c5b8ccbce9f7635975d /src/compiler.rs | |
parent | 7bb1008f508f61b51dd80086a91ada347be36c68 (diff) | |
download | markdown-rs-7721f210c16e19b1c2af90f69130386b89bb5104.tar.gz markdown-rs-7721f210c16e19b1c2af90f69130386b89bb5104.tar.bz2 markdown-rs-7721f210c16e19b1c2af90f69130386b89bb5104.zip |
Add support for sharing identifiers, references before definitions
Diffstat (limited to '')
-rw-r--r-- | src/compiler.rs | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index bb7aedc..6f4d1a6 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -91,6 +91,14 @@ struct Media { title: Option<String>, } +/// To do. +#[derive(Debug, Clone, PartialEq)] +struct DefinitionInfo { + id: Option<String>, + destination: Option<String>, + title: Option<String>, +} + /// Configuration (optional). #[derive(Default, Debug)] pub struct Options { @@ -226,17 +234,39 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String { let mut media_stack: Vec<Media> = vec![]; // let mut slurp_all_line_endings = false; + let mut definition: Option<DefinitionInfo> = None; + + // To do: actually do a compile pass, so that `buffer`, `resume`, etc can be used. while index < events.len() { let event = &events[index]; - if event.event_type == EventType::Exit + // Find the used line ending style. + if line_ending_inferred.is_none() + && event.event_type == EventType::Exit && (event.token_type == TokenType::BlankLineEnding || event.token_type == TokenType::CodeTextLineEnding || event.token_type == TokenType::LineEnding) { let codes = codes_from_span(codes, &from_exit_event(events, index)); line_ending_inferred = Some(LineEnding::from_code(*codes.first().unwrap())); - break; + } + + if event.event_type == EventType::Enter { + if event.token_type == TokenType::Definition { + definition = Some(DefinitionInfo { + id: None, + destination: None, + title: None, + }); + } + } else if event.token_type == TokenType::Definition { + definition = None; + } else if event.token_type == TokenType::DefinitionLabelString + || event.token_type == TokenType::DefinitionDestinationString + || event.token_type == TokenType::DefinitionTitleString + { + let slice = serialize(codes, &from_exit_event(events, index), false); + println!("set: {:?} {:?}", slice, definition); } index += 1; @@ -250,7 +280,7 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String { LineEnding::LineFeed }; - index = 0; + let mut index = 0; while index < events.len() { let event = &events[index]; @@ -483,7 +513,7 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String { let label = media.label.unwrap(); let buf = buf_tail_mut(buffers); // To do: get from definition. - let destination = media.destination.unwrap(); + let destination = media.destination.unwrap_or_else(|| "".to_string()); let title = if let Some(title) = media.title { format!(" title=\"{}\"", title) } else { |