Skip to content

Commit c84f467

Browse files
committed
Fix #1105: change order of markdown parsers to allow pipes in lists
1 parent 5329594 commit c84f467

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

src/Distribution/Server/Util/Markdown.hs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,30 @@ adjustRelativeLink url
120120
-- <p>Published to <a href="http://hackage.haskell.org/foo3/bar">http://hackage.haskell.org/foo3/bar</a>.</p>
121121
-- <BLANKLINE>
122122
--
123+
-- >>> renderMarkdown "test" "Issue #1105:\n- pipes\n- like `a|b`\n- should be allowed in lists"
124+
-- <p>Issue #1105:</p>
125+
-- <ul>
126+
-- <li>pipes
127+
-- </li>
128+
-- <li>like <code>a|b</code>
129+
-- </li>
130+
-- <li>should be allowed in lists
131+
-- </li>
132+
-- </ul>
133+
-- <BLANKLINE>
134+
--
135+
-- >>> renderMarkdown "test" "Tables should be supported:\n\nfoo|bar\n---|---\n"
136+
-- <p>Tables should be supported:</p>
137+
-- <table>
138+
-- <thead>
139+
-- <tr>
140+
-- <th>foo</th>
141+
-- <th>bar</th>
142+
-- </tr>
143+
-- </thead>
144+
-- </table>
145+
-- <BLANKLINE>
146+
--
123147
renderMarkdown
124148
:: String -- ^ Name or path of input.
125149
-> BS.ByteString -- ^ Commonmark text input.
@@ -160,11 +184,33 @@ renderMarkdown'
160184
-> BS.ByteString -- ^ Commonmark text input.
161185
-> XHtml.Html -- ^ Rendered HTML.
162186
renderMarkdown' render name md =
163-
either (const $ XHtml.pre XHtml.<< T.unpack txt) (XHtml.primHtml . T.unpack . sanitizeBalance . TL.toStrict . render) $
164-
runIdentity (commonmarkWith (mathSpec <> gfmExtensions <> defaultSyntaxSpec)
165-
name
166-
txt)
167-
where txt = T.decodeUtf8With T.lenientDecode . BS.toStrict $ md
187+
either (const $ fallback) mdToHTML $
188+
runIdentity $ commonmarkWith spec name txt
189+
where
190+
-- Input
191+
txt = T.decodeUtf8With T.lenientDecode . BS.toStrict $ md
192+
-- Fall back to HTML if there is a parse error for markdown
193+
fallback = XHtml.pre XHtml.<< T.unpack txt
194+
-- Conversion of parsed md to HTML
195+
mdToHTML = XHtml.primHtml . T.unpack . sanitizeBalance . TL.toStrict . render
196+
-- Specification of the markdown parser.
197+
-- Andreas Abel, 2022-07-21, issue #1105.
198+
-- Workaround for https://github.com/jgm/commonmark-hs/issues/95:
199+
-- Put the table parser last.
200+
spec = mconcat $
201+
mathSpec :
202+
-- all the gfm extensions except for tables
203+
emojiSpec :
204+
strikethroughSpec :
205+
autolinkSpec :
206+
autoIdentifiersSpec :
207+
taskListSpec :
208+
footnoteSpec :
209+
-- the default syntax
210+
defaultSyntaxSpec :
211+
-- the problematic table parser
212+
pipeTableSpec :
213+
[]
168214

169215
-- | Does the file extension suggest that the file is in markdown syntax?
170216
supposedToBeMarkdown :: FilePath -> Bool

0 commit comments

Comments
 (0)