Skip to content

Commit f78c09f

Browse files
committed
HTML Reader: Use underlineSpan and add test case
1 parent dce46bd commit f78c09f

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/Text/Pandoc/Readers/HTML.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import Text.Pandoc.Definition
4444
import qualified Text.Pandoc.Builder as B
4545
import Text.Pandoc.Builder (Blocks, Inlines, trimInlines, HasMeta(..))
4646
import Text.Pandoc.Shared ( extractSpaces, renderTags'
47-
, escapeURI, safeRead, mapLeft )
47+
, escapeURI, safeRead, mapLeft, underlineSpan )
4848
import Text.Pandoc.Options (ReaderOptions(readerParseRaw, readerTrace)
4949
, Extension (Ext_epub_html_exts,
5050
Ext_native_divs, Ext_native_spans))
@@ -495,6 +495,7 @@ inline = choice
495495
, pSuperscript
496496
, pSubscript
497497
, pStrikeout
498+
, pUnderline
498499
, pLineBreak
499500
, pLink
500501
, pImage
@@ -563,6 +564,9 @@ pStrikeout = do
563564
contents <- mconcat <$> manyTill inline (pCloses "span")
564565
return $ B.strikeout contents)
565566

567+
pUnderline :: TagParser Inlines
568+
pUnderline = pInlinesInTags "u" underlineSpan <|> pInlinesInTags "ins" underlineSpan
569+
566570
pLineBreak :: TagParser Inlines
567571
pLineBreak = do
568572
pSelfClosing (=="br") (const True)

tests/html-reader.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ <h1>Inline Markup</h1>
310310
<p>So is <strong><em>this</em></strong> word.</p>
311311
<p>This is code: <code>&gt;</code>, <code>$</code>, <code>\</code>, <code>\$</code>, <code>&lt;html&gt;</code>.</p>
312312
<p>This is <span style="font-variant: small-caps;">small caps</span>.</p>
313+
<p>These are all underlined: <u>foo</u> and <ins>bar</ins>.</p>
314+
<p>These are all strikethrough: <s>foo</s>, <strike>bar</strike>, and <del>baz</del>.</p>
313315
<hr />
314316
<h1>Smart quotes, ellipses, dashes</h1>
315317
<p>"Hello," said the spider. "'Shelob' is my name."</p>

tests/html-reader.native

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("titl
194194
,Para [Str "So",Space,Str "is",Space,Strong [Emph [Str "this"]],Space,Str "word."]
195195
,Para [Str "This",Space,Str "is",Space,Str "code:",Space,Code ("",[],[]) ">",Str ",",Space,Code ("",[],[]) "$",Str ",",Space,Code ("",[],[]) "\\",Str ",",Space,Code ("",[],[]) "\\$",Str ",",Space,Code ("",[],[]) "<html>",Str "."]
196196
,Para [Str "This",Space,Str "is",Space,SmallCaps [Str "small",Space,Str "caps"],Str "."]
197+
,Para [Str "These",Space,Str "are",Space,Str "all",Space,Str "underlined:",Space,Span ("",["underline"],[]) [Str "foo"],Space,Str "and",Space,Span ("",["underline"],[]) [Str "bar"],Str "."]
198+
,Para [Str "These",Space,Str "are",Space,Str "all",Space,Str "strikethrough:",Space,Strikeout [Str "foo"],Str ",",Space,Strikeout [Str "bar"],Str ",",Space,Str "and",Space,Strikeout [Str "baz"],Str "."]
197199
,HorizontalRule
198200
,Header 1 ("",[],[]) [Str "Smart",Space,Str "quotes,",Space,Str "ellipses,",Space,Str "dashes"]
199201
,Para [Str "\"Hello,\"",Space,Str "said",Space,Str "the",Space,Str "spider.",Space,Str "\"'Shelob'",Space,Str "is",Space,Str "my",Space,Str "name.\""]

0 commit comments

Comments
 (0)