git.iko.soy/typeable/pandoc
on master help sign in
Org reader: respect unnumbered header property

Sections the `unnumbered` property should, as the name implies, be excluded from the automatic numbering of section provided by some output formats. The Pandoc convention for this is to add an "unnumbered" class to the header. The reader treats properties as key-value pairs per default, so a special case is added to translate the above property to a class instead. Closes #3095.

commit21cd76c2012457cfb14aa064ebf0c007b47da82f authorAlbert Krewinkel <albert@zeitkraut.de> dateTue 30 Aug 2016, 18:10 (10 years ago) parentabc4bca
2 files changed+19−2
src/Text/Pandoc/Readers/Org/Blocks.hs+10−2 tests/Tests/Readers/Org.hs+9
src/Text/Pandoc/Readers/Org/Blocks.hs+10−2
@@ -80,6 +80,10 @@ newtype PropertyValue = PropertyValue { fromValue :: String }
8080toPropertyValue :: String -> PropertyValue
8181toPropertyValue = PropertyValue
8282
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+
8387-- | Key/value pairs from a PROPERTIES drawer
8488type Properties = [(PropertyKey, PropertyValue)]
8589
@@ -200,12 +204,16 @@ propertiesToAttr properties =
200204 toStringPair prop = (fromKey (fst prop), fromValue (snd prop))
201205 customIdKey = toPropertyKey "custom_id"
202206 classKey = toPropertyKey "class"
207+ unnumberedKey = toPropertyKey "unnumbered"
208+ specialProperties = [customIdKey, classKey, unnumberedKey]
203209 id' = fromMaybe mempty . fmap fromValue . lookup customIdKey $ properties
204210 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)
206212 $ properties
213+ isUnnumbered =
214+ fromMaybe False . fmap isNonNil . lookup unnumberedKey $ properties
207215 in
208− (id', words cls, kvs')
216+ (id', words cls ++ (if isUnnumbered then ["unnumbered"] else []), kvs')
209217
210218tagTitle :: Inlines -> [Tag] -> Inlines
211219tagTitle title tags = title <> (mconcat $ map tagToInline tags)
tests/Tests/Readers/Org.hs+9
@@ -818,6 +818,15 @@ tests =
818818 ] =?>
819819 headerWith ("fubar", [], [("bar", "baz")]) 1 "foo"
820820
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+
821830 , "Paragraph starting with an asterisk" =:
822831 "*five" =?>
823832 para "*five"