From: Sergio Correia <sergio.correia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Scripting with Haskell to achieve a filter for acronyms in pandoc
Date: Tue, 27 Dec 2016 18:37:44 -0800 (PST) [thread overview]
Message-ID: <719e577c-e900-4951-afb2-0423e71ff601@googlegroups.com> (raw)
In-Reply-To: <92666292-e593-4249-8ec2-ad37ceba79d2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 3893 bytes --]
Chiming in:
- That error happened to me when the code I was running had errors (so
the problem might be on the Python side)
- A quick way to test the python side is to just run the python program
w/out any arguments. That would ensure there are no "compile-time" errors
at least
- This also looks quite similar to what I did in one of the panflute
examples
<http://scorreia.com/software/panflute/guide.html#calling-external-programs> (might
be useful in case you want a more complex filter)
Best,
Sergio
On Tuesday, December 27, 2016 at 4:34:43 PM UTC-5, Luis Fernado Silva
Castro de Araújo wrote:
>
> Sorry John,
>
> I tried, but Haskell is too foreign to me. It would be simpler to go with
> a more familiar language.
>
>
> - The aim is to create an acronym filter (in Haskell) to run with
> pandoc. The filter would modify the current link syntax and make
> [LRU](acro: "Least Recently Used") represent a definition for an acronym.
>
>
> - In the LATEX side, an acronym addition would have to involve adding \usepackage[acronym,smallcaps]{glossaries}
> to the preamble and \newacronym{LRU}{LRU}{Least Recently Used} for the
> definition of LRU and finally \gls{LRU} to every time the term is used
> in the text.
>
>
>
> I have been adapting Pacrodoc, however I am stuck at the following code:
>
>
> # Based on https://github.com/cflewis/Pacrodoc/blob/master/pacrodoc.py
>
> import sys
> import json
> import re
> import urllib
>
> acronyms = {}
>
> def processAcronym(linkData):
> # Links look like this:
> # [[{u'Str': u'Link Name'}], [u'Link URL', 'Link Title']]
> acronym = linkData[0][0]['Str']
> acronymText = linkData[1][0]
>
> # First we check if there is an acronym being defined
> if re.search('^acro:', linkData[1][0]):
> # An acronym is being defined, so strip off the acro:
> # prefix and unencode the text
> acronyms[acronym] = {'text': urllib.unquote(acronymText[5:]),
> 'used': False}
>
> # Strip out this link
> return {'Str': ''}
>
> # Now we check if its referring to an acronym instead
> if not acronymText and acronym in acronyms:
> if not acronyms[acronym]['used']:
> acronyms[acronym]['used'] = True
> return {'Str': '%s (%s)' % (acronyms[acronym]['text'],
> acronym)}
> else:
> return {'Str': acronym}
>
> # It was just a normal link, so return it unchanged
> return {'Link': linkData}
>
> def lookForAcronyms(jsonData):
> if isinstance(jsonData, list):
> return [lookForAcronyms(value) for value in jsonData]
>
> if isinstance(jsonData, dict):
> if 'Link' in jsonData:
> return processAcronym(jsonData['Link'])
> else:
> return {k: lookForAcronyms(v) for k, v in jsonData.items()}
>
> return jsonData
>
> if __name__ == "__main__":
> toJSONFilter(lookForAcronyms)
>
>
> And I get the error:
>
> fd:4: hClose: resource vanished (Broken pipe)
>
>
>
> I hope anyone could shed some light on where I am getting it wrong.
> Perhaps some pointers on how to do it using the more recent panflute
> framework.
>
> Thanks
>
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/719e577c-e900-4951-afb2-0423e71ff601%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 6087 bytes --]
next prev parent reply other threads:[~2016-12-28 2:37 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-09 0:43 Luis Fernado Silva Castro de Araújo
[not found] ` <6c9b4eec-0ea9-46bf-8da3-51998b63c902-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-09-19 18:25 ` John MacFarlane
[not found] ` <20160919182539.GA9066-l/d5Ua9yGnxXsXJlQylH7w@public.gmane.org>
2016-09-22 5:11 ` Luis Fernado Silva Castro de Araújo
[not found] ` <be83b525-f6d9-4536-8271-53d80b3ffd5b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-09-23 8:35 ` John MacFarlane
[not found] ` <20160923083514.GI86115-BKjuZOBx5Kn2N3qrpRCZGbhGAdq7xJNKhPhL2mjWHbk@public.gmane.org>
2016-12-27 21:34 ` Luis Fernado Silva Castro de Araújo
[not found] ` <92666292-e593-4249-8ec2-ad37ceba79d2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-12-28 2:37 ` Sergio Correia [this message]
[not found] ` <719e577c-e900-4951-afb2-0423e71ff601-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-12-28 3:14 ` Luis Fernado Silva Castro de Araújo
[not found] ` <f979c153-7a62-41f9-a782-64532d1cee6b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-12-28 4:22 ` Sergio Correia
[not found] ` <13631c6c-5a3a-441a-8076-928182fc69b3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-12-28 6:06 ` Luis Fernado Silva Castro de Araújo
2016-12-28 16:01 ` BP Jonsson
[not found] ` <d7c214b7-ce07-cb9f-2c10-6714bab0c313-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-12-28 16:40 ` Sergio Correia
[not found] ` <45ddd0a9-2d80-496d-8706-8afa29803d26-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-12-29 0:08 ` BP Jonsson
[not found] ` <4fc0c0e2-3a27-2fed-3df7-e8ecb7a48a85-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-12-29 4:15 ` Sergio Correia
[not found] ` <1fdbe7b4-4b43-4989-af94-d50664ce6a7e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-12-29 22:44 ` Luis Fernado Silva Castro de Araújo
[not found] ` <6da29099-4a66-4489-8f6f-be8b2212b329-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-12-29 23:50 ` Luis Fernado Silva Castro de Araújo
[not found] ` <f5347462-26d3-4b8a-bc06-fdedfbd7c4f3-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-12-30 5:53 ` Sergio Correia
[not found] ` <659aafe6-54b9-496d-8c28-bd4384479960-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-01-01 21:09 ` BP Jonsson
[not found] ` <CAFC_yuSAZ3Tom2hXdq0_KviEjUVSMvMRrvWPQAZXOA83EHDAFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-02 2:08 ` Sergio Correia
[not found] ` <59f7d3c3-aadb-403b-aac8-6c158ff50777-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-01-03 3:33 ` Luis Fernado Silva Castro de Araújo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=719e577c-e900-4951-afb2-0423e71ff601@googlegroups.com \
--to=sergio.correia-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).