ConTeXt writer: add support for unlisted, unnumbered headings

Closes: #8486
This commit is contained in:
Albert Krewinkel
2022-12-16 13:48:57 +01:00
parent 1698af8885
commit da2d7ce6f5
2 changed files with 53 additions and 12 deletions
+10 -12
View File
@@ -664,20 +664,18 @@ sectionHeader (ident,classes,kvs) hdrLevel lst secenv = do
opts <- gets stOptions
contents <- inlineListToConTeXt lst
levelText <- sectionLevelToText opts (ident,classes,kvs) hdrLevel secenv
let ident' = if T.null ident
then empty
else "reference=" <> braces (literal (toLabel ident))
let contents' = if isEmpty contents
then empty
else "title=" <> braces contents
let options = if isEmpty keys || isEmpty levelText
then empty
else brackets keys
where keys = hcat $ intersperse "," $
filter (not . isEmpty) [contents', ident']
let optsList = mconcat . filter (not . null) $
[ ["title=" <> braces contents | not (isEmpty contents)]
, ["reference=" <> braces (literal (toLabel ident)) | not (T.null ident)]
, ["number=no" | "unnumbered" `elem` classes]
, ["incrementnumber=no" | "unnumbered" `elem` classes]
]
let starter = case secenv of
SectionHeading -> "\\start"
NonSectionHeading -> "\\"
let options = if null optsList || isEmpty levelText
then empty
else brackets $ hcat (intersperse "," optsList)
return $ starter <> levelText <> options <> blankline
-- | Craft the section footer
@@ -693,7 +691,7 @@ sectionLevelToText :: PandocMonad m
-> WM m (Doc Text)
sectionLevelToText opts (_,classes,_) hdrLevel headingType = do
let semanticSection shift = do
let (section, chapter) = if "unnumbered" `elem` classes
let (section, chapter) = if "unlisted" `elem` classes
then (literal "subject", literal "title")
else (literal "section", literal "chapter")
return $ case hdrLevel + shift of
+43
View File
@@ -0,0 +1,43 @@
# Unnumbered and unlisted headings in ConTeXt
```
% pandoc --to=context
# Preface {.unlisted -}
Nullam rutrum.
# Introduction
Nullam eu ante vel est convallis dignissim.
# Methods
Sed diam. Nulla posuere. Praesent fermentum tempor tellus. Nam
vestibulum accumsan nisl. Nam vestibulum accumsan nisl.
# References {-}
^D
\startsectionlevel[title={Preface},reference={preface},number=no,incrementnumber=no]
Nullam rutrum.
\stopsectionlevel
\startsectionlevel[title={Introduction},reference={introduction}]
Nullam eu ante vel est convallis dignissim.
\stopsectionlevel
\startsectionlevel[title={Methods},reference={methods}]
Sed diam. Nulla posuere. Praesent fermentum tempor tellus. Nam
vestibulum accumsan nisl. Nam vestibulum accumsan nisl.
\stopsectionlevel
\startsectionlevel[title={References},reference={references},number=no,incrementnumber=no]
\stopsectionlevel
```