11use crate :: errors:: * ;
22use log:: { debug, trace, warn} ;
3- use memchr:: { self , Memchr } ;
4- use pulldown_cmark:: { self , Event , HeadingLevel , Tag } ;
3+ use memchr:: Memchr ;
4+ use pulldown_cmark:: { DefaultBrokenLinkCallback , Event , HeadingLevel , Tag , TagEnd } ;
55use serde:: { Deserialize , Serialize } ;
66use std:: fmt:: { self , Display , Formatter } ;
77use std:: iter:: FromIterator ;
@@ -163,7 +163,7 @@ impl From<Link> for SummaryItem {
163163/// > match the following regex: "[^<>\n[]]+".
164164struct SummaryParser < ' a > {
165165 src : & ' a str ,
166- stream : pulldown_cmark:: OffsetIter < ' a , ' a > ,
166+ stream : pulldown_cmark:: OffsetIter < ' a , DefaultBrokenLinkCallback > ,
167167 offset : usize ,
168168
169169 /// We can't actually put an event back into the `OffsetIter` stream, so instead we store it
@@ -210,7 +210,7 @@ macro_rules! collect_events {
210210}
211211
212212impl < ' a > SummaryParser < ' a > {
213- fn new ( text : & str ) -> SummaryParser < ' _ > {
213+ fn new ( text : & ' a str ) -> SummaryParser < ' a > {
214214 let pulldown_parser = pulldown_cmark:: Parser :: new ( text) . into_offset_iter ( ) ;
215215
216216 SummaryParser {
@@ -265,7 +265,12 @@ impl<'a> SummaryParser<'a> {
265265 loop {
266266 match self . next_event ( ) {
267267 Some ( ev @ Event :: Start ( Tag :: List ( ..) ) )
268- | Some ( ev @ Event :: Start ( Tag :: Heading ( HeadingLevel :: H1 , ..) ) ) => {
268+ | Some (
269+ ev @ Event :: Start ( Tag :: Heading {
270+ level : HeadingLevel :: H1 ,
271+ ..
272+ } ) ,
273+ ) => {
269274 if is_prefix {
270275 // we've finished prefix chapters and are at the start
271276 // of the numbered section.
@@ -275,8 +280,8 @@ impl<'a> SummaryParser<'a> {
275280 bail ! ( self . parse_error( "Suffix chapters cannot be followed by a list" ) ) ;
276281 }
277282 }
278- Some ( Event :: Start ( Tag :: Link ( _type , href , _title ) ) ) => {
279- let link = self . parse_link ( href . to_string ( ) ) ;
283+ Some ( Event :: Start ( Tag :: Link { dest_url , .. } ) ) => {
284+ let link = self . parse_link ( dest_url . to_string ( ) ) ;
280285 items. push ( SummaryItem :: Link ( link) ) ;
281286 }
282287 Some ( Event :: Rule ) => items. push ( SummaryItem :: Separator ) ,
@@ -304,10 +309,13 @@ impl<'a> SummaryParser<'a> {
304309 break ;
305310 }
306311
307- Some ( Event :: Start ( Tag :: Heading ( HeadingLevel :: H1 , ..) ) ) => {
312+ Some ( Event :: Start ( Tag :: Heading {
313+ level : HeadingLevel :: H1 ,
314+ ..
315+ } ) ) => {
308316 debug ! ( "Found a h1 in the SUMMARY" ) ;
309317
310- let tags = collect_events ! ( self . stream, end Tag :: Heading ( HeadingLevel :: H1 , .. ) ) ;
318+ let tags = collect_events ! ( self . stream, end TagEnd :: Heading ( HeadingLevel :: H1 ) ) ;
311319 Some ( stringify_events ( tags) )
312320 }
313321
@@ -336,7 +344,7 @@ impl<'a> SummaryParser<'a> {
336344 /// Finishes parsing a link once the `Event::Start(Tag::Link(..))` has been opened.
337345 fn parse_link ( & mut self , href : String ) -> Link {
338346 let href = href. replace ( "%20" , " " ) ;
339- let link_content = collect_events ! ( self . stream, end Tag :: Link ( .. ) ) ;
347+ let link_content = collect_events ! ( self . stream, end TagEnd :: Link ) ;
340348 let name = stringify_events ( link_content) ;
341349
342350 let path = if href. is_empty ( ) {
@@ -377,7 +385,12 @@ impl<'a> SummaryParser<'a> {
377385 }
378386 // The expectation is that pulldown cmark will terminate a paragraph before a new
379387 // heading, so we can always count on this to return without skipping headings.
380- Some ( ev @ Event :: Start ( Tag :: Heading ( HeadingLevel :: H1 , ..) ) ) => {
388+ Some (
389+ ev @ Event :: Start ( Tag :: Heading {
390+ level : HeadingLevel :: H1 ,
391+ ..
392+ } ) ,
393+ ) => {
381394 // we're starting a new part
382395 self . back ( ev) ;
383396 break ;
@@ -398,7 +411,7 @@ impl<'a> SummaryParser<'a> {
398411
399412 // Skip over the contents of this tag
400413 while let Some ( event) = self . next_event ( ) {
401- if event == Event :: End ( other_tag. clone ( ) ) {
414+ if event == Event :: End ( other_tag. clone ( ) . into ( ) ) {
402415 break ;
403416 }
404417 }
@@ -469,7 +482,7 @@ impl<'a> SummaryParser<'a> {
469482
470483 last_item. nested_items = sub_items;
471484 }
472- Some ( Event :: End ( Tag :: List ( ..) ) ) => break ,
485+ Some ( Event :: End ( TagEnd :: List ( ..) ) ) => break ,
473486 Some ( _) => { }
474487 None => break ,
475488 }
@@ -486,8 +499,8 @@ impl<'a> SummaryParser<'a> {
486499 loop {
487500 match self . next_event ( ) {
488501 Some ( Event :: Start ( Tag :: Paragraph ) ) => continue ,
489- Some ( Event :: Start ( Tag :: Link ( _type , href , _title ) ) ) => {
490- let mut link = self . parse_link ( href . to_string ( ) ) ;
502+ Some ( Event :: Start ( Tag :: Link { dest_url , .. } ) ) => {
503+ let mut link = self . parse_link ( dest_url . to_string ( ) ) ;
491504
492505 let mut number = parent. clone ( ) ;
493506 number. 0 . push ( num_existing_items as u32 + 1 ) ;
@@ -529,14 +542,18 @@ impl<'a> SummaryParser<'a> {
529542 fn parse_title ( & mut self ) -> Option < String > {
530543 loop {
531544 match self . next_event ( ) {
532- Some ( Event :: Start ( Tag :: Heading ( HeadingLevel :: H1 , ..) ) ) => {
545+ Some ( Event :: Start ( Tag :: Heading {
546+ level : HeadingLevel :: H1 ,
547+ ..
548+ } ) ) => {
533549 debug ! ( "Found a h1 in the SUMMARY" ) ;
534550
535- let tags = collect_events ! ( self . stream, end Tag :: Heading ( HeadingLevel :: H1 , .. ) ) ;
551+ let tags = collect_events ! ( self . stream, end TagEnd :: Heading ( HeadingLevel :: H1 ) ) ;
536552 return Some ( stringify_events ( tags) ) ;
537553 }
538554 // Skip a HTML element such as a comment line.
539- Some ( Event :: Html ( _) ) => { }
555+ Some ( Event :: Html ( _) | Event :: InlineHtml ( _) )
556+ | Some ( Event :: Start ( Tag :: HtmlBlock ) | Event :: End ( TagEnd :: HtmlBlock ) ) => { }
540557 // Otherwise, no title.
541558 Some ( ev) => {
542559 self . back ( ev) ;
@@ -744,7 +761,7 @@ mod tests {
744761 let _ = parser. stream . next ( ) ; // Discard opening paragraph
745762
746763 let href = match parser. stream . next ( ) {
747- Some ( ( Event :: Start ( Tag :: Link ( _type , href , _title ) ) , _range) ) => href . to_string ( ) ,
764+ Some ( ( Event :: Start ( Tag :: Link { dest_url , .. } ) , _range) ) => dest_url . to_string ( ) ,
748765 other => panic ! ( "Unreachable, {:?}" , other) ,
749766 } ;
750767
0 commit comments