summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2015-05-20 18:01:03 +0200
committerAlbert Krewinkel <albert@zeitkraut.de>2015-05-23 14:06:32 +0200
commitd8e4a8bc10bfd97d81ec0166fd786742fe3a2370 (patch)
tree780064d4a76b47172af8b07d45cd5437de36734a /src
parentd5f367d04b9b7830ead3e3298aafe3987e55c697 (diff)
Org reader: put header tags into empty spans
Org mode allows headers to be tagged: ``` org-mode * Headline :TAG1:TAG2: ``` Instead of being interpreted as part of the headline, the tags are now put into the attributes of empty spans. Spans without textual content won't be visible by default, but they are detectable by filters. They can also be styled using CSS when written as HTML. This fixes #2160.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Org.hs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs
index 83fb48764..dd8da30c2 100644
--- a/src/Text/Pandoc/Readers/Org.hs
+++ b/src/Text/Pandoc/Readers/Org.hs
@@ -652,8 +652,25 @@ parseFormat = try $ do
header :: OrgParser (F Blocks)
header = try $ do
level <- headerStart
- title <- inlinesTillNewline
- return $ B.header level <$> title
+ title <- manyTill inline (lookAhead headerEnd)
+ tags <- headerEnd
+ let inlns = trimInlinesF . mconcat $ title <> map tagToInlineF tags
+ return $ B.header level <$> inlns
+ where
+ tagToInlineF :: String -> F Inlines
+ tagToInlineF t = return $ B.spanWith ("", ["tag"], [("data-tag-name", t)]) mempty
+
+headerEnd :: OrgParser [String]
+headerEnd = option [] headerTags <* newline
+
+headerTags :: OrgParser [String]
+headerTags = try $
+ skipSpaces
+ *> char ':'
+ *> many1 tag
+ <* skipSpaces
+ where tag = many1 (alphaNum <|> oneOf "@%#_")
+ <* char ':'
headerStart :: OrgParser Int
headerStart = try $