Skip to content

Commit 95d8814

Browse files
committed
Unit tests for renderMarkdown in doctest format (#1000, #1001)
1 parent d179da8 commit 95d8814

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Distribution/Server/Util/Markdown.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ import System.FilePath.Posix (takeExtension)
2828
import qualified Data.ByteString.Lazy as BS (ByteString, toStrict)
2929
import qualified Text.XHtml.Strict as XHtml
3030

31+
-- Set up doctest to deal with bytestring literals.
32+
-- Need to import a suitable @instance IsString@ for @ByteString@.
33+
34+
-- $setup
35+
-- >>> :set -XOverloadedStrings
36+
-- >>> import Data.ByteString.Lazy.Char8 ()
37+
3138
-- HHtml wraps Html, and mostly behaves the same, except that
3239
-- relative links in images and urls have "src/" prepended.
3340
newtype HHtml a = HHtml { unHHtml :: Html a }
@@ -104,13 +111,27 @@ adjustRelativeLink url
104111
| otherwise = url
105112

106113
-- | Render markdown to HTML.
114+
--
115+
-- >>> renderMarkdown "test" "Please send bug reports to [email protected]."
116+
-- <p>Please send bug reports to <a href="mailto:[email protected]">[email protected]</a>.</p>
117+
-- <BLANKLINE>
118+
--
119+
-- >>> renderMarkdown "test" "Published to http://hackage.haskell.org/foo3/bar."
120+
-- <p>Published to <a href="http://hackage.haskell.org/foo3/bar">http://hackage.haskell.org/foo3/bar</a>.</p>
121+
-- <BLANKLINE>
122+
--
107123
renderMarkdown
108124
:: String -- ^ Name or path of input.
109125
-> BS.ByteString -- ^ Commonmark text input.
110126
-> XHtml.Html -- ^ Rendered HTML.
111127
renderMarkdown = renderMarkdown' (renderHtml :: Html () -> TL.Text)
112128

113129
-- | Render markdown to HTML, prefixing relative links with @src/@.
130+
--
131+
-- >>> renderMarkdownRel "test" "See [world file](world.txt)."
132+
-- <p>See <a href="src/world.txt">world file</a>.</p>
133+
-- <BLANKLINE>
134+
--
114135
renderMarkdownRel
115136
:: String -- ^ Name or path of input.
116137
-> BS.ByteString -- ^ Commonmark text input.

0 commit comments

Comments
 (0)