From efdf90959f78d1582da312bffbefaabb79f264b7 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 13 Jun 2022 12:37:25 +0200 Subject: Add autolinks --- src/compiler.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/compiler.rs') diff --git a/src/compiler.rs b/src/compiler.rs index 48983b6..df26f1b 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -89,7 +89,11 @@ pub fn compile(events: &[Event], codes: &[Code], options: &CompileOptions) -> St | TokenType::CharacterReferenceMarkerNumeric | TokenType::CharacterReferenceMarkerHexadecimal | TokenType::CharacterReferenceMarkerSemi - | TokenType::CharacterReferenceValue => {} + | TokenType::CharacterReferenceValue + | TokenType::Autolink + | TokenType::AutolinkMarker + | TokenType::AutolinkProtocol + | TokenType::AutolinkEmail => {} #[allow(unreachable_patterns)] _ => { unreachable!("unhandled `enter` of TokenType {:?}", token_type) @@ -108,7 +112,9 @@ pub fn compile(events: &[Event], codes: &[Code], options: &CompileOptions) -> St | TokenType::CharacterEscape | TokenType::CharacterEscapeMarker | TokenType::CharacterReference - | TokenType::CharacterReferenceMarkerSemi => {} + | TokenType::CharacterReferenceMarkerSemi + | TokenType::Autolink + | TokenType::AutolinkMarker => {} TokenType::HtmlFlow => { ignore_encode = false; } @@ -229,6 +235,26 @@ pub fn compile(events: &[Event], codes: &[Code], options: &CompileOptions) -> St atx_opening_sequence_size = None; atx_heading_buffer = None; } + TokenType::AutolinkProtocol => { + let slice = slice_serialize(codes, &get_span(events, index), false); + let buf = buf_tail_mut(buffers); + // To do: options.allowDangerousProtocol ? undefined : protocolHref + // let url = sanitize_uri(slice); + let url = encode(&slice); + buf.push(format!("", url)); + buf.push(encode(&slice)); + buf.push("".to_string()); + } + TokenType::AutolinkEmail => { + let slice = slice_serialize(codes, &get_span(events, index), false); + let buf = buf_tail_mut(buffers); + // To do: options.allowDangerousProtocol ? undefined : protocolHref + // let url = sanitize_uri(slice); + let url = encode(&slice); + buf.push(format!("", url)); + buf.push(encode(&slice)); + buf.push("".to_string()); + } TokenType::ThematicBreak => { buf_tail_mut(buffers).push("
".to_string()); } -- cgit