public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* [citeproc] textual citation
@ 2010-11-11  1:49 Andrea Rossato
       [not found] ` <20101111014927.GP24988-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
  0 siblings, 1 reply; 71+ messages in thread
From: Andrea Rossato @ 2010-11-11  1:49 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 1397 bytes --]

Hi,

it took a bit, since in the meantime I tried to move on with the
CSL-1.0 implementation (now citation collapsing works) but I
eventually was able to get the textual citation running.

I didn't touch the parsers, so the syntax is not there, but there is
the '+' modifier to play with...

Now, a textual citation would look like [+@item1], instead of @item1.
A textual citation with multiple citations would look like [+@item1;
@item2], etc.

I'm attaching the code for pandoc:
0009-add-support-for-textual-citation.patch

and pandoc-types:
0001-mv-AuthorOnly-AuthoInText.patch

Here you can find updated tests:
http://gorgias.mine.nu/citeproc/

I didn't switch to the Map, yet.

As for the API: when a citation group with a leading AuthorInText
citation is sent to the processor, the first item in the returned list
is the label to be placed in-text. This citation is then rendered as a
SuppressAuthor one in the citation group.

We should be almost done, I think.

Andrea

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at http://groups.google.com/group/pandoc-discuss?hl=en.


[-- Attachment #2: 0001-mv-AuthorOnly-AuthoInText.patch --]
[-- Type: text/plain, Size: 897 bytes --]

From 5431832bc9d81d5391f10af463666aee71976a2d Mon Sep 17 00:00:00 2001
From: Andrea Rossato <andrea.rossato-/Q1r7N5in3P/wltNWqQaag@public.gmane.org>
Date: Wed, 10 Nov 2010 12:13:48 +0100
Subject: [PATCH] mv AuthorOnly AuthoInText

---
 Text/Pandoc/Definition.hs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Text/Pandoc/Definition.hs b/Text/Pandoc/Definition.hs
index 1c2db89..3b8c7e6 100644
--- a/Text/Pandoc/Definition.hs
+++ b/Text/Pandoc/Definition.hs
@@ -142,7 +142,7 @@ instance Eq Citation where
     (==) (Citation _ _ _ _ _ ha)
          (Citation _ _ _ _ _ hb) = ha == hb
 
-data CitationMode = AuthorOnly | SuppressAuthor | NormalCitation
+data CitationMode = AuthorInText | SuppressAuthor | NormalCitation
                     deriving (Show, Eq, Ord, Read, Typeable, Data)
 
 -- | Applies a transformation on @a@s to matching elements in a @b@.
-- 
1.7.1


[-- Attachment #3: 0009-add-support-for-textual-citation.patch --]
[-- Type: text/plain, Size: 5543 bytes --]

From 32df46a6c66df16e7a125bda023447370b73dac5 Mon Sep 17 00:00:00 2001
From: Andrea Rossato <andrea.rossato-/Q1r7N5in3P/wltNWqQaag@public.gmane.org>
Date: Thu, 11 Nov 2010 01:56:03 +0100
Subject: [PATCH 9/9] add support for textual citation

---
 src/Text/Pandoc/Biblio.hs           |   45 +++++++++++++++++++++--------------
 src/Text/Pandoc/Readers/Markdown.hs |    2 +-
 2 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/src/Text/Pandoc/Biblio.hs b/src/Text/Pandoc/Biblio.hs
index d8a4659..c334d89 100644
--- a/src/Text/Pandoc/Biblio.hs
+++ b/src/Text/Pandoc/Biblio.hs
@@ -54,19 +54,27 @@ processBiblio cf r p
             result     = citeproc csl r (setNearNote csl $ map (map toCslCite) grps)
             cits_map   = zip grps (citations result)
             biblioList = map (renderPandoc' csl) (bibliography result)
-            Pandoc m b = processWith (processCite csl cits_map) p'
+            Pandoc m b = processWith (procInlines $ processCite csl cits_map) p'
         return . generateNotes nts . Pandoc m $ b ++ biblioList
 
 -- | Substitute 'Cite' elements with formatted citations.
-processCite :: Style -> [([Citation],[FormattedOutput])] -> Inline -> Inline
-processCite s cs il
-    | Cite t _ <- il = Cite t (process t)
-    | otherwise      = il
+processCite :: Style -> [([Citation],[FormattedOutput])] -> [Inline] -> [Inline]
+processCite _ _ [] = []
+processCite s cs (i:is)
+    | Cite t _ <- i = process t ++ processCite s cs is
+    | otherwise     = i          : processCite s cs is
     where
       process t = case lookup t cs of
-                    Just  i -> renderPandoc s i
+                    Just  x -> if isTextualCitation t && x /= []
+                               then renderPandoc s [head x] ++ [Space] ++
+                                    [Cite t $ renderPandoc s $ tail x]
+                               else [Cite t $ renderPandoc s        x]
                     Nothing -> [Str ("Error processing " ++ show t)]
 
+isTextualCitation :: [Citation] -> Bool
+isTextualCitation (c:_) = citationMode c == AuthorInText
+isTextualCitation _     = False
+
 -- | Retrieve all citations from a 'Pandoc' docuument. To be used with
 -- 'queryWith'.
 getCitation :: Inline -> [[Citation]]
@@ -109,22 +117,22 @@ mvCiteInNote is = procInlines mvCite
       mvCite :: [Inline] -> [Inline]
       mvCite inls
           | x:i:xs <- inls, startWithPunct xs
-          , x == Space,   i `elem_` is = split i xs ++ mvCite (tailFirstInlineStr xs)
+          , x == Space,   i `elem_` is = switch i xs ++ mvCite (tailFirstInlineStr xs)
           | x:i:xs <- inls
-          , x == Space,   i `elem_` is = mvInNote i :  mvCite xs
+          , x == Space,   i `elem_` is = mvInNote i :   mvCite xs
           | i:xs <- inls, i `elem_` is
-          , startWithPunct xs          = split i xs ++ mvCite (tailFirstInlineStr xs)
-          | i:xs <- inls, Note _ <- i  = checkNt  i :  mvCite xs
-          | i:xs <- inls               = i          :  mvCite xs
+          , startWithPunct xs          = switch i xs ++ mvCite (tailFirstInlineStr xs)
+          | i:xs <- inls, Note _ <- i  = checkNt  i :   mvCite xs
+          | i:xs <- inls               = i          :   mvCite xs
           | otherwise                  = []
-      elem_ x xs = case x of Cite cs _ -> (Cite cs []) `elem` xs; _ -> False
-      split i xs = Str (headInline xs) : mvInNote i : []
+      elem_  x xs = case x of Cite cs _ -> (Cite cs []) `elem` xs; _ -> False
+      switch i xs = Str (headInline xs) : mvInNote i : []
       mvInNote i
           | Cite t o <- i = Note [Para [Cite t $ sanitize o]]
           | otherwise     = Note [Para [i                  ]]
       sanitize i
-          | endWithPunct i = toCapital i
-          | otherwise      = toCapital (i ++ [Str "."])
+          | endWithPunct   i = toCapital i
+          | otherwise        = toCapital (i ++ [Str "."])
 
       checkPt i
           | Cite c o : xs <- i
@@ -142,10 +150,10 @@ setCitationNoteNum :: Int -> [Citation] -> [Citation]
 setCitationNoteNum i = map $ \c -> c { citationNoteNum = i}
 
 toCslCite :: Citation -> CSL.Cite
-toCslCite (Citation i p l cm nn _)
+toCslCite (Citation i p l cm nn h)
     = let (la,lo) = parseLocator l
           citMode = case cm of
-                      AuthorOnly     -> (True, False)
+                      AuthorInText   -> (True, False)
                       SuppressAuthor -> (False,True )
                       NormalCitation -> (False,False)
       in   emptyCite { CSL.citeId         = i
@@ -153,6 +161,7 @@ toCslCite (Citation i p l cm nn _)
                      , CSL.citeLabel      = la
                      , CSL.citeLocator    = lo
                      , CSL.citeNoteNumber = show nn
-                     , CSL.authorOnly     = fst citMode
+                     , CSL.authorInText   = fst citMode
                      , CSL.suppressAuthor = snd citMode
+                     , CSL.citeHash       = h
                      }
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index b7c5220..7a42d90 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1345,6 +1345,6 @@ parseLabel = try $ do
                else (p        , False)
       mode = case (na,o) of
                (True, False) -> SuppressAuthor
-               (False,True ) -> AuthorOnly
+               (False,True ) -> AuthorInText
                _             -> NormalCitation
   return $ Citation cit (trim p') (trim loc) mode 0 0

^ permalink raw reply	[flat|nested] 71+ messages in thread

end of thread, other threads:[~2010-12-09 16:29 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-11  1:49 [citeproc] textual citation Andrea Rossato
     [not found] ` <20101111014927.GP24988-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-12  6:36   ` John MacFarlane
     [not found]     ` <20101112063622.GA8676-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-12  8:43       ` John MacFarlane
     [not found]         ` <20101112084314.GA15038-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-12 11:16           ` Andrea Rossato
     [not found]             ` <20101112111654.GE19143-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-12 16:08               ` John MacFarlane
2010-11-12 13:45           ` Nathan Gass
     [not found]             ` <4CDD4501.7030700-8UOIJiGH10pyDzI6CaY1VQ@public.gmane.org>
2010-11-12 16:13               ` John MacFarlane
2010-11-12 23:26               ` Andrea Rossato
2010-11-12 15:38           ` Andrea Rossato
     [not found]             ` <20101112153829.GG19143-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-12 16:16               ` John MacFarlane
2010-11-12 23:23           ` Andrea Rossato
     [not found]             ` <20101112232354.GH19143-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-13  2:56               ` John MacFarlane
     [not found]                 ` <20101113025645.GA25386-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-13  9:16                   ` Andrea Rossato
     [not found]                     ` <20101113091616.GK19143-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-13 11:40                       ` Andrea Rossato
     [not found]                         ` <20101113114018.GM19143-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-13 16:57                           ` John MacFarlane
2010-11-13 16:50                       ` John MacFarlane
2010-11-13  1:11           ` Andrea Rossato
     [not found]             ` <20101113011105.GJ19143-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-13  3:38               ` John MacFarlane
     [not found]                 ` <20101113033806.GA27595-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-13 13:15                   ` Andrea Rossato
     [not found]                     ` <20101113131538.GO19143-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-13 16:27                       ` John MacFarlane
     [not found]                         ` <20101113162702.GC1212-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-13 16:55                           ` Bruce
2010-11-14 13:26                           ` Andrea Rossato
     [not found]                             ` <20101114132646.GR19143-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-17  4:39                               ` John MacFarlane
     [not found]                                 ` <20101117043955.GA18136-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-17 21:49                                   ` Andrea Rossato
2010-11-19 19:51                                   ` John MacFarlane
     [not found]                                     ` <20101119195134.GB30277-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-20  2:53                                       ` Andrea Rossato
     [not found]                                         ` <20101120025350.GA13438-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-21 18:23                                           ` John MacFarlane
     [not found]                                             ` <20101121182302.GK24768-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-22 17:09                                               ` Andrea Rossato
2010-11-23  9:56                                   ` Nathan Gass
     [not found]                                     ` <4CEB8FB6.807-8UOIJiGH10pyDzI6CaY1VQ@public.gmane.org>
2010-11-23 15:46                                       ` John MacFarlane
     [not found]                                         ` <20101123154639.GB12884-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-23 20:09                                           ` Andrea Rossato
2010-11-24  1:20                                           ` Nathan Gass
     [not found]                                             ` <4CEC6860.7020908-8UOIJiGH10pyDzI6CaY1VQ@public.gmane.org>
2010-11-24  2:39                                               ` John MacFarlane
     [not found]                                                 ` <20101124023950.GA25133-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-24  9:39                                                   ` Nathan Gass
     [not found]                                                     ` <4CECDD5D.6010400-8UOIJiGH10pyDzI6CaY1VQ@public.gmane.org>
2010-11-24 16:09                                                       ` John MacFarlane
     [not found]                                                         ` <20101124160951.GD1590-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-26 12:33                                                           ` Nathan Gass
     [not found]                                                             ` <4CEFA937.7040606-8UOIJiGH10pyDzI6CaY1VQ@public.gmane.org>
2010-11-27 15:12                                                               ` John MacFarlane
     [not found]                                                                 ` <20101127151254.GA535-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-27 18:58                                                                   ` Andrea Rossato
     [not found]                                                                     ` <20101127185836.GD32527-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-27 19:32                                                                       ` John MacFarlane
     [not found]                                                                         ` <20101127193232.GA3576-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-27 20:09                                                                           ` John MacFarlane
     [not found]                                                                             ` <20101127200931.GA4421-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-27 20:39                                                                               ` Andrea Rossato
     [not found]                                                                                 ` <20101127203907.GH32527-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-28 12:57                                                                                   ` Andrea Rossato
2010-11-28 13:03                                                                               ` Andrea Rossato
     [not found]                                                                                 ` <20101128130345.GK32527-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-28 16:16                                                                                   ` John MacFarlane
     [not found]                                                                                     ` <20101128161612.GB29510-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-29 16:10                                                                                       ` Andrea Rossato
     [not found]                                                                                         ` <20101129161059.GC20563-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-12-01 13:06                                                                                           ` Andrea Rossato
     [not found]                                                                                             ` <20101201130603.GJ10338-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-12-01 16:17                                                                                               ` John MacFarlane
     [not found]                                                                                                 ` <20101201161702.GD3038-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-12-01 20:55                                                                                                   ` dsanson
     [not found]                                                                                                     ` <8f044663-b02a-45bd-b299-60fef03bf457-n9fKM5ssUrqdjmvXPhoLGFYGCWtFR9XvQQ4Iyu8u01E@public.gmane.org>
2010-12-07 16:35                                                                                                       ` John MacFarlane
     [not found]                                                                                                         ` <20101207163551.GC13385-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-12-09 11:23                                                                                                           ` Andrea Rossato
     [not found]                                                                                                             ` <20101209112343.GD28254-u31zCTIHpvLVI6Gt0zCidg@public.gmane.org>
2010-12-09 16:29                                                                                                               ` John MacFarlane
2010-12-03  5:57                                                                                                   ` John MacFarlane
     [not found]                                                                                                     ` <20101203055730.GA24661-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-12-03  6:09                                                                                                       ` John MacFarlane
     [not found]                                                                                                         ` <20101203060948.GA24736-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-12-03  6:45                                                                                                           ` John MacFarlane
2010-12-03 14:18                                                                                                           ` Andrea Rossato
2010-12-07 17:27                                                                                                           ` Andrea Rossato
2010-12-03 14:11                                                                                                       ` Andrea Rossato
     [not found]                                                                                                         ` <20101203141139.GD14815-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-12-03 14:19                                                                                                           ` Andrea Rossato
     [not found]                                                                                                             ` <20101203141953.GF14815-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-12-03 15:40                                                                                                               ` John MacFarlane
     [not found]                                                                                                                 ` <20101203154032.GB28210-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-12-07 10:30                                                                                                                   ` Andrea Rossato
     [not found]                                                                                                                     ` <20101207103034.GA22516-u31zCTIHpvLVI6Gt0zCidg@public.gmane.org>
2010-12-07 16:30                                                                                                                       ` John MacFarlane
2010-12-03 15:30                                                                                                           ` John MacFarlane
2010-11-28 18:10                                                                                   ` John MacFarlane
     [not found]                                                                                     ` <20101128181002.GA30854-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-11-29 16:12                                                                                       ` Andrea Rossato
2010-11-27 20:10                                                                           ` Andrea Rossato
     [not found]                                                                             ` <20101127201014.GF32527-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-11-27 20:18                                                                               ` Andrea Rossato
2010-11-28  2:22                                                                               ` John MacFarlane
     [not found]                                                                                 ` <20101128022210.GA6819-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2010-12-01 11:28                                                                                   ` Andrea Rossato
     [not found]                                                                                     ` <20101201112806.GH10338-j4W6CDmL7uNdAaE8spi6tJZpQXiuRcL9@public.gmane.org>
2010-12-01 15:52                                                                                       ` John MacFarlane
2010-11-24 20:32                                                       ` Andrea Rossato
2010-11-16 23:17                   ` Nathan Gass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).