Skip to content

Commit e2d7104

Browse files
committed
added tests for reifyFootnotes and inced asset version
1 parent 302f17f commit e2d7104

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/CMark/Extended.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ reifyFootnotes body =
9898
href i = "href=\"#fnr-" <> show i <> "\""
9999
referenceS _ = ""
100100
footnoteS :: Text -> Text
101-
footnoteS _ = "\n\n"
101+
footnoteS _ = ""
102102

103103
renderMarkdown :: Text -> Text
104104
renderMarkdown = commonmarkToHtml [optUnsafe]

src/Lib/Server/Template.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ instance ToHtml a => ToHtml (Template a) where
3232
let description = case descriptionM of
3333
Nothing -> "unsafePerformIO is the blog and personal website of Wilfred Denton."
3434
Just description' -> description'
35-
assetVer = "11"
35+
assetVer = "12"
3636
title_ $ toHtml title
3737
meta_ [charset_ "utf-8"]
3838
meta_ [name_ "description", content_ description]

test/Spec/Markdown.hs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Spec.Markdown (markdownSpec) where
22

3-
import CMark.Extended (extractMetaDescription, linkifyHeaders, renderMarkdown)
3+
import CMark.Extended (extractMetaDescription, linkifyHeaders, reifyFootnotes, renderMarkdown)
44
import Protolude
55
import Test.Tasty.Hspec (Spec, describe, it, shouldReturn)
66

@@ -47,3 +47,25 @@ markdownSpec = do
4747
it "returns modified" $
4848
runLinkifyHeaders "## [Foo](https://foo.com)"
4949
`shouldReturn` "## <a class=\"h-anchor\" id=\"foo\" href=\"#foo\">#</a>[Foo](https://foo.com)"
50+
describe "Reify Footnotes" $ do
51+
let runReifyFootnotes = pure . reifyFootnotes
52+
it "returns unmodified" $
53+
runReifyFootnotes "" `shouldReturn` ""
54+
it "returns unmodified" $
55+
runReifyFootnotes "foo" `shouldReturn` "foo"
56+
it "returns unmodified" $
57+
runReifyFootnotes "foo\n\n" `shouldReturn` "foo\n\n"
58+
it "returns with empty footnote block" $
59+
-- must be prefixed with \n\n (block)
60+
-- without references generated footnote block is empty
61+
runReifyFootnotes "[^foo]: hey\n\n[^bar]: you"
62+
`shouldReturn` "[^foo]: hey\n\n---\n\n<ol></ol>"
63+
it "returns with empty footnote block" $
64+
runReifyFootnotes "\n\n[^foo]: hey\n\n[^bar]: you"
65+
`shouldReturn` "\n\n---\n\n<ol></ol>"
66+
it "returns with correct footnote block" $
67+
runReifyFootnotes "foo.[^foo]\n\nbar.[^bar]\n\n[^foo]: hey\n\n[^bar]: you"
68+
`shouldReturn` "foo.<sup><a id=\"fn-1\" href=\"#fnr-1\">1</a></sup>\n\nbar.<sup><a id=\"fn-2\" href=\"#fnr-2\">2</a></sup>\n\n---\n\n<ol><li id=\"fnr-1\"><p>hey <a class=\"rfn\" href=\"#fn-1\">\8617</a></p>\n</li>\n<li id=\"fnr-2\"><p>you <a class=\"rfn\" href=\"#fn-2\">\8617</a></p>\n</li>\n</ol>"
69+
it "returns with correct footnote block" $
70+
runReifyFootnotes "foo.[^foo]\n\n[^foo]: hey\n\n[^bar]: you\n\nbar.[^bar]\n\n"
71+
`shouldReturn` "foo.<sup><a id=\"fn-1\" href=\"#fnr-1\">1</a></sup>\n\nbar.<sup><a id=\"fn-2\" href=\"#fnr-2\">2</a></sup>\n\n---\n\n<ol><li id=\"fnr-1\"><p>hey <a class=\"rfn\" href=\"#fn-1\">\8617</a></p>\n</li>\n<li id=\"fnr-2\"><p>you <a class=\"rfn\" href=\"#fn-2\">\8617</a></p>\n</li>\n</ol>"

0 commit comments

Comments
 (0)