Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
Only print labels if selected variable is non-empty.
Browse files Browse the repository at this point in the history
Closes #437.
  • Loading branch information
jgm committed Jan 27, 2020
1 parent b05d286 commit 167e44e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/Text/CSL/Eval/Names.hs
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,23 @@ formatTerm f fm p refid s = do
else oStr' t fm

formatLabel :: Form -> Formatting -> Bool -> Text -> State EvalState [Output]
formatLabel f fm p s
| "locator" <- s = when' ( (/=) "" <$> gets (citeLocator . cite . env)) $ do
(l,v) <- getLocVar
form (\fm' -> return . flip OLoc emptyFormatting . output fm') id l (isRange v)
| "page" <- s = checkPlural
| "volume" <- s = checkPlural
| "issue" <- s = checkPlural
| "ibid" <- s = format s p
| isRole s = do a <- getAgents' (if s == "editortranslator"
then "editor"
else s)
if null a
then return []
else form (\fm' x -> [OLabel x fm']) id s p
| otherwise = format s p
formatLabel f fm p s = when' (isVarSet s) go
where
go
| "locator" <- s = when' ( (/=) "" <$> gets (citeLocator . cite . env)) $ do
(l,v) <- getLocVar
form (\fm' -> return . flip OLoc emptyFormatting . output fm') id l (isRange v)
| "page" <- s = checkPlural
| "volume" <- s = checkPlural
| "issue" <- s = checkPlural
| "ibid" <- s = format s p
| isRole s = do a <- getAgents' (if s == "editortranslator"
then "editor"
else s)
if null a
then return []
else form (\fm' x -> [OLabel x fm']) id s p
| otherwise = format s p
isRole = flip elem ["author", "collection-editor", "composer", "container-author"
,"director", "editor", "editorial-director", "editortranslator"
,"illustrator", "interviewer", "original-author", "recipient"
Expand Down
26 changes: 26 additions & 0 deletions tests/issue437.csl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="note" default-locale="en-US" version="1.0">
<info>
<title>Minimal style to reproduce bug</title>
<id>http://www.example.org/styles/minimal-test-style</id>
<author>
<name>Nicolas Chachereau</name>
<email>nicolas@nchachereau.ch</email>
</author>
<updated>2020-01-27T14:27:45+01:00</updated>
</info>
<citation>
<layout>
<group delimiter=", ">
<names variable="author"/>
<text variable="title"/>
<text variable="publisher-place"/>
<date variable="issued" form="numeric" date-parts="year"/>
<group delimiter="&#160;">
<number variable="number-of-pages"/>
<label variable="number-of-pages"/>
</group>
</group>
</layout>
</citation>
</style>
3 changes: 3 additions & 0 deletions tests/issue437.expected.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Pandoc (Meta {unMeta = fromList [("csl",MetaInlines [Str "tests/issue437.csl"]),("references",MetaList [MetaMap (fromList [("author",MetaList [MetaMap (fromList [("family",MetaInlines [Str "Smith"]),("given",MetaInlines [Str "John"])])]),("id",MetaInlines [Str "hirt2009"]),("issued",MetaList [MetaMap (fromList [("year",MetaInlines [Str "2009"])])]),("publisher",MetaInlines [Str "Publishing",Space,Str "House"]),("publisher-place",MetaInlines [Str "Lausanne"]),("title",MetaInlines [Str "Some",Space,Str "Book"]),("type",MetaInlines [Str "book"])])])]})
[BlockQuote
[Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "quote.",Cite [Citation {citationId = "hirt2009", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 1}] [Note [Para [Str "John",Space,Str "Smith,",Space,Str "Some",Space,Str "Book,",Space,Str "Lausanne,",Space,Str "2009"]]]]]]
3 changes: 3 additions & 0 deletions tests/issue437.in.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Pandoc (Meta {unMeta = fromList [("csl",MetaInlines [Str "tests/issue437.csl"]),("references",MetaList [MetaMap (fromList [("author",MetaList [MetaMap (fromList [("family",MetaInlines [Str "Smith"]),("given",MetaInlines [Str "John"])])]),("id",MetaInlines [Str "hirt2009"]),("issued",MetaList [MetaMap (fromList [("year",MetaInlines [Str "2009"])])]),("publisher",MetaInlines [Str "Publishing",Space,Str "House"]),("publisher-place",MetaInlines [Str "Lausanne"]),("title",MetaInlines [Str "Some",Space,Str "Book"]),("type",MetaInlines [Str "book"])])])]})
[BlockQuote
[Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "quote.",Space,Cite [Citation {citationId = "hirt2009", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@hirt2009]"]]]]

0 comments on commit 167e44e

Please sign in to comment.