Skip to content

Commit 7cbfb46

Browse files
committed
HTML Reader: Use underlineSpan and add test case
1 parent 10b80cb commit 7cbfb46

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
@@ -45,7 +45,7 @@ import Text.Pandoc.Definition
4545
import qualified Text.Pandoc.Builder as B
4646
import Text.Pandoc.Builder (Blocks, Inlines, trimInlines, HasMeta(..))
4747
import Text.Pandoc.Shared ( extractSpaces, addMetaField
48-
, escapeURI, safeRead, crFilter )
48+
, escapeURI, safeRead, crFilter, underlineSpan )
4949
import Text.Pandoc.Options (
5050
ReaderOptions(readerExtensions,readerStripComments), extensionEnabled,
5151
Extension (Ext_epub_html_exts,
@@ -627,6 +627,7 @@ inline = choice
627627
, pSuperscript
628628
, pSubscript
629629
, pStrikeout
630+
, pUnderline
630631
, pLineBreak
631632
, pLink
632633
, pImage
@@ -696,6 +697,9 @@ pStrikeout = do
696697
contents <- mconcat <$> manyTill inline (pCloses "span")
697698
return $ B.strikeout contents)
698699

700+
pUnderline :: PandocMonad m => TagParser m Inlines
701+
pUnderline = pInlinesInTags "u" underlineSpan <|> pInlinesInTags "ins" underlineSpan
702+
699703
pLineBreak :: PandocMonad m => TagParser m Inlines
700704
pLineBreak = do
701705
pSelfClosing (=="br") (const True)

test/html-reader.html

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

test/html-reader.native

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("titl
207207
,Para [Str "So",Space,Str "is",Space,Strong [Emph [Str "this"]],Space,Str "word."]
208208
,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 "."]
209209
,Para [Str "This",Space,Str "is",Space,SmallCaps [Str "small",Space,Str "caps"],Str "."]
210+
,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 "."]
211+
,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 "."]
210212
,HorizontalRule
211213
,Header 1 ("smart-quotes-ellipses-dashes",[],[]) [Str "Smart",Space,Str "quotes,",Space,Str "ellipses,",Space,Str "dashes"]
212214
,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)