aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-04 14:38:09 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-04 14:38:09 +0100
commit0795244458868839cf8135ed20724b8a0b1a173f (patch)
tree17eff1d3ea80bb7de2c01eca1f03835a565ae4ac /src/Text/Pandoc/Readers
parent738880bfcbb6dc9b8327b0dc2cde4129071b0c2f (diff)
downloadpandoc-0795244458868839cf8135ed20724b8a0b1a173f.tar.gz
Markdown reader: treat span with class `smallcaps` as SmallCaps.
This allows users to specify small caps in Markdown this way: [my text]{.smallcaps} See #1592.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 6fb1cc40c..fb5da022a 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1780,13 +1780,21 @@ bracketedSpan = try $ do
guardEnabled Ext_bracketed_spans
(lab,_) <- reference
attr <- attributes
- let (ident,classes,keyvals) = attr
- case lookup "style" keyvals of
- Just s | null ident && null classes &&
- map toLower (filter (`notElem` " \t;") s) ==
- "font-variant:small-caps"
- -> return $ B.smallcaps <$> lab
- _ -> return $ B.spanWith attr <$> lab
+ return $ if isSmallCaps attr
+ then B.smallcaps <$> lab
+ else B.spanWith attr <$> lab
+
+-- | We treat a span as SmallCaps if class is "smallcaps" (and
+-- no other attributes are set or if style is "font-variant:small-caps"
+-- (and no other attributes are set).
+isSmallCaps :: Attr -> Bool
+isSmallCaps ("",["smallcaps"],[]) = True
+isSmallCaps ("",[],kvs) =
+ case lookup "style" kvs of
+ Just s -> map toLower (filter (`notElem` " \t;") s) ==
+ "font-variant:small-caps"
+ Nothing -> False
+isSmallCaps _ = False
regLink :: PandocMonad m
=> (Attr -> String -> String -> Inlines -> Inlines)
@@ -1930,12 +1938,9 @@ spanHtml = try $ do
let ident = fromMaybe "" $ lookup "id" attrs
let classes = maybe [] words $ lookup "class" attrs
let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
- case lookup "style" keyvals of
- Just s | null ident && null classes &&
- map toLower (filter (`notElem` " \t;") s) ==
- "font-variant:small-caps"
- -> return $ B.smallcaps <$> contents
- _ -> return $ B.spanWith (ident, classes, keyvals) <$> contents
+ return $ if isSmallCaps (ident, classes, keyvals)
+ then B.smallcaps <$> contents
+ else B.spanWith (ident, classes, keyvals) <$> contents
divHtml :: PandocMonad m => MarkdownParser m (F Blocks)
divHtml = try $ do