diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-09-14 16:21:42 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-09-14 16:26:24 +0200 |
commit | 74d2688aa329f0a41c2a92034c3454ed9299e71a (patch) | |
tree | 9ec8fdc6e40ff7cd40a14408afcc47716990134e /src/resolve.rs | |
parent | 65d4b46c2a3bdecb0493e484473d2de3d124f839 (diff) | |
download | markdown-rs-74d2688aa329f0a41c2a92034c3454ed9299e71a.tar.gz markdown-rs-74d2688aa329f0a41c2a92034c3454ed9299e71a.tar.bz2 markdown-rs-74d2688aa329f0a41c2a92034c3454ed9299e71a.zip |
Fix to prefer flow over definitions, setext headings
An undocumented part of CommonMark is how to deal with things in definition
labels or definition titles (which both can span multiple lines).
Can flow (or containers?) interrupt them?
They can according to the `cmark` reference parser, so this was implemented here.
This adds a new `Content` content type, which houses zero or more definitions,
and then zero-or-one paragraphs.
Content can be followed by a setext heading underline, which either turns
into a setext heading when the content ends in a paragraph, or turns into
the start of the following paragraph when it is followed by content that
starts with a paragraph, or turns into a stray paragraph.
Diffstat (limited to '')
-rw-r--r-- | src/resolve.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/resolve.rs b/src/resolve.rs index d015213..2586676 100644 --- a/src/resolve.rs +++ b/src/resolve.rs @@ -1,7 +1,9 @@ //! Resolve events. use crate::construct; +use crate::subtokenize::Subresult; use crate::tokenizer::Tokenizer; +use alloc::string::String; /// Names of resolvers. #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -32,8 +34,8 @@ pub enum Name { HeadingAtx, /// Resolve heading (setext). /// - /// Heading (setext) is parsed as an underline that is preceded by a - /// paragraph, both will form the whole construct. + /// Heading (setext) is parsed as an underline that is preceded by content, + /// both will form the whole construct. HeadingSetext, /// Resolve list item. /// @@ -41,12 +43,12 @@ pub enum Name { /// They are wrapped into ordered or unordered lists based on whether items /// with the same marker occur next to each other. ListItem, - /// Resolve paragraphs. + /// Resolve content. /// - /// Paragraphs are parsed as single line paragraphs, as what remains if - /// other flow constructs don’t match. + /// Content is parsed as single lines, as what remains if other flow + /// constructs don’t match. /// But, when they occur next to each other, they need to be merged. - Paragraph, + Content, /// Resolve data. /// /// Data is parsed as many small bits, due to many punctuation characters @@ -61,7 +63,7 @@ pub enum Name { } /// Call the corresponding resolver. -pub fn call(tokenizer: &mut Tokenizer, name: Name) { +pub fn call(tokenizer: &mut Tokenizer, name: Name) -> Result<Option<Subresult>, String> { let func = match name { Name::Label => construct::label_end::resolve, Name::Attention => construct::attention::resolve, @@ -69,11 +71,11 @@ pub fn call(tokenizer: &mut Tokenizer, name: Name) { Name::HeadingAtx => construct::heading_atx::resolve, Name::HeadingSetext => construct::heading_setext::resolve, Name::ListItem => construct::list_item::resolve, - Name::Paragraph => construct::paragraph::resolve, + Name::Content => construct::content::resolve, Name::Data => construct::partial_data::resolve, Name::String => construct::string::resolve, Name::Text => construct::text::resolve, }; - func(tokenizer); + func(tokenizer) } |