From 678a90d99c6e3e3bab72307db677fc5e9ad64e76 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Mon, 25 Mar 2024 11:52:32 -0400 Subject: [PATCH 1/4] Remove Note from plainify output --- src/Commonmark/Extensions/WikiLink.hs | 53 +++++++++++++++------------ 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/Commonmark/Extensions/WikiLink.hs b/src/Commonmark/Extensions/WikiLink.hs index 6c88d69..0f9ee15 100644 --- a/src/Commonmark/Extensions/WikiLink.hs +++ b/src/Commonmark/Extensions/WikiLink.hs @@ -263,26 +263,33 @@ wikilinkSpec = TODO: extend on top of plainify from heist-extra -} plainify :: [B.Inline] -> Text -plainify = W.query $ \case - B.Str x -> x - B.Code _attr x -> x - B.Space -> " " - B.SoftBreak -> " " - B.LineBreak -> " " - -- TODO: if fmt is html, we should strip the html tags - B.RawInline _fmt s -> s - -- Ignore "wrapper" inlines like span. - B.Span _ _ -> "" - -- TODO: How to wrap math stuff here? - B.Math _mathTyp s -> s - -- Wiki-links must be displayed using its show instance (which returns its - -- human-readable representation) - (mkWikiLinkFromInline -> Just (wl, customText)) -> - if null customText - then -- We will display raw wikilink; ideally, though, we want to display the title. - show wl - else -- Because `W.query` will walk the child nodes once again, so we don't have to do anything. - "" - -- Ignore the rest of AST nodes, as they are recursively defined in terms of - -- `Inline` which `W.query` will traverse again. - _ -> "" +plainify = W.query doPlainify . W.walk (mapMaybe removeInlineNotes) + where + removeInlineNotes :: B.Inline -> Maybe B.Inline + removeInlineNotes = \case + B.Note {} -> Nothing + a -> Just a + + doPlainify = \case + B.Str x -> x + B.Code _attr x -> x + B.Space -> " " + B.SoftBreak -> " " + B.LineBreak -> " " + -- TODO: if fmt is html, we should strip the html tags + B.RawInline _fmt s -> s + -- Ignore "wrapper" inlines like span. + B.Span _ _ -> "" + -- TODO: How to wrap math stuff here? + B.Math _mathTyp s -> s + -- Wiki-links must be displayed using its show instance (which returns its + -- human-readable representation) + (mkWikiLinkFromInline -> Just (wl, customText)) -> + if null customText + then -- We will display raw wikilink; ideally, though, we want to display the title. + show wl + else -- Because `W.query` will walk the child nodes once again, so we don't have to do anything. + "" + -- Ignore the rest of AST nodes, as they are recursively defined in terms of + -- `Inline` which `W.query` will traverse again. + _ -> "" From 4158b46666a86c501364e9440af21ff6c36ac13d Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 25 Mar 2024 12:36:30 -0400 Subject: [PATCH 2/4] minimize diff --- src/Commonmark/Extensions/WikiLink.hs | 49 ++++++++++++++------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Commonmark/Extensions/WikiLink.hs b/src/Commonmark/Extensions/WikiLink.hs index 0f9ee15..2125f82 100644 --- a/src/Commonmark/Extensions/WikiLink.hs +++ b/src/Commonmark/Extensions/WikiLink.hs @@ -263,33 +263,34 @@ wikilinkSpec = TODO: extend on top of plainify from heist-extra -} plainify :: [B.Inline] -> Text -plainify = W.query doPlainify . W.walk (mapMaybe removeInlineNotes) +plainify = W.query plainify' . W.walk (mapMaybe removeInlineNotes) where removeInlineNotes :: B.Inline -> Maybe B.Inline removeInlineNotes = \case B.Note {} -> Nothing a -> Just a - doPlainify = \case - B.Str x -> x - B.Code _attr x -> x - B.Space -> " " - B.SoftBreak -> " " - B.LineBreak -> " " - -- TODO: if fmt is html, we should strip the html tags - B.RawInline _fmt s -> s - -- Ignore "wrapper" inlines like span. - B.Span _ _ -> "" - -- TODO: How to wrap math stuff here? - B.Math _mathTyp s -> s - -- Wiki-links must be displayed using its show instance (which returns its - -- human-readable representation) - (mkWikiLinkFromInline -> Just (wl, customText)) -> - if null customText - then -- We will display raw wikilink; ideally, though, we want to display the title. - show wl - else -- Because `W.query` will walk the child nodes once again, so we don't have to do anything. - "" - -- Ignore the rest of AST nodes, as they are recursively defined in terms of - -- `Inline` which `W.query` will traverse again. - _ -> "" +plainify' :: [B.Inline] -> Text +plainify' = W.query $ \case + B.Str x -> x + B.Code _attr x -> x + B.Space -> " " + B.SoftBreak -> " " + B.LineBreak -> " " + -- TODO: if fmt is html, we should strip the html tags + B.RawInline _fmt s -> s + -- Ignore "wrapper" inlines like span. + B.Span _ _ -> "" + -- TODO: How to wrap math stuff here? + B.Math _mathTyp s -> s + -- Wiki-links must be displayed using its show instance (which returns its + -- human-readable representation) + (mkWikiLinkFromInline -> Just (wl, customText)) -> + if null customText + then -- We will display raw wikilink; ideally, though, we want to display the title. + show wl + else -- Because `W.query` will walk the child nodes once again, so we don't have to do anything. + "" + -- Ignore the rest of AST nodes, as they are recursively defined in terms of + -- `Inline` which `W.query` will traverse again. + _ -> "" From 3cf6de6d29eaab1858e66e4b203372daa25a4032 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 25 Mar 2024 15:08:10 -0400 Subject: [PATCH 3/4] Re-enable the test --- test/Commonmark/Extensions/WikiLinkSpec.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Commonmark/Extensions/WikiLinkSpec.hs b/test/Commonmark/Extensions/WikiLinkSpec.hs index 3a94cc8..55f26bc 100644 --- a/test/Commonmark/Extensions/WikiLinkSpec.hs +++ b/test/Commonmark/Extensions/WikiLinkSpec.hs @@ -35,8 +35,7 @@ spec = do plainify <$> parseMdPara1 "[Hello](https://example.com)" `shouldBe` Right "Hello" it "with wikilink" $ do plainify <$> parseMdPara1 "[[World]]" `shouldBe` Right "[[World]]" - -- FIXME - xit "with footnote" $ do + it "with footnote" $ do plainify <$> parseMdPara1 "Hello[^1] World.\n\n[^1]: Some footnote." `shouldBe` Right "Hello World." -- | Parse Markdown with our wikilink parser enabled From e706b2c4b6ed4ed92590ff7502c9d1bf862b5114 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 25 Mar 2024 15:13:30 -0400 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61dec63..96be753 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ ## Unreleased -- `plainify`: Fix double scanning of inlines of wiki-links +- Fixes + - `plainify` + - Fix double scanning of inlines of wiki-links + - Remove footnotes (\#3) ## 0.1.0.0