diff options
| author | Juliusz Gonera <juliusz.gonera@gmail.com> | 2015-08-15 07:54:38 +0200 | 
|---|---|---|
| committer | Juliusz Gonera <juliusz.gonera@gmail.com> | 2015-08-15 07:57:48 +0200 | 
| commit | f1c87ed16452c96426864a83beb036a4d09d1988 (patch) | |
| tree | 448bd35799ecba0b20815e619c031de409f11b11 /src/Text | |
| parent | aa08b4cd677b975cf63c451a3414df447e31b55c (diff) | |
| download | pandoc-f1c87ed16452c96426864a83beb036a4d09d1988.tar.gz | |
Org reader: add auto identifiers if not present on headers
Refs #2354
This should also fix the table of contents (--toc) when generating a html file
from org input
Diffstat (limited to 'src/Text')
| -rw-r--r-- | src/Text/Pandoc.hs | 3 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/Org.hs | 17 | 
2 files changed, 18 insertions, 2 deletions
diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs index a0a9de1b2..d7311d978 100644 --- a/src/Text/Pandoc.hs +++ b/src/Text/Pandoc.hs @@ -320,7 +320,8 @@ getDefaultExtensions "markdown_mmd" = multimarkdownExtensions  getDefaultExtensions "markdown_github" = githubMarkdownExtensions  getDefaultExtensions "markdown"        = pandocExtensions  getDefaultExtensions "plain"           = plainExtensions -getDefaultExtensions "org"             = Set.fromList [Ext_citations] +getDefaultExtensions "org"             = Set.fromList [Ext_citations, +                                                       Ext_auto_identifiers]  getDefaultExtensions "textile"         = Set.fromList [Ext_auto_identifiers]  getDefaultExtensions "html"            = Set.fromList [Ext_auto_identifiers,                                                         Ext_native_divs, diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs index 980f63504..55ac92bcb 100644 --- a/src/Text/Pandoc/Readers/Org.hs +++ b/src/Text/Pandoc/Readers/Org.hs @@ -70,6 +70,14 @@ data OrgParserLocal = OrgParserLocal { orgLocalQuoteContext :: QuoteContext }  type OrgParser = ParserT [Char] OrgParserState (Reader OrgParserLocal) +instance HasIdentifierList OrgParserState where +  extractIdentifierList = orgStateIdentifiers +  updateIdentifierList f s = s{ orgStateIdentifiers = f (orgStateIdentifiers s) } + +instance HasHeaderMap OrgParserState where +  extractHeaderMap = orgStateHeaderMap +  updateHeaderMap  f s = s{ orgStateHeaderMap = f (orgStateHeaderMap s) } +  parseOrg :: OrgParser Pandoc  parseOrg = do    blocks' <- parseBlocks @@ -135,6 +143,8 @@ data OrgParserState = OrgParserState                        , orgStateMeta                 :: Meta                        , orgStateMeta'                :: F Meta                        , orgStateNotes'               :: OrgNoteTable +                      , orgStateIdentifiers          :: [String] +                      , orgStateHeaderMap            :: M.Map Inlines String                        }  instance Default OrgParserLocal where @@ -174,6 +184,8 @@ defaultOrgParserState = OrgParserState                          , orgStateMeta = nullMeta                          , orgStateMeta' = return nullMeta                          , orgStateNotes' = [] +                        , orgStateIdentifiers = [] +                        , orgStateHeaderMap = M.empty                          }  recordAnchorId :: String -> OrgParser () @@ -668,7 +680,10 @@ header = try $ do    title <- manyTill inline (lookAhead headerEnd)    tags <- headerEnd    let inlns = trimInlinesF . mconcat $ title <> map tagToInlineF tags -  return $ B.header level <$> inlns +  st <- getState +  let inlines = runF inlns st +  attr <- registerHeader nullAttr inlines +  return $ pure (B.headerWith attr level inlines)   where     tagToInlineF :: String -> F Inlines     tagToInlineF t = return $ B.spanWith ("", ["tag"], [("data-tag-name", t)]) mempty  | 
