From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/387 Path: news.gmane.org!not-for-mail From: Andrea Rossato Newsgroups: gmane.text.pandoc Subject: [citeproc] textual citation Date: Thu, 11 Nov 2010 02:49:28 +0100 Message-ID: <20101111014927.GP24988@eeepc.istitutocolli.org> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="VbJkn9YxBvnuCH5J" X-Trace: dough.gmane.org 1289440186 14545 80.91.229.12 (11 Nov 2010 01:49:46 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 11 Nov 2010 01:49:46 +0000 (UTC) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncCNzq99GEChCtl-3mBBoEUbybTA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Nov 11 02:49:42 2010 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-wy0-f186.google.com ([74.125.82.186]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PGMIG-0006WT-Nv for gtp-pandoc-discuss@m.gmane.org; Thu, 11 Nov 2010 02:49:40 +0100 Original-Received: by wyi11 with SMTP id 11sf847547wyi.3 for ; Wed, 10 Nov 2010 17:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:received:received:date:from:to :subject:message-id:mime-version:x-pgp-fingerprint:x-pgp-key :user-agent:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:sender:list-subscribe:list-unsubscribe:content-type :content-disposition; bh=KrInwgKUgQK3tKTGcOYt6TpM/ayuU0YXnV4N0aYsw/0=; b=S5+PGU4IdBY/F4ZTXx9lEAjlFq4hfuwPLNQOTACHExXHqzCIfeQgH4FXIUunpYnZJH aPH0I5clcHS0Ekhq81FGzaMWPj+2tdqiwBFt7fOVaBANnvfBK4ZsMV1fvPkK01TD6OHp jHPBf5K31WMmwBjBDhKIEQQVKAZgL3A01bscM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:date:from:to:subject:message-id :mime-version:x-pgp-fingerprint:x-pgp-key:user-agent :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe:content-type :content-disposition; b=IMbk24FfAWnKE46BKpzPIYoSnak1T4BKoW2BFQy9r214A1oktQA+emYicM1Tn3w6Hj R4epvSNF+N3+WS1XlJSEPGUV6BiXjyl1fLl+Y90k798mjgifFg1TWx9lc0gxuTuP4D0X BLYar5/6Uk7KIhv9KSE72+tbqaQZdK/j4asTc= Original-Received: by 10.216.159.205 with SMTP id s55mr247418wek.12.1289440173342; Wed, 10 Nov 2010 17:49:33 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.216.68.80 with SMTP id k58ls547725wed.0.p; Wed, 10 Nov 2010 17:49:32 -0800 (PST) Original-Received: by 10.216.55.145 with SMTP id k17mr161630wec.0.1289440172504; Wed, 10 Nov 2010 17:49:32 -0800 (PST) Original-Received: by 10.216.55.145 with SMTP id k17mr161629wec.0.1289440172488; Wed, 10 Nov 2010 17:49:32 -0800 (PST) Original-Received: from gorgias.mine.nu (host118-2-static.225-95-b.business.telecomitalia.it [95.225.2.118]) by gmr-mx.google.com with ESMTP id l5si429241weq.15.2010.11.10.17.49.32; Wed, 10 Nov 2010 17:49:32 -0800 (PST) Received-SPF: neutral (google.com: 95.225.2.118 is neither permitted nor denied by best guess record for domain of andrea.rossato-3IIOeSMMxS4@public.gmane.org) client-ip=95.225.2.118; Original-Received: from eeepc.nowhere.net (localhost [127.0.0.1]) by gorgias.mine.nu (8.14.3/8.14.3) with ESMTP id oAB1nVmA022313 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 11 Nov 2010 02:49:31 +0100 Original-Received: from eeepc.nowhere.net (localhost [127.0.0.1]) by eeepc.nowhere.net (8.14.4/8.14.3) with ESMTP id oAB1nSSF017774 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 11 Nov 2010 02:49:29 +0100 Original-Received: (from andrea@localhost) by eeepc.nowhere.net (8.14.4/8.14.4/Submit) id oAB1nSOo017768 for pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; Thu, 11 Nov 2010 02:49:28 +0100 X-PGP-Fingerprint: 6FB5 7A1A C6CB 9136 A001 4E7C 3329 A039 8964 D6D3 X-PGP-Key: http://www.istitutocolli.org/pubkey.asc User-Agent: Mutt/1.5.20 (2009-06-14) X-Original-Sender: andrea.rossato-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 95.225.2.118 is neither permitted nor denied by best guess record for domain of andrea.rossato-3IIOeSMMxS4@public.gmane.org) smtp.mail=andrea.rossato-3IIOeSMMxS4@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: List-Post: , List-Help: , List-Archive: Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-Subscribe: , List-Unsubscribe: , Content-Disposition: inline Xref: news.gmane.org gmane.text.pandoc:387 Archived-At: --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline 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. --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0001-mv-AuthorOnly-AuthoInText.patch" >From 5431832bc9d81d5391f10af463666aee71976a2d Mon Sep 17 00:00:00 2001 From: Andrea Rossato 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 --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0009-add-support-for-textual-citation.patch" >From 32df46a6c66df16e7a125bda023447370b73dac5 Mon Sep 17 00:00:00 2001 From: Andrea Rossato 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