diff options
author | Sebastian Wiesner <sebastian@swsnr.de> | 2019-03-26 21:16:13 +0100 |
---|---|---|
committer | Sebastian Wiesner <sebastian@swsnr.de> | 2019-03-26 21:16:13 +0100 |
commit | 53fb49e2d3a08edd524b581f278f63456ec1bd55 (patch) | |
tree | 5047bba5fc6fe759d93596bc3ea1fb325cd62a00 | |
parent | 3b6d819e98003f51ea5332363f397e1f90f849a7 (diff) | |
parent | 8384aa2cf985268a972bf062572ddc258ccb1670 (diff) |
Merge branch 'update-pulldown-cmark'
* update-pulldown-cmark:
Update test data
Handle HTML block start and end
Cover new events and tags
Fix compiler errors from CowStr
Update to pulldown cmark 0.4
Bump pulldown-cmark from 0.2.0 to 0.3.0
-rw-r--r-- | Cargo.lock | 14 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/lib.rs | 41 | ||||
-rw-r--r-- | tests/formatting/code_blocks.expected.html | 4 |
4 files changed, 36 insertions, 25 deletions
@@ -497,7 +497,7 @@ dependencies = [ "immeta 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "pulldown-cmark 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pulldown-cmark 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "syntect 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -505,6 +505,11 @@ dependencies = [ ] [[package]] +name = "memchr" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "memoffset" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -796,10 +801,12 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.2.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1513,6 +1520,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "3e27ca21f40a310bd06d9031785f4801710d566c184a6e15bad4f1d9b65f9425" "checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed" @@ -1544,7 +1552,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum plist 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f4739851c08dd9a62a78beff2edf1a438517268b2c563c42fc6d9d3139e42d2a" "checksum pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427" "checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09" -"checksum pulldown-cmark 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eef52fac62d0ea7b9b4dc7da092aa64ea7ec3d90af6679422d3d7e0e14b6ee15" +"checksum pulldown-cmark 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa4987312f985c300f4d68d208a9e4b646268140b6dbe83388c09652cc19ed3f" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c" "checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" @@ -55,7 +55,7 @@ default-features = false features = ["color", "wrap_help"] [dependencies.pulldown-cmark] -version = "^0.2" +version = "^0.4" default-features = false features = [] @@ -23,8 +23,7 @@ use ansi_term::{Colour, Style}; use failure::Error; use pulldown_cmark::Event::*; use pulldown_cmark::Tag::*; -use pulldown_cmark::{Event, Tag}; -use std::borrow::Cow; +use pulldown_cmark::{CowStr, Event, Tag}; use std::collections::VecDeque; use std::io; use std::io::Write; @@ -114,9 +113,9 @@ struct Link<'a> { /// The index of the link. index: usize, /// The link destination. - destination: Cow<'a, str>, + destination: CowStr<'a>, /// The link title. - title: Cow<'a, str>, + title: CowStr<'a>, } /// Input context. @@ -189,7 +188,7 @@ struct LinkContext<'a> { /// We use this field to track the content of link tags, and omit a link /// reference if the link text equals the link destination, ie, if the link /// appears in text literally. - last_text: Option<Cow<'a, str>>, + last_text: Option<CowStr<'a>>, /// Whether we are inside an inline link currently. inside_inline_link: bool, } @@ -401,7 +400,7 @@ impl<'io, 'c, 'l, W: Write> Context<'io, 'c, 'l, W> { /// Add a link to the context. /// /// Return the index of the link. - fn add_link(&mut self, destination: Cow<'l, str>, title: Cow<'l, str>) -> usize { + fn add_link(&mut self, destination: CowStr<'l>, title: CowStr<'l>) -> usize { let index = self.links.next_link_index; self.links.next_link_index += 1; self.links.pending_links.push_back(Link { @@ -440,7 +439,7 @@ impl<'io, 'c, 'l, W: Write> Context<'io, 'c, 'l, W> { /// /// If the code context has a highlighter, use it to highlight `text` and /// write it. Otherwise write `text` without highlighting. - fn write_highlighted(&mut self, text: Cow<'l, str>) -> io::Result<()> { + fn write_highlighted(&mut self, text: CowStr<'l>) -> io::Result<()> { let mut wrote_highlighted: bool = false; if let Some(ref mut highlighter) = self.code.current_highlighter { if let StyleCapability::Ansi(ref ansi) = self.output.capabilities.style { @@ -486,10 +485,10 @@ fn write_event<'io, 'c, 'l, W: Write>( } Ok(ctx) } + TaskListMarker(_) => panic!("mdcat does not support task lists"), Start(tag) => start_tag(ctx, tag), End(tag) => end_tag(ctx, tag), Html(content) => { - ctx.newline()?; let html_style = ctx.style.current.fg(Colour::Green); for line in content.lines() { ctx.write_styled(&html_style, line)?; @@ -512,6 +511,7 @@ fn start_tag<'io, 'c, 'l, W: Write>( tag: Tag<'l>, ) -> Result<Context<'io, 'c, 'l, W>, Error> { match tag { + HtmlBlock => ctx.newline()?, Paragraph => ctx.start_inline_text()?, Rule => { ctx.start_inline_text()?; @@ -585,6 +585,7 @@ fn start_tag<'io, 'c, 'l, W: Write>( } FootnoteDefinition(_) => panic!("mdcat does not support footnotes"), Table(_) | TableHead | TableRow | TableCell => panic!("mdcat does not support tables"), + Strikethrough => panic!("mdcat does not support strikethrough"), Emphasis => ctx.enable_emphasis(), Strong => { let style = ctx.style.current.bold(); @@ -594,13 +595,14 @@ fn start_tag<'io, 'c, 'l, W: Write>( let style = ctx.style.current.fg(Colour::Yellow); ctx.set_style(style) } - Link(destination, _) => { - // Do nothing if the terminal doesn’t support inline links of if - // `destination` is no valid URL: We will write a reference link - // when closing the link tag. + Link(_, destination, _) => { + // Do nothing if the terminal doesn’t support inline links of if `destination` is no + // valid URL: We will write a reference link when closing the link tag. match ctx.output.capabilities.links { #[cfg(feature = "osc8_links")] LinkCapability::OSC8(ref osc8) => { + // TODO: check link type (first tuple element) to write proper mailto link for + // emails if let Some(url) = ctx.resources.resolve_reference(&destination) { osc8.set_link_url(ctx.output.writer, url)?; ctx.links.inside_inline_link = true; @@ -612,7 +614,7 @@ fn start_tag<'io, 'c, 'l, W: Write>( } } } - Image(link, _title) => match ctx.output.capabilities.image { + Image(_, link, _title) => match ctx.output.capabilities.image { #[cfg(feature = "terminology")] ImageCapability::Terminology(ref terminology) => { let access = ctx.resources.resource_access; @@ -658,6 +660,7 @@ fn end_tag<'io, 'c, 'l, W: Write>( tag: Tag<'l>, ) -> Result<Context<'io, 'c, 'l, W>, Error> { match tag { + HtmlBlock => {} Paragraph => ctx.end_inline_text_with_margin()?, Rule => ctx.end_inline_text_with_margin()?, Header(_) => { @@ -702,12 +705,13 @@ fn end_tag<'io, 'c, 'l, W: Write>( ctx.end_inline_text_with_margin()? } FootnoteDefinition(_) | Table(_) | TableHead | TableRow | TableCell => {} + Strikethrough => panic!("mdcat does not support strikethrough"), Emphasis => { ctx.drop_style(); ctx.style.emphasis_level -= 1; } Strong | Code => ctx.drop_style(), - Link(destination, title) => { + Link(_, destination, title) => { if ctx.links.inside_inline_link { match ctx.output.capabilities.links { #[cfg(feature = "osc8_links")] @@ -723,10 +727,9 @@ fn end_tag<'io, 'c, 'l, W: Write>( // can still happen for anything that's not a valid URL. match ctx.links.last_text { Some(ref text) if *text == destination => { - // Do nothing if the last printed text matches the - // destination of the link. In this we likely looked at an - // inline autolink and we should not repeat the link when - // it's already in text. + // Do nothing if the last printed text matches the destination of the link. + // In this case we likely looked at an inline autolink and we should not + // repeat the link when it's already in text. } _ => { // Reference link @@ -737,7 +740,7 @@ fn end_tag<'io, 'c, 'l, W: Write>( } } } - Image(link, _) => { + Image(_, link, _) => { if !ctx.image.inline_image { // If we could not write an inline image, write the image link // after the image title. diff --git a/tests/formatting/code_blocks.expected.html b/tests/formatting/code_blocks.expected.html index 813c946..6ce0a37 100644 --- a/tests/formatting/code_blocks.expected.html +++ b/tests/formatting/code_blocks.expected.html @@ -22,8 +22,8 @@ <span id="line-1"></span> <span id="line-2"><span class="ansi32">────────────────────</span></span> <span id="line-3"><span class="ansi33">Some plain</span> -<span id="line-4"></span><span class="ansi33">code block</span> -<span id="line-5"></span><span class="ansi33"> </span><span class="ansi33">fooo</span> +<span id="line-4">code block</span> +<span id="line-5"> fooo</span> <span id="line-6"></span><span class="ansi32">────────────────────</span></span> <span id="line-7"></span> <span id="line-8">Or with syntax highlighting, eg, Rust:</span> |