aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
-rw-r--r--src/pandoc.hs50
4 files changed, 43 insertions, 33 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)
diff --git a/src/pandoc.hs b/src/pandoc.hs
index 406469598..dfba4093d 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -52,7 +52,6 @@ import qualified Control.Exception as E
import Control.Exception.Extensible ( throwIO )
import qualified Text.Pandoc.UTF8 as UTF8
import qualified Text.CSL as CSL
-import Text.Pandoc.Biblio
import Control.Monad (when, unless, liftM)
import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
import Network.URI (parseURI, isURI, URI(..))
@@ -924,6 +923,24 @@ main = do
reffiles >>=
return . map unescapeRefId . concat
+ mbsty <- if citeMethod == Citeproc && not (null refs)
+ then do
+ csl <- CSL.parseCSL =<<
+ case mbCsl of
+ Nothing -> readDataFile datadir "default.csl"
+ Just cslfile -> do
+ exists <- doesFileExist cslfile
+ if exists
+ then UTF8.readFile cslfile
+ else do
+ csldir <- getAppUserDataDirectory "csl"
+ print csldir
+ readDataFile datadir (replaceDirectory
+ (replaceExtension cslfile "csl") csldir)
+ abbrevs <- maybe (return []) CSL.readJsonAbbrevFile cslabbrevs
+ return $ Just csl { CSL.styleAbbrevs = abbrevs }
+ else return Nothing
+
let sourceDir = if null sources
then "."
else takeDirectory (head sources)
@@ -935,7 +952,8 @@ main = do
, readerColumns = columns
, readerTabStop = tabStop
, readerOldDashes = oldDashes
- , readerCitations = map CSL.refId refs
+ , readerReferences = refs
+ , readerCitationStyle = mbsty
, readerIndentedCodeClasses = codeBlockClasses
, readerApplyMacros = not laTeXOutput
}
@@ -1004,26 +1022,6 @@ main = do
then bottomUpM rtfEmbedImage doc0
else return doc0
- doc2 <- do
- if citeMethod == Citeproc && not (null refs)
- then do
- csl <- CSL.parseCSL =<<
- case mbCsl of
- Nothing -> readDataFile datadir "default.csl"
- Just cslfile -> do
- exists <- doesFileExist cslfile
- if exists
- then UTF8.readFile cslfile
- else do
- csldir <- getAppUserDataDirectory "csl"
- print csldir
- readDataFile datadir (replaceDirectory
- (replaceExtension cslfile "csl") csldir)
- abbrevs <- maybe (return []) CSL.readJsonAbbrevFile cslabbrevs
- let csl' = csl { CSL.styleAbbrevs = abbrevs }
- return $ processBiblio csl' refs doc1
- else return doc1
-
let writeBinary :: B.ByteString -> IO ()
writeBinary = B.writeFile (UTF8.encodePath outputFile)
@@ -1033,15 +1031,15 @@ main = do
case getWriter writerName' of
Left e -> err 9 e
- Right (IOStringWriter f) -> f writerOptions doc2 >>= writerFn outputFile
- Right (IOByteStringWriter f) -> f writerOptions doc2 >>= writeBinary
+ Right (IOStringWriter f) -> f writerOptions doc1 >>= writerFn outputFile
+ Right (IOByteStringWriter f) -> f writerOptions doc1 >>= writeBinary
Right (PureStringWriter f)
| pdfOutput -> do
- res <- tex2pdf latexEngine $ f writerOptions doc2
+ res <- tex2pdf latexEngine $ f writerOptions doc1
case res of
Right pdf -> writeBinary pdf
Left err' -> err 43 $ UTF8.toStringLazy err'
- | otherwise -> selfcontain (f writerOptions doc2 ++
+ | otherwise -> selfcontain (f writerOptions doc1 ++
['\n' | not standalone'])
>>= writerFn outputFile . handleEntities
where htmlFormat = writerName' `elem`