git.iko.soy/typeable/pandoc
on master help sign in
Org reader: respect export option `p` for planning info

Inclusion of planning info (*DEADLINE*, *SCHEDULED*, and *CLOSED*) can be controlled via the `p` export option: setting the option to `t` will add all planning information in a *Plain* block below the respective headline.

commit275afec38a9feb1143344af19d5ebfbf4ef4fb32 authorAlbert Krewinkel <albert@zeitkraut.de> dateThu 6 Sep 2018, 20:57 (8 years ago) parentaac3d75
5 files changed+64−2
src/Text/Pandoc/Readers/Org/DocumentTree.hs+25−1 src/Text/Pandoc/Readers/Org/ExportSettings.hs+1−1 src/Text/Pandoc/Readers/Org/ParserState.hs+2 test/Tests/Readers/Org/Block/Header.hs+13 test/Tests/Readers/Org/Directive.hs+23
src/Text/Pandoc/Readers/Org/DocumentTree.hs+25−1
@@ -204,6 +204,7 @@ headlineToHeaderWithList hdln = do
204204 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
205205 header <- headlineToHeader hdln
206206 listElements <- mapM headlineToBlocks (headlineChildren hdln)
207+ planningBlock <- planningToBlock (headlinePlanning hdln)
207208 let listBlock = if null listElements
208209 then mempty
209210 else B.orderedList listElements
@@ -213,6 +214,7 @@ headlineToHeaderWithList hdln = do
213214 return . mconcat $
214215 [ headerText
215216 , headlineContents hdln
217+ , planningBlock
216218 , listBlock
217219 ]
218220 where
@@ -225,8 +227,9 @@ headlineToHeaderWithList hdln = do
225227headlineToHeaderWithContents :: Monad m => Headline -> OrgParser m Blocks
226228headlineToHeaderWithContents hdln = do
227229 header <- headlineToHeader hdln
230+ planningBlock <- planningToBlock (headlinePlanning hdln)
228231 childrenBlocks <- mconcat <$> mapM headlineToBlocks (headlineChildren hdln)
229− return $ header <> headlineContents hdln <> childrenBlocks
232+ return $ header <> planningBlock <> headlineContents hdln <> childrenBlocks
230233
231234headlineToHeader :: Monad m => Headline -> OrgParser m Blocks
232235headlineToHeader hdln = do
@@ -287,6 +290,27 @@ tagsToInlines tags =
287290tagSpan :: Tag -> Inlines -> Inlines
288291tagSpan t = B.spanWith ("", ["tag"], [("tag-name", fromTag t)])
289292
293+-- | Render planning info as a block iff the respective export setting is
294+-- enabled.
295+planningToBlock :: Monad m => PlanningInfo -> OrgParser m Blocks
296+planningToBlock planning = do
297+ includePlanning <- getExportSetting exportWithPlanning
298+ return $
299+ if includePlanning
300+ then B.plain . mconcat . intersperse B.space . filter (/= mempty) $
301+ [ datumInlines planningClosed "CLOSED"
302+ , datumInlines planningDeadline "DEADLINE"
303+ , datumInlines planningScheduled "SCHEDULED"
304+ ]
305+ else mempty
306+ where
307+ datumInlines field name =
308+ case field planning of
309+ Nothing -> mempty
310+ Just time -> B.strong (B.str name <> B.str ":")
311+ <> B.space
312+ <> B.emph (B.str time)
313+
290314-- | An Org timestamp, including repetition marks. TODO: improve
291315type Timestamp = String
292316
src/Text/Pandoc/Readers/Org/ExportSettings.hs+1−1
@@ -69,7 +69,7 @@ exportSetting = choice
6969 , integerSetting "H" (\val es -> es { exportHeadlineLevels = val })
7070 , ignoredSetting "inline"
7171 , ignoredSetting "num"
72− , ignoredSetting "p"
72+ , booleanSetting "p" (\val es -> es { exportWithPlanning = val })
7373 , ignoredSetting "pri"
7474 , ignoredSetting "prop"
7575 , ignoredSetting "stat"
src/Text/Pandoc/Readers/Org/ParserState.hs+2
@@ -260,6 +260,7 @@ data ExportSettings = ExportSettings
260260 , exportWithAuthor :: Bool -- ^ Include author in final meta-data
261261 , exportWithCreator :: Bool -- ^ Include creator in final meta-data
262262 , exportWithEmail :: Bool -- ^ Include email in final meta-data
263+ , exportWithPlanning :: Bool -- ^ Keep planning info after headlines
263264 , exportWithTags :: Bool -- ^ Keep tags as part of headlines
264265 , exportWithTodoKeywords :: Bool -- ^ Keep TODO keywords in headers
265266 }
@@ -280,6 +281,7 @@ defaultExportSettings = ExportSettings
280281 , exportWithAuthor = True
281282 , exportWithCreator = True
282283 , exportWithEmail = True
284+ , exportWithPlanning = False
283285 , exportWithTags = True
284286 , exportWithTodoKeywords = True
285287 }
test/Tests/Readers/Org/Block/Header.hs+13
@@ -205,5 +205,18 @@ tests =
205205 , " :END:"
206206 ] =?>
207207 headerWith ("look", [], []) 1 "important"
208+
209+ , "Planning info followed by test" =:
210+ T.unlines [ "* important "
211+ , " " <> T.unwords
212+ [ "CLOSED: [2018-09-05 Wed 13:58]"
213+ , "DEADLINE: <2018-09-17 Mon>"
214+ , "SCHEDULED: <2018-09-10 Mon>"
215+ ]
216+ , " :PROPERTIES:"
217+ , " :custom_id: look"
218+ , " :END:"
219+ ] =?>
220+ headerWith ("look", [], []) 1 "important"
208221 ]
209222 ]
test/Tests/Readers/Org/Directive.hs+23
@@ -150,6 +150,29 @@ tests =
150150 , "* Headline :hello:world:"
151151 ] =?>
152152 headerWith ("headline", [], mempty) 1 "Headline"
153+
154+ , testGroup "planning information"
155+ [ "include planning info after headlines" =:
156+ T.unlines [ "#+OPTIONS: p:t"
157+ , "* important"
158+ , " DEADLINE: <2018-10-01 Mon> SCHEDULED: <2018-09-15 Sat>"
159+ ] =?>
160+ mconcat [ headerWith ("important", mempty, mempty) 1 "important"
161+ , plain $ strong "DEADLINE:"
162+ <> space
163+ <> emph (str "<2018-10-01 Mon>")
164+ <> space
165+ <> strong "SCHEDULED:"
166+ <> space
167+ <> emph (str "<2018-09-15 Sat>")
168+ ]
169+
170+ , "empty planning info is not included" =:
171+ T.unlines [ "#+OPTIONS: p:t"
172+ , "* Wichtig"
173+ ] =?>
174+ headerWith ("wichtig", mempty, mempty) 1 "Wichtig"
175+ ]
153176 ]
154177
155178 , testGroup "Include"