@@ -111,7 +111,7 @@ headline lvl = try $ do
111111 newline
112112 properties <- option mempty propertiesDrawer
113113 contents <- blocks
114− children <- many (headline (lvl + 1))
114+ children <- many (headline (level + 1))
115115 return $ do
116116 title' <- title
117117 contents' <- contents
@@ -135,12 +135,14 @@ headline lvl = try $ do
135135
136136-- | Convert an Org mode headline (i.e. a document tree) into pandoc's Blocks
137137headlineToBlocks :: Headline -> OrgParser Blocks
138−headlineToBlocks hdln@(Headline {..}) =
138+headlineToBlocks hdln@(Headline {..}) = do
139+ maxHeadlineLevels <- getExportSetting exportHeadlineLevels
139140 case () of
140− _ | any isNoExportTag headlineTags -> return mempty
141− _ | any isArchiveTag headlineTags -> archivedHeadlineToBlocks hdln
142− _ | isCommentTitle headlineText -> return mempty
143− _ -> headlineToHeaderWithContents hdln
141+ _ | any isNoExportTag headlineTags -> return mempty
142+ _ | any isArchiveTag headlineTags -> archivedHeadlineToBlocks hdln
143+ _ | isCommentTitle headlineText -> return mempty
144+ _ | headlineLevel >= maxHeadlineLevels -> headlineToHeaderWithList hdln
145+ _ -> headlineToHeaderWithContents hdln
144146
145147isNoExportTag :: Tag -> Bool
146148isNoExportTag = (== toTag "noexport")
@@ -163,6 +165,25 @@ archivedHeadlineToBlocks hdln = do
163165 ArchivedTreesExport -> headlineToHeaderWithContents hdln
164166 ArchivedTreesHeadlineOnly -> headlineToHeader hdln
165167
168+headlineToHeaderWithList :: Headline -> OrgParser Blocks
169+headlineToHeaderWithList hdln@(Headline {..}) = do
170+ maxHeadlineLevels <- getExportSetting exportHeadlineLevels
171+ header <- headlineToHeader hdln
172+ listElements <- sequence (map headlineToBlocks headlineChildren)
173+ let listBlock = if null listElements
174+ then mempty
175+ else B.orderedList listElements
176+ let headerText = if maxHeadlineLevels == headlineLevel
177+ then header
178+ else flattenHeader header
179+ return $ headerText <> headlineContents <> listBlock
180+ where
181+ flattenHeader :: Blocks -> Blocks
182+ flattenHeader blks =
183+ case B.toList blks of
184+ (Header _ _ inlns:_) -> B.para (B.fromList inlns)
185+ _ -> mempty
186+
166187headlineToHeaderWithContents :: Headline -> OrgParser Blocks
167188headlineToHeaderWithContents hdln@(Headline {..}) = do
168189 header <- headlineToHeader hdln