pandoc-citeproc 0.8.0.1 → 0.8.1
raw patch · 15 files changed
+567/−67 lines, 15 filesdep +unordered-containers
Dependencies added: unordered-containers
Files
- changelog +22/−0
- man/man1/pandoc-citeproc.1 +2/−2
- pandoc-citeproc.cabal +2/−1
- src/Text/CSL/Eval.hs +1/−1
- src/Text/CSL/Eval/Date.hs +4/−1
- src/Text/CSL/Eval/Output.hs +6/−1
- src/Text/CSL/Input/Bibtex.hs +403/−37
- src/Text/CSL/Pandoc.hs +23/−12
- src/Text/CSL/Parser.hs +7/−4
- src/Text/CSL/Reference.hs +33/−1
- src/Text/CSL/Util.hs +47/−3
- tests/biblio2yaml/kastenholz.biblatex +2/−2
- tests/biblio2yaml/sigfridsson.biblatex +2/−2
- tests/issue175.expected.native +7/−0
- tests/issue175.in.native +6/−0
changelog view
@@ -1,3 +1,25 @@+pandoc-citeproc (0.8.1)++ * Improved performance in bibtex cross-reference resolution (#190).+ * Take 'form' for date-part elements from date if not specified (#116).+ Previously if the 'form' were unspecified in a date-part+ element, it would go to the default 'long', even if the+ date as a whole was 'numeric'.+ * Transform only uppercase ASCII letters in titlecase transform.+ This helps us pass one more citeproc test case.+ * Cleaned up locator parsing code.+ * Allow roman numeral locators (#173.+ * Fixed missing dash between months in date ranges (#175).+ * Fixed `strip-periods` (#185).+ * Parse supplementary fields in CSL JSON "note" fields (#94).+ * Support more biblatex markup in converting biblatex bibliographies:+ `mkbibemph`, `mkbibitalic`, `mkbibbold`, `mkbibparens`, `mkbibbrackets`,+ `autocap` (Nick Bart, #26). Treat reviews as articles.+ * Add biblatex keys for additional languages (Nick Bart).+ * Use HTTPS for DOI resolver (Andrew Dunning).+ * Add biblatex keys for additional languages (Nick Bart):+ ca-AD, da-DK, es-ES, fi-FI, it-IT, nl-NL, pl-PL, pt-PT, pt-BR, sv-SE+ pandoc-citeproc (0.8.0.1) * Allow aeson 0.10.x (Felix Yan).
man/man1/pandoc-citeproc.1 view
@@ -1,8 +1,8 @@ .\"t-.\" Automatically generated by Pandoc 1.15.1+.\" Automatically generated by Pandoc 1.15.1.1 .\" .hy-.TH "pandoc\-citeproc" "1" "2015-10-13" "" ""+.TH "pandoc\-citeproc" "1" "2015-11-12" "pandoc-citeproc 0.8.1" "" .SH NAME .PP pandoc\-citeproc \- filter to resolve citations in a pandoc document.
pandoc-citeproc.cabal view
@@ -1,5 +1,5 @@ name: pandoc-citeproc-version: 0.8.0.1+version: 0.8.1 cabal-version: >= 1.12 synopsis: Supports using pandoc with citeproc @@ -96,6 +96,7 @@ bytestring, filepath, pandoc-types >= 1.12.3, tagsoup, aeson >= 0.7 && < 0.11, text, vector, xml-conduit >= 1.2 && < 1.4,+ unordered-containers >= 0.2 && < 0.3, data-default, setenv >= 0.1 && < 0.2, split, yaml >= 0.8.8.7, pandoc >= 1.13
src/Text/CSL/Eval.hs view
@@ -216,7 +216,7 @@ "doi" -> do d <- getStringVar "doi" let (prefixPart, linkPart) = T.breakOn (T.pack "http") (T.pack (prefix fm)) let u = if T.null linkPart- then "http://doi.org/" ++ d+ then "https://doi.org/" ++ d else T.unpack linkPart ++ d if null d then return []
src/Text/CSL/Eval/Date.hs view
@@ -99,7 +99,10 @@ diffDate (RefDate ya ma sa da _ _) (RefDate yb mb sb db _ _) = case () of _ | ya /= yb -> ["year","month","day"]- | ma /= mb -> ["month","day"]+ | ma /= mb ->+ if da == mempty && db == mempty+ then ["month"]+ else ["month","day"] | da /= db -> ["day"] | sa /= sb -> ["month"] | otherwise -> ["year","month","day"]
src/Text/CSL/Eval/Output.hs view
@@ -130,7 +130,8 @@ _ -> Formatted [] addFormatting :: Formatting -> Formatted -> Formatted-addFormatting f = addLink . addSuffix . pref . quote . font . text_case+addFormatting f =+ addLink . addSuffix . pref . quote . font . text_case . strip_periods where addLink i = case hyperlink f of "" -> i url -> Formatted [Link (unFormatted i) (url, "")]@@ -143,6 +144,10 @@ , case lastInline (unFormatted i) of {(c:_) | isPunct c -> True; _ -> False} = i <> fromString (tail $ suffix f) | otherwise = i <> fromString (suffix f)++ strip_periods (Formatted ils) = Formatted (walk removePeriod ils)+ removePeriod (Str xs) | stripPeriods f = Str (filter (/='.') xs)+ removePeriod x = x quote (Formatted []) = Formatted [] quote (Formatted ils) =
src/Text/CSL/Input/Bibtex.hs view
@@ -64,7 +64,14 @@ where (command', contents') = break (=='{') xs command = trim command' contents = drop 1 $ reverse $ drop 1 $ reverse contents'- f "mkbibquote" ils = [Quoted DoubleQuote ils]+ f "mkbibquote" ils = [Quoted DoubleQuote ils]+ f "mkbibemph" ils = [Emph ils]+ f "mkbibitalic" ils = [Emph ils] -- TODO: italic/=emph+ f "mkbibbold" ils = [Strong ils]+ f "mkbibparens" ils = [Str "("] ++ ils ++ [Str ")"] -- TODO: ...+ f "mkbibbrackets" ils = [Str "["] ++ ils ++ [Str "]"] -- TODO: ...+ -- ... both should be nestable & should work in year fields+ f "autocap" ils = ils -- TODO: should work in year fields f "textnormal" ils = [Span ("",["nodecor"],[]) ils] f "bibstring" [Str s] = [Str $ resolveKey' lang s] f _ ils = [Span nullAttr ils]@@ -236,8 +243,8 @@ return (k',v) resolveCrossRef :: Bool -> [Item] -> Item -> Item-resolveCrossRef isBibtex entries entry = foldl go entry (fields entry)- where go entry' (key, val) =+resolveCrossRef isBibtex entries entry = foldr go entry (fields entry)+ where go (key, val) entry' = if key == "crossref" || key == "xdata" then entry'{ fields = fields entry' ++ getXrefFields isBibtex entry entries val }@@ -333,7 +340,119 @@ where go (Str s) = Str $ resolveKey' lang s go x = x +-- biblatex localization keys, from files at+-- http://github.com/plk/biblatex/tree/master/tex/latex/biblatex/lbx+-- Some keys missing in these were added from csl locale files at+-- http://github.com/citation-style-language/locales -- labeled "csl" resolveKey' :: Lang -> String -> String+resolveKey' (Lang "ca" "AD") k =+ case map toLower k of+ "inpreparation" -> "en preparació"+ "submitted" -> "enviat"+ "forthcoming" -> "disponible en breu"+ "inpress" -> "a impremta"+ "prepublished" -> "pre-publicat"+ "mathesis" -> "tesi de màster"+ "phdthesis" -> "tesi doctoral"+ "candthesis" -> "tesi de candidatura"+ "techreport" -> "informe tècnic"+ "resreport" -> "informe de recerca"+ "software" -> "programari"+ "datacd" -> "CD de dades"+ "audiocd" -> "CD d’àudio"+ "patent" -> "patent"+ "patentde" -> "patent alemana"+ "patenteu" -> "patent europea"+ "patentfr" -> "patent francesa"+ "patentuk" -> "patent britànica"+ "patentus" -> "patent estatunidenca"+ "patreq" -> "soŀlicitud de patent"+ "patreqde" -> "soŀlicitud de patent alemana"+ "patreqeu" -> "soŀlicitud de patent europea"+ "patreqfr" -> "soŀlicitud de patent francesa"+ "patrequk" -> "soŀlicitud de patent britànica"+ "patrequs" -> "soŀlicitud de patent estatunidenca"+ "countryde" -> "Alemanya"+ "countryeu" -> "Unió Europea"+ "countryep" -> "Unió Europea"+ "countryfr" -> "França"+ "countryuk" -> "Regne Unit"+ "countryus" -> "Estats Units d’Amèrica"+ "newseries" -> "sèrie nova"+ "oldseries" -> "sèrie antiga"+ _ -> k+resolveKey' (Lang "da" "DK") k =+ case map toLower k of+ -- "inpreparation" -> "" -- missing+ -- "submitted" -> "" -- missing+ "forthcoming" -> "kommende" -- csl+ "inpress" -> "i tryk" -- csl+ -- "prepublished" -> "" -- missing+ "mathesis" -> "speciale"+ "phdthesis" -> "ph.d.-afhandling"+ "candthesis" -> "kandidatafhandling"+ "techreport" -> "teknisk rapport"+ "resreport" -> "forskningsrapport"+ "software" -> "software"+ "datacd" -> "data-cd"+ "audiocd" -> "lyd-cd"+ "patent" -> "patent"+ "patentde" -> "tysk patent"+ "patenteu" -> "europæisk patent"+ "patentfr" -> "fransk patent"+ "patentuk" -> "britisk patent"+ "patentus" -> "amerikansk patent"+ "patreq" -> "ansøgning om patent"+ "patreqde" -> "ansøgning om tysk patent"+ "patreqeu" -> "ansøgning om europæisk patent"+ "patreqfr" -> "ansøgning om fransk patent"+ "patrequk" -> "ansøgning om britisk patent"+ "patrequs" -> "ansøgning om amerikansk patent"+ "countryde" -> "Tyskland"+ "countryeu" -> "Europæiske Union"+ "countryep" -> "Europæiske Union"+ "countryfr" -> "Frankrig"+ "countryuk" -> "Storbritanien"+ "countryus" -> "USA"+ "newseries" -> "ny serie"+ "oldseries" -> "gammel serie"+ _ -> k+resolveKey' (Lang "de" "DE") k =+ case map toLower k of+ "inpreparation" -> "in Vorbereitung"+ "submitted" -> "eingereicht"+ "forthcoming" -> "im Erscheinen"+ "inpress" -> "im Druck"+ "prepublished" -> "Vorveröffentlichung"+ "mathesis" -> "Magisterarbeit"+ "phdthesis" -> "Dissertation"+ -- "candthesis" -> "" -- missing+ "techreport" -> "Technischer Bericht"+ "resreport" -> "Forschungsbericht"+ "software" -> "Computer-Software"+ "datacd" -> "CD-ROM"+ "audiocd" -> "Audio-CD"+ "patent" -> "Patent"+ "patentde" -> "deutsches Patent"+ "patenteu" -> "europäisches Patent"+ "patentfr" -> "französisches Patent"+ "patentuk" -> "britisches Patent"+ "patentus" -> "US-Patent"+ "patreq" -> "Patentanmeldung"+ "patreqde" -> "deutsche Patentanmeldung"+ "patreqeu" -> "europäische Patentanmeldung"+ "patreqfr" -> "französische Patentanmeldung"+ "patrequk" -> "britische Patentanmeldung"+ "patrequs" -> "US-Patentanmeldung"+ "countryde" -> "Deutschland"+ "countryeu" -> "Europäische Union"+ "countryep" -> "Europäische Union"+ "countryfr" -> "Frankreich"+ "countryuk" -> "Großbritannien"+ "countryus" -> "USA"+ "newseries" -> "neue Folge"+ "oldseries" -> "alte Folge"+ _ -> k resolveKey' (Lang "en" "US") k = case map toLower k of "audiocd" -> "audio CD"@@ -382,42 +501,79 @@ "techreport" -> "technical report" "volume" -> "vol." _ -> k-resolveKey' (Lang "de" "DE") k =+resolveKey' (Lang "es" "ES") k = case map toLower k of- "inpreparation" -> "in Vorbereitung"- "submitted" -> "eingereicht"- "forthcoming" -> "im Erscheinen"- "inpress" -> "im Druck"- "prepublished" -> "Vorveröffentlichung"- "mathesis" -> "Magisterarbeit"- "phdthesis" -> "Dissertation"+ -- "inpreparation" -> "" -- missing+ -- "submitted" -> "" -- missing+ "forthcoming" -> "previsto" -- csl+ "inpress" -> "en imprenta" -- csl+ -- "prepublished" -> "" -- missing+ "mathesis" -> "Tesis de licenciatura"+ "phdthesis" -> "Tesis doctoral" -- "candthesis" -> "" -- missing- "techreport" -> "Technischer Bericht"- "resreport" -> "Forschungsbericht"- "software" -> "Computer-Software"- "datacd" -> "CD-ROM"- "audiocd" -> "Audio-CD"- "patent" -> "Patent"- "patentde" -> "deutsches Patent"- "patenteu" -> "europäisches Patent"- "patentfr" -> "französisches Patent"- "patentuk" -> "britisches Patent"- "patentus" -> "US-Patent"- "patreq" -> "Patentanmeldung"- "patreqde" -> "deutsche Patentanmeldung"- "patreqeu" -> "europäische Patentanmeldung"- "patreqfr" -> "französische Patentanmeldung"- "patrequk" -> "britische Patentanmeldung"- "patrequs" -> "US-Patentanmeldung"- "countryde" -> "Deutschland"- "countryeu" -> "Europäische Union"- "countryep" -> "Europäische Union"- "countryfr" -> "Frankreich"- "countryuk" -> "Großbritannien"- "countryus" -> "USA"- "newseries" -> "neue Folge"- "oldseries" -> "alte Folge"+ "techreport" -> "informe técnico"+ -- "resreport" -> "" -- missing+ -- "software" -> "" -- missing+ -- "datacd" -> "" -- missing+ -- "audiocd" -> "" -- missing+ "patent" -> "patente"+ "patentde" -> "patente alemana"+ "patenteu" -> "patente europea"+ "patentfr" -> "patente francesa"+ "patentuk" -> "patente británica"+ "patentus" -> "patente americana"+ "patreq" -> "solicitud de patente"+ "patreqde" -> "solicitud de patente alemana"+ "patreqeu" -> "solicitud de patente europea"+ "patreqfr" -> "solicitud de patente francesa"+ "patrequk" -> "solicitud de patente británica"+ "patrequs" -> "solicitud de patente americana"+ "countryde" -> "Alemania"+ "countryeu" -> "Unión Europea"+ "countryep" -> "Unión Europea"+ "countryfr" -> "Francia"+ "countryuk" -> "Reino Unido"+ "countryus" -> "Estados Unidos de América"+ "newseries" -> "nueva época"+ "oldseries" -> "antigua época" _ -> k+resolveKey' (Lang "fi" "FI") k =+ case map toLower k of+ -- "inpreparation" -> "" -- missing+ -- "submitted" -> "" -- missing+ "forthcoming" -> "tulossa" -- csl+ "inpress" -> "painossa" -- csl+ -- "prepublished" -> "" -- missing+ "mathesis" -> "tutkielma"+ "phdthesis" -> "tohtorinväitöskirja"+ "candthesis" -> "kandidat"+ "techreport" -> "tekninen raportti"+ "resreport" -> "tutkimusraportti"+ "software" -> "ohjelmisto"+ "datacd" -> "data-CD"+ "audiocd" -> "ääni-CD"+ "patent" -> "patentti"+ "patentde" -> "saksalainen patentti"+ "patenteu" -> "Euroopan Unionin patentti"+ "patentfr" -> "ranskalainen patentti"+ "patentuk" -> "englantilainen patentti"+ "patentus" -> "yhdysvaltalainen patentti"+ "patreq" -> "patenttihakemus"+ "patreqde" -> "saksalainen patenttihakemus"+ "patreqeu" -> "Euroopan Unionin patenttihakemus"+ "patreqfr" -> "ranskalainen patenttihakemus"+ "patrequk" -> "englantilainen patenttihakemus"+ "patrequs" -> "yhdysvaltalainen patenttihakemus"+ "countryde" -> "Saksa"+ "countryeu" -> "Euroopan Unioni"+ "countryep" -> "Euroopan Unioni"+ "countryfr" -> "Ranska"+ "countryuk" -> "Iso-Britannia"+ "countryus" -> "Yhdysvallat"+ "newseries" -> "uusi sarja"+ "oldseries" -> "vanha sarja"+ _ -> k+ resolveKey' (Lang "fr" "FR") k = case map toLower k of "inpreparation" -> "en préparation"@@ -454,6 +610,216 @@ "newseries" -> "nouvelle série" "oldseries" -> "ancienne série" _ -> k+resolveKey' (Lang "it" "IT") k =+ case map toLower k of+ -- "inpreparation" -> "" -- missing+ -- "submitted" -> "" -- missing+ "forthcoming" -> "futuro" -- csl+ "inpress" -> "in stampa"+ -- "prepublished" -> "" -- missing+ "mathesis" -> "tesi di laurea magistrale"+ "phdthesis" -> "tesi di dottorato"+ -- "candthesis" -> "" -- missing+ "techreport" -> "rapporto tecnico"+ "resreport" -> "rapporto di ricerca"+ -- "software" -> "" -- missing+ -- "datacd" -> "" -- missing+ -- "audiocd" -> "" -- missing+ "patent" -> "brevetto"+ "patentde" -> "brevetto tedesco"+ "patenteu" -> "brevetto europeo"+ "patentfr" -> "brevetto francese"+ "patentuk" -> "brevetto britannico"+ "patentus" -> "brevetto americano"+ "patreq" -> "brevetto richiesto"+ "patreqde" -> "brevetto tedesco richiesto"+ "patreqeu" -> "brevetto europeo richiesto"+ "patreqfr" -> "brevetto francese richiesto"+ "patrequk" -> "brevetto britannico richiesto"+ "patrequs" -> "brevetto U.S.A. richiesto"+ "countryde" -> "Germania"+ "countryeu" -> "Unione Europea"+ "countryep" -> "Unione Europea"+ "countryfr" -> "Francia"+ "countryuk" -> "Regno Unito"+ "countryus" -> "Stati Uniti d’America"+ "newseries" -> "nuova serie"+ "oldseries" -> "vecchia serie"+ _ -> k+resolveKey' (Lang "nl" "NL") k =+ case map toLower k of+ "inpreparation" -> "in voorbereiding"+ "submitted" -> "ingediend"+ "forthcoming" -> "onderweg"+ "inpress" -> "in druk"+ "prepublished" -> "voorpublicatie"+ "mathesis" -> "masterscriptie"+ "phdthesis" -> "proefschrift"+ -- "candthesis" -> "" -- missing+ "techreport" -> "technisch rapport"+ "resreport" -> "onderzoeksrapport"+ "software" -> "computersoftware"+ "datacd" -> "cd-rom"+ "audiocd" -> "audio-cd"+ "patent" -> "patent"+ "patentde" -> "Duits patent"+ "patenteu" -> "Europees patent"+ "patentfr" -> "Frans patent"+ "patentuk" -> "Brits patent"+ "patentus" -> "Amerikaans patent"+ "patreq" -> "patentaanvraag"+ "patreqde" -> "Duitse patentaanvraag"+ "patreqeu" -> "Europese patentaanvraag"+ "patreqfr" -> "Franse patentaanvraag"+ "patrequk" -> "Britse patentaanvraag"+ "patrequs" -> "Amerikaanse patentaanvraag"+ "countryde" -> "Duitsland"+ "countryeu" -> "Europese Unie"+ "countryep" -> "Europese Unie"+ "countryfr" -> "Frankrijk"+ "countryuk" -> "Verenigd Koninkrijk"+ "countryus" -> "Verenigde Staten van Amerika"+ "newseries" -> "nieuwe reeks"+ "oldseries" -> "oude reeks"+ _ -> k+resolveKey' (Lang "pl" "PL") k =+ case map toLower k of+ "inpreparation" -> "przygotowanie"+ "submitted" -> "prezentacja"+ "forthcoming" -> "przygotowanie"+ "inpress" -> "wydrukowane"+ "prepublished" -> "przedwydanie"+ "mathesis" -> "praca magisterska"+ "phdthesis" -> "praca doktorska"+ "techreport" -> "sprawozdanie techniczne"+ "resreport" -> "sprawozdanie naukowe"+ "software" -> "oprogramowanie"+ "datacd" -> "CD-ROM"+ "audiocd" -> "audio CD"+ "patent" -> "patent"+ "patentde" -> "patent Niemiec"+ "patenteu" -> "patent Europy"+ "patentfr" -> "patent Francji"+ "patentuk" -> "patent Wielkiej Brytanji"+ "patentus" -> "patent USA"+ "patreq" -> "podanie na patent"+ "patreqeu" -> "podanie na patent Europy"+ "patrequs" -> "podanie na patent USA"+ "countryde" -> "Niemcy"+ "countryeu" -> "Unia Europejska"+ "countryep" -> "Unia Europejska"+ "countryfr" -> "Francja"+ "countryuk" -> "Wielka Brytania"+ "countryus" -> "Stany Zjednoczone Ameryki"+ "newseries" -> "nowa serja"+ "oldseries" -> "stara serja"+ _ -> k+resolveKey' (Lang "pt" "PT") k =+ case map toLower k of+ -- "candthesis" -> "" -- missing+ "techreport" -> "relatório técnico"+ "resreport" -> "relatório de pesquisa"+ "software" -> "software"+ "datacd" -> "CD-ROM"+ "patent" -> "patente"+ "patentde" -> "patente alemã"+ "patenteu" -> "patente européia"+ "patentfr" -> "patente francesa"+ "patentuk" -> "patente britânica"+ "patentus" -> "patente americana"+ "patreq" -> "pedido de patente"+ "patreqde" -> "pedido de patente alemã"+ "patreqeu" -> "pedido de patente européia"+ "patreqfr" -> "pedido de patente francesa"+ "patrequk" -> "pedido de patente britânica"+ "patrequs" -> "pedido de patente americana"+ "countryde" -> "Alemanha"+ "countryeu" -> "União Europeia"+ "countryep" -> "União Europeia"+ "countryfr" -> "França"+ "countryuk" -> "Reino Unido"+ "countryus" -> "Estados Unidos da América"+ "newseries" -> "nova série"+ "oldseries" -> "série antiga"+ -- "inpreparation" -> "" -- missing+ "forthcoming" -> "a publicar" -- csl+ "inpress" -> "na imprensa"+ -- "prepublished" -> "" -- missing+ "mathesis" -> "tese de mestrado"+ "phdthesis" -> "tese de doutoramento"+ "audiocd" -> "CD áudio"+ _ -> k+resolveKey' (Lang "pt" "BR") k =+ case map toLower k of + -- "candthesis" -> "" -- missing+ "techreport" -> "relatório técnico"+ "resreport" -> "relatório de pesquisa"+ "software" -> "software"+ "datacd" -> "CD-ROM"+ "patent" -> "patente"+ "patentde" -> "patente alemã"+ "patenteu" -> "patente européia"+ "patentfr" -> "patente francesa"+ "patentuk" -> "patente britânica"+ "patentus" -> "patente americana"+ "patreq" -> "pedido de patente"+ "patreqde" -> "pedido de patente alemã"+ "patreqeu" -> "pedido de patente européia"+ "patreqfr" -> "pedido de patente francesa"+ "patrequk" -> "pedido de patente britânica"+ "patrequs" -> "pedido de patente americana"+ "countryde" -> "Alemanha"+ "countryeu" -> "União Europeia"+ "countryep" -> "União Europeia"+ "countryfr" -> "França"+ "countryuk" -> "Reino Unido"+ "countryus" -> "Estados Unidos da América"+ "newseries" -> "nova série"+ "oldseries" -> "série antiga"+ "inpreparation" -> "em preparação"+ "forthcoming" -> "aceito para publicação"+ "inpress" -> "no prelo"+ "prepublished" -> "pré-publicado"+ "mathesis" -> "dissertação de mestrado"+ "phdthesis" -> "tese de doutorado"+ "audiocd" -> "CD de áudio"+ _ -> k+resolveKey' (Lang "sv" "SE") k =+ case map toLower k of+ -- "inpreparation" -> "" -- missing+ -- "submitted" -> "" -- missing+ "forthcoming" -> "kommande" -- csl+ "inpress" -> "i tryck" -- csl+ -- "prepublished" -> "" -- missing+ "mathesis" -> "examensarbete"+ "phdthesis" -> "doktorsavhandling"+ "candthesis" -> "kandidatavhandling"+ "techreport" -> "teknisk rapport"+ "resreport" -> "forskningsrapport"+ "software" -> "datorprogram"+ "datacd" -> "data-cd"+ "audiocd" -> "ljud-cd"+ "patent" -> "patent"+ "patentde" -> "tyskt patent"+ "patenteu" -> "europeiskt patent"+ "patentfr" -> "franskt patent"+ "patentuk" -> "brittiskt patent"+ "patentus" -> "amerikanskt patent"+ "patreq" -> "patentansökan"+ "patreqde" -> "ansökan om tyskt patent"+ "patreqeu" -> "ansökan om europeiskt patent"+ "patreqfr" -> "ansökan om franskt patent"+ "patrequk" -> "ansökan om brittiskt patent"+ "patrequs" -> "ansökan om amerikanskt patent"+ "countryde" -> "Tyskland"+ "countryeu" -> "Europeiska unionen"+ "countryep" -> "Europeiska unionen"+ "countryfr" -> "Frankrike"+ "countryuk" -> "Storbritannien"+ "countryus" -> "USA"+ "newseries" -> "ny följd"+ "oldseries" -> "gammal följd"+ _ -> k resolveKey' _ k = resolveKey' (Lang "en" "US") k parseMonth :: String -> String@@ -949,7 +1315,7 @@ -- FIXME: add same for editora, editorb, editorc -- titles- let isArticle = et `elem` ["article", "periodical", "suppperiodical"]+ let isArticle = et `elem` ["article", "periodical", "suppperiodical", "review"] let isPeriodical = et == "periodical" let isChapterlike = et `elem` ["inbook","incollection","inproceedings","inreference","bookinbook"]
src/Text/CSL/Pandoc.hs view
@@ -5,7 +5,7 @@ import Text.Pandoc import Text.Pandoc.Walk import Text.Pandoc.Builder (setMeta, deleteMeta, Inlines, cite)-import Text.Pandoc.Shared (stringify, trim)+import Text.Pandoc.Shared (stringify) import Text.HTML.TagSoup.Entity (lookupEntity) import qualified Data.ByteString.Lazy as L import System.SetEnv (setEnv)@@ -29,7 +29,7 @@ import Control.Monad.State import System.FilePath import System.Directory (doesFileExist, getAppUserDataDirectory)-import Text.CSL.Util (findFile, splitStrWhen, tr')+import Text.CSL.Util (findFile, splitStrWhen, tr', parseRomanNumeral, trim) import System.IO.Error (isDoesNotExistError) -- | Process a 'Pandoc' document by adding citations formatted@@ -365,15 +365,25 @@ pLocator locMap = try $ do optional $ pMatch (== Str ",") optional pSpace- rawLoc <- many (notFollowedBy (pWordWithDigits True) >> anyToken)- la <- case trim (stringify rawLoc) of- "" -> lookAhead (optional pSpace >> pDigit) >> return "page"- s -> maybe mzero return $ parseLocator locMap s+ la <- try (do ts <- many1 (notFollowedBy (pWordWithDigits True) >> anyToken)+ case M.lookup (trim (stringify ts)) locMap of+ Just l -> return l+ Nothing -> mzero)+ <|> (lookAhead pDigit >> return "page") g <- pWordWithDigits True gs <- many (pWordWithDigits False) let lo = concat (g:gs) return (la, lo) +pRoman :: Parsec [Inline] st String+pRoman = try $ do+ t <- anyToken+ case t of+ Str xs -> case parseRomanNumeral xs of+ Nothing -> mzero+ Just _ -> return xs+ _ -> mzero+ -- we want to capture: 123, 123A, C22, XVII, 33-44, 22-33; 22-11 pWordWithDigits :: Bool -> Parsec [Inline] st String pWordWithDigits isfirst = try $ do@@ -381,9 +391,13 @@ then return "" else stringify `fmap` pLocatorPunct sp <- option "" (pSpace >> return " ")- r <- many1 (notFollowedBy pSpace >> notFollowedBy pLocatorPunct >> anyToken)- let s = stringify r- guard $ any isDigit s || all (`elem` ("IVXLCM" :: String)) s+ s <- pRoman <|>+ try (do ts <- many1 (notFollowedBy pSpace >>+ notFollowedBy pLocatorPunct >>+ anyToken)+ let ts' = stringify ts+ guard (any isDigit ts')+ return ts') return $ punct ++ sp ++ s pDigit :: Parsec [Inline] st ()@@ -401,9 +415,6 @@ isLocatorPunct _ = False type LocatorMap = M.Map String String--parseLocator :: LocatorMap -> String -> Maybe String-parseLocator locMap s = M.lookup s locMap locatorMap :: Style -> LocatorMap locatorMap sty =
src/Text/CSL/Parser.hs view
@@ -219,14 +219,17 @@ _ -> NoFormDate format = getFormatting cur delim = stringAttr "delimiter" cur- parts = cur $/ get "date-part" &| parseDatePart+ parts = cur $/ get "date-part" &| (parseDatePart form) partsAttr = stringAttr "date-parts" cur -parseDatePart :: Cursor -> DatePart-parseDatePart cur =+parseDatePart :: DateForm -> Cursor -> DatePart+parseDatePart defaultForm cur = DatePart { dpName = stringAttr "name" cur , dpForm = case stringAttr "form" cur of- "" -> "long"+ "" -> case defaultForm of+ TextDate -> "long"+ NumericDate -> "numeric"+ _ -> "long" x -> x , dpRangeDelim = case stringAttr "range-delimiter" cur of "" -> "-"
src/Text/CSL/Reference.hs view
@@ -46,11 +46,13 @@ import Data.Generics hiding (Generic) import GHC.Generics (Generic) import Data.Aeson hiding (Value)+import qualified Data.Aeson as Aeson import Data.Aeson.Types (Parser) import qualified Data.Yaml.Builder as Y import Data.Yaml.Builder (ToYaml(..)) import Control.Applicative ((<|>)) import qualified Data.Text as T+import Data.Text (Text) import qualified Data.Vector as V import Data.Char (toLower, isDigit) import Text.CSL.Style hiding (Number)@@ -59,6 +61,9 @@ (&=), mapping') import Text.Pandoc (Inline(Str)) import Data.String+import qualified Text.Parsec as P+import qualified Text.Parsec.String as P+import qualified Data.HashMap.Strict as H newtype Literal = Literal { unLiteral :: String } deriving ( Show, Read, Eq, Data, Typeable, Monoid, Generic )@@ -366,7 +371,9 @@ } deriving ( Eq, Show, Read, Typeable, Data, Generic ) instance FromJSON Reference where- parseJSON (Object v) = addPageFirst <$> (Reference <$>+ parseJSON (Object v') = do+ v <- parseSuppFields v'+ addPageFirst <$> (Reference <$> v .:? "id" .!= "" <*> v .:? "type" .!= NoType <*> v .:? "author" .!= [] <*>@@ -452,6 +459,31 @@ takeFirstNum (page ref) } else ref parseJSON _ = fail "Could not parse Reference"++-- Syntax for adding supplementary fields in note variable+-- {:authority:Superior Court of California}{:section:A}{:original-date:1777}+-- see http://gsl-nagoya-u.net/http/pub/citeproc-doc.html#supplementary-fields+parseSuppFields :: Aeson.Object -> Parser Aeson.Object+parseSuppFields o = do+ nt <- o .: "note" <|> return ("" :: String)+ case P.parse noteFields "note" nt of+ Left err -> fail (show err)+ Right fs -> return $ foldr (\(k,v) x -> H.insert k v x) o fs++noteFields :: P.Parser [(Text, Aeson.Value)]+noteFields = do+ -- TODO - actually parse the fields+ fs <- P.many noteField+ rest <- P.getInput+ return (("note", Aeson.String (T.pack rest)) : fs)++noteField :: P.Parser (Text, Aeson.Value)+noteField = P.try $ do+ P.char '{'+ P.char ':'+ k <- P.manyTill (P.letter <|> P.char '-') (P.char ':')+ v <- P.manyTill P.anyChar (P.char '}')+ return (T.pack k, Aeson.String (T.pack v)) instance ToJSON Reference where toJSON ref = object' [
src/Text/CSL/Util.hs view
@@ -42,12 +42,14 @@ , findFile , (&=) , mapping'+ , parseRomanNumeral ) where import Data.Aeson import Data.Aeson.Types (Parser) import Data.Text (Text) import qualified Data.Text as T-import Data.Char (toLower, toUpper, isLower, isUpper, isPunctuation)+import Data.Char (toLower, toUpper, isLower, isUpper, isPunctuation,+ isLetter, isAscii) import qualified Data.Traversable import Text.Pandoc.Shared (safeRead, stringify) import Text.Pandoc.Walk (walk)@@ -60,6 +62,8 @@ import System.Directory (doesFileExist) import qualified Data.Yaml.Builder as Y import Data.Yaml.Builder (ToYaml(..), YamlBuilder)+import qualified Text.Parsec as P+ #ifdef TRACE import qualified Debug.Trace import Text.Show.Pretty (ppShow)@@ -211,9 +215,9 @@ where tc (Str (x:xs)) = do st <- get return $ case st of- WordBoundary -> if isShortWord (x:xs)+ WordBoundary -> if isShortWord (x:xs) ||+ not (isAscii x && isLetter x) then Str (x:xs)- -- or? map toLower (x:xs) else Str (toUpper x : xs) SentenceBoundary -> Str (toUpper x : xs) _ -> Str (x:xs)@@ -381,3 +385,43 @@ mapping' :: [[(Text, YamlBuilder)] -> [(Text, YamlBuilder)]] -> YamlBuilder mapping' = Y.mapping . foldr ($) []++-- TODO: romanNumeral is defined in Text.Pandoc.Parsing, but it's+-- not exported there. Eventually we should remove this code duplication+-- by exporting something from pandoc.++parseRomanNumeral :: String -> Maybe Int+parseRomanNumeral s = case P.parse (pRomanNumeral <* P.eof) "" s of+ Left _ -> Nothing+ Right x -> Just x++-- | Parses a roman numeral (uppercase or lowercase), returns number.+pRomanNumeral :: P.Stream s m Char => P.ParsecT s st m Int+pRomanNumeral = do+ let lowercaseRomanDigits = ['i','v','x','l','c','d','m']+ let uppercaseRomanDigits = ['I','V','X','L','C','D','M']+ c <- P.lookAhead $ P.oneOf (lowercaseRomanDigits ++ uppercaseRomanDigits)+ let romanDigits = if isUpper c+ then uppercaseRomanDigits+ else lowercaseRomanDigits+ let [one, five, ten, fifty, hundred, fivehundred, thousand] =+ map P.char romanDigits+ thousands <- P.many thousand >>= (return . (1000 *) . length)+ ninehundreds <- P.option 0 $ P.try $ hundred >> thousand >> return 900+ fivehundreds <- P.many fivehundred >>= (return . (500 *) . length)+ fourhundreds <- P.option 0 $ P.try $ hundred >> fivehundred >> return 400+ hundreds <- P.many hundred >>= (return . (100 *) . length)+ nineties <- P.option 0 $ P.try $ ten >> hundred >> return 90+ fifties <- P.many fifty >>= (return . (50 *) . length)+ forties <- P.option 0 $ P.try $ ten >> fifty >> return 40+ tens <- P.many ten >>= (return . (10 *) . length)+ nines <- P.option 0 $ P.try $ one >> ten >> return 9+ fives <- P.many five >>= (return . (5 *) . length)+ fours <- P.option 0 $ P.try $ one >> five >> return 4+ ones <- P.many one >>= (return . length)+ let total = thousands + ninehundreds + fivehundreds + fourhundreds ++ hundreds + nineties + fifties + forties + tens + nines ++ fives + fours + ones+ if total == 0+ then fail "not a roman numeral"+ else return total
tests/biblio2yaml/kastenholz.biblatex view
@@ -11,7 +11,7 @@ Methodologyindependent Ionic Solvation Free Energies from Molecular Simulations: I. the Electrostatic Potential in Molecular Liquids.” *J. Chem. Phys.* 124.-doi:[10.1063/1.2172593](http://doi.org/10.1063/1.2172593 "10.1063/1.2172593").+doi:[10.1063/1.2172593](https://doi.org/10.1063/1.2172593 "10.1063/1.2172593"). Formatted with pandoc and apa.csl, 2013-10-23:@@ -22,7 +22,7 @@ methodologyindependent ionic solvation free energies from molecular simulations: I. the electrostatic potential in molecular liquids. *J. Chem. Phys.*, *124*.-doi:[10.1063/1.2172593](http://doi.org/10.1063/1.2172593 "10.1063/1.2172593")+doi:[10.1063/1.2172593](https://doi.org/10.1063/1.2172593 "10.1063/1.2172593") NOTES:
tests/biblio2yaml/sigfridsson.biblatex view
@@ -9,7 +9,7 @@ Sigfridsson, Emma, and Ulf Ryde. 1998. “Comparison of Methods for Deriving Atomic Charges from the Electrostatic Potential and Moments.” *Journal of Computational Chemistry* 19 (4): 377–395.-doi:[10.1002/(SICI)1096-987X(199803)19:4\<377::AID-JCC1\>3.0.CO;2-P](http://doi.org/10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P "10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P").+doi:[10.1002/(SICI)1096-987X(199803)19:4\<377::AID-JCC1\>3.0.CO;2-P](https://doi.org/10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P "10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P"). Formatted with pandoc and apa.csl, 2013-10-23:@@ -19,7 +19,7 @@ Sigfridsson, E., & Ryde, U. (1998). Comparison of methods for deriving atomic charges from the electrostatic potential and moments. *Journal of Computational Chemistry*, *19*(4), 377–395.-doi:[10.1002/(SICI)1096-987X(199803)19:4\<377::AID-JCC1\>3.0.CO;2-P](http://doi.org/10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P "10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P")+doi:[10.1002/(SICI)1096-987X(199803)19:4\<377::AID-JCC1\>3.0.CO;2-P](https://doi.org/10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P "10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P") NOTES:
+ tests/issue175.expected.native view
@@ -0,0 +1,7 @@+Pandoc (Meta {unMeta = fromList [("references",MetaList [MetaMap (fromList [("author",MetaList [MetaMap (fromList [("family",MetaInlines [Str "Doe"]),("given",MetaInlines [Str "Jane"])])]),("container-title",MetaInlines [Str "A",Space,Str "magazine"]),("id",MetaInlines [Str "item1"]),("issued",MetaList [MetaMap (fromList [("month",MetaString "1"),("year",MetaString "2011")]),MetaMap (fromList [("month",MetaString "2"),("year",MetaString "2011")])]),("page",MetaInlines [Str "33-44"]),("title",MetaInlines [Str "A",Space,Str "title"]),("type",MetaInlines [Str "article-magazine"])])])]})+[Header 2 ("missing-en-dash-between-months",[],[]) [Str "Missing",Space,Str "en-dash",Space,Str "between",Space,Str "months"]+,Para [Str "Foo",Space,Cite [Citation {citationId = "item1", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 1}] [Str "(",Str "Doe",Space,Str "2011",Str ")"],Str "."]+,Header 2 ("expected",[],[]) [Str "Expected"]+,BlockQuote+ [Para [Str "Doe,",Space,Str "Jane.",Space,Str "2011.",Space,Str "\8220A",Space,Str "Title.\8221",Space,Emph [Str "A",Space,Str "Magazine"],Str ",",Space,Str "January\8211February."]]+,Div ("refs",["references"],[]) [Div ("ref-item1",[],[]) [Para [Str "Doe",Str ",",Space,Str "Jane",Str ".",Space,Str "2011",Str ".",Space,Str "\8220",Str "A",Space,Str "Title",Str ".",Str "\8221",Space,Emph [Str "A",Space,Str "Magazine"],Str ",",Space,Str "January",Str "\8211",Str "February",Str "."]]]]
+ tests/issue175.in.native view
@@ -0,0 +1,6 @@+Pandoc (Meta {unMeta = fromList [("references",MetaList [MetaMap (fromList [("author",MetaList [MetaMap (fromList [("family",MetaInlines [Str "Doe"]),("given",MetaInlines [Str "Jane"])])]),("container-title",MetaInlines [Str "A",Space,Str "magazine"]),("id",MetaInlines [Str "item1"]),("issued",MetaList [MetaMap (fromList [("month",MetaString "1"),("year",MetaString "2011")]),MetaMap (fromList [("month",MetaString "2"),("year",MetaString "2011")])]),("page",MetaInlines [Str "33-44"]),("title",MetaInlines [Str "A",Space,Str "title"]),("type",MetaInlines [Str "article-magazine"])])])]})+[Header 2 ("missing-en-dash-between-months",[],[]) [Str "Missing",Space,Str "en-dash",Space,Str "between",Space,Str "months"]+,Para [Str "Foo",Space,Cite [Citation {citationId = "item1", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@item1]"],Str "."]+,Header 2 ("expected",[],[]) [Str "Expected"]+,BlockQuote+ [Para [Str "Doe,",Space,Str "Jane.",Space,Str "2011.",Space,Str "\8220A",Space,Str "Title.\8221",Space,Emph [Str "A",Space,Str "Magazine"],Str ",",Space,Str "January\8211February."]]]