git.iko.soy/typeable/pandoc
on master help sign in
Org reader: respect unnumbered header property
21cd76cAlbert Krewinkel
src/Text/Pandoc/Readers/Org/Blocks.hs+10−2
@@ -80,6 +80,10 @@ newtype PropertyValue = PropertyValue { fromValue :: String }
80toPropertyValue :: String -> PropertyValue
80toPropertyValue :: String -> PropertyValue
81toPropertyValue = PropertyValue
81toPropertyValue = PropertyValue
82
82
83+-- | Check whether the property value is non-nil (i.e. truish).
84+isNonNil :: PropertyValue -> Bool
85+isNonNil p = map toLower (fromValue p) `notElem` ["()", "{}", "nil"]
86+
83-- | Key/value pairs from a PROPERTIES drawer
87-- | Key/value pairs from a PROPERTIES drawer
84type Properties = [(PropertyKey, PropertyValue)]
88type Properties = [(PropertyKey, PropertyValue)]
85
89
@@ -200,12 +204,16 @@ propertiesToAttr properties =
200 toStringPair prop = (fromKey (fst prop), fromValue (snd prop))
204 toStringPair prop = (fromKey (fst prop), fromValue (snd prop))
201 customIdKey = toPropertyKey "custom_id"
205 customIdKey = toPropertyKey "custom_id"
202 classKey = toPropertyKey "class"
206 classKey = toPropertyKey "class"
207+ unnumberedKey = toPropertyKey "unnumbered"
208+ specialProperties = [customIdKey, classKey, unnumberedKey]
203 id' = fromMaybe mempty . fmap fromValue . lookup customIdKey $ properties
209 id' = fromMaybe mempty . fmap fromValue . lookup customIdKey $ properties
204 cls = fromMaybe mempty . fmap fromValue . lookup classKey $ properties
210 cls = fromMaybe mempty . fmap fromValue . lookup classKey $ properties
205− kvs' = map toStringPair . filter ((`notElem` [customIdKey, classKey]) . fst)
211+ kvs' = map toStringPair . filter ((`notElem` specialProperties) . fst)
206 $ properties
212 $ properties
213+ isUnnumbered =
214+ fromMaybe False . fmap isNonNil . lookup unnumberedKey $ properties
207 in
215 in
208− (id', words cls, kvs')
216+ (id', words cls ++ (if isUnnumbered then ["unnumbered"] else []), kvs')
209
217
210tagTitle :: Inlines -> [Tag] -> Inlines
218tagTitle :: Inlines -> [Tag] -> Inlines
211tagTitle title tags = title <> (mconcat $ map tagToInline tags)
219tagTitle title tags = title <> (mconcat $ map tagToInline tags)
tests/Tests/Readers/Org.hs+9
@@ -818,6 +818,15 @@ tests =
818 ] =?>
818 ] =?>
819 headerWith ("fubar", [], [("bar", "baz")]) 1 "foo"
819 headerWith ("fubar", [], [("bar", "baz")]) 1 "foo"
820
820
821+
822+ , "Headers marked with a unnumbered property get a class of the same name" =:
823+ unlines [ "* Not numbered"
824+ , " :PROPERTIES:"
825+ , " :UNNUMBERED: t"
826+ , " :END:"
827+ ] =?>
828+ headerWith ("not-numbered", ["unnumbered"], []) 1 "Not numbered"
829+
821 , "Paragraph starting with an asterisk" =:
830 , "Paragraph starting with an asterisk" =:
822 "*five" =?>
831 "*five" =?>
823 para "*five"
832 para "*five"