aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-10-13 11:33:55 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-10-13 11:33:55 -0700
commitb5dd06d30374edb7a2756ba58019d7f21f3bbfe5 (patch)
treec1ab0bb0361cfd9f65a9bed9583b845248a9119a /src/Text/Pandoc
parent9a77a3f15ba4201a0b617a814b73d2eb9cad11fc (diff)
downloadpandoc-b5dd06d30374edb7a2756ba58019d7f21f3bbfe5.tar.gz
Moved bibliography processing into readers.
Previously this was done in src/pandoc.hs, which made it difficult for library users. * Removed readerCitations in ReaderOptions. * Added readerReferences and readerCitationStyle to ReaderOptions. * Moved use of processBiblio from main program to the markdown and LaTeX readers.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Options.hs9
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs6
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs11
3 files changed, 19 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs
index 834810859..27661ecd4 100644
--- a/src/Text/Pandoc/Options.hs
+++ b/src/Text/Pandoc/Options.hs
@@ -44,6 +44,7 @@ import Data.Set (Set)
import qualified Data.Set as Set
import Data.Default
import Text.Pandoc.Highlighting (Style, pygments)
+import qualified Text.CSL as CSL
-- | Individually selectable syntax extensions.
data Extension =
@@ -141,11 +142,12 @@ data ReaderOptions = ReaderOptions{
, readerOldDashes :: Bool -- ^ Use pandoc <= 1.8.2.1 behavior
-- in parsing dashes; -- is em-dash;
-- - before numerial is en-dash
- , readerCitations :: [String] -- ^ List of available citations
+ , readerReferences :: [CSL.Reference] -- ^ Bibliographic references
+ , readerCitationStyle :: Maybe CSL.Style -- ^ Citation style
, readerApplyMacros :: Bool -- ^ Apply macros to TeX math
, readerIndentedCodeClasses :: [String] -- ^ Default classes for
-- indented code blocks
-} deriving (Show, Read)
+} deriving (Show {- TODO need update in citeproc-hs , Read -})
instance Default ReaderOptions
where def = ReaderOptions{
@@ -157,7 +159,8 @@ instance Default ReaderOptions
, readerColumns = 80
, readerTabStop = 4
, readerOldDashes = False
- , readerCitations = []
+ , readerReferences = []
+ , readerCitationStyle = Nothing
, readerApplyMacros = True
, readerIndentedCodeClasses = []
}
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index bdbf8f100..458c114ff 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -36,6 +36,7 @@ module Text.Pandoc.Readers.LaTeX ( readLaTeX,
import Text.Pandoc.Definition
import Text.Pandoc.Shared
import Text.Pandoc.Options
+import Text.Pandoc.Biblio (processBiblio)
import Text.Pandoc.Parsing hiding ((<|>), many, optional, space)
import qualified Text.Pandoc.UTF8 as UTF8
import Data.Char ( chr, ord )
@@ -63,7 +64,10 @@ parseLaTeX = do
let title' = stateTitle st
let authors' = stateAuthors st
let date' = stateDate st
- return $ Pandoc (Meta title' authors' date') $ toList bs
+ refs <- getOption readerReferences
+ mbsty <- getOption readerCitationStyle
+ return $ processBiblio mbsty refs
+ $ Pandoc (Meta title' authors' date') $ toList bs
type LP = Parser [Char] ParserState
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 7ac68c856..ab8069a75 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -45,6 +45,8 @@ import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
isTextTag, isCommentTag )
import Text.Pandoc.XML ( fromEntities )
+import Text.Pandoc.Biblio (processBiblio)
+import qualified Text.CSL as CSL
import Data.Monoid (mconcat, mempty)
import Control.Applicative ((<$>), (<*), (*>), (<$))
import Control.Monad
@@ -216,7 +218,10 @@ parseMarkdown = do
(title, authors, date) <- option (mempty,return [],mempty) titleBlock
blocks <- parseBlocks
st <- getState
- return $ B.setTitle (runF title st)
+ mbsty <- getOption readerCitationStyle
+ refs <- getOption readerReferences
+ return $ processBiblio mbsty refs
+ $ B.setTitle (runF title st)
$ B.setAuthors (runF authors st)
$ B.setDate (runF date st)
$ B.doc $ runF blocks st
@@ -1542,7 +1547,7 @@ rawHtmlInline = do
cite :: Parser [Char] ParserState (F Inlines)
cite = do
guardEnabled Ext_citations
- getOption readerCitations >>= guard . not . null
+ getOption readerReferences >>= guard . not . null
citations <- textualCite <|> normalCite
return $ flip B.cite mempty <$> citations
@@ -1591,7 +1596,7 @@ citeKey = try $ do
let internal p = try $ p >>~ lookAhead (letter <|> digit)
rest <- many $ letter <|> digit <|> internal (oneOf ":.#$%&-_?<>~")
let key = first:rest
- citations' <- getOption readerCitations
+ citations' <- map CSL.refId <$> getOption readerReferences
guard $ key `elem` citations'
return (suppress_author, key)