preprocessor script help

aaaaaa's Avatar


24 Oct, 2023 03:25 AM

Despite my lack of programming skills, I've managed to create two similar preprocessor scripts that I frequently switch between. I use one for previewing in Marked as I work in real time, and I switch to the other one when I'm exporting to PDF or DOCX.

When I use pandoc as my processor, these preprocessors allow me to turn pandoc-flavor citations (ie. [@author2023]) into clickable hyperlinks using zotero:// URLs that open my local citation manager. Normally, since the syntax for markdown hyperlinks and pandoc citations conflict with each other, writing [@author2023](zotero://open-pdf/library/items/R3RXLUWV) fails to render a proper parenthetical citation. These preprocessor scripts fix the issue.

I'm hoping somebody here could help me merge these two scripts into one. I'd like to be able to include a custom metadata variable in my documents called something like hide_zotero_links to toggle between these two scripts by passing it an argument. How might I go about doing something like that?

cat | sed -E 's/\[(-?@[[:lower:]]{1,6}[[:digit:]]{4}[[:lower:]]?_[[:alnum:]]{4}, p\. [[:digit:]]*)\]\((zotero:\/\/open-pdf\/library\/items\/[[:alnum:]]{8}\?page=[[:digit:]]*(&annotation=[[:alnum:]]{8})?)\)/<a href="\2">\[\1\]<\/a>/g'
cat | sed -E 's/\[(-?@[[:lower:]]{1,6}[[:digit:]]{4}[[:lower:]]?_[[:alnum:]]{4}, p\. [[:digit:]]*)\]\((zotero:\/\/open-pdf\/library\/items\/[[:alnum:]]{8}\?page=[[:digit:]]*(&annotation=[[:alnum:]]{8})?)\)/\1/g'
  1. Support Staff 1 Posted by Brett on 24 Oct, 2023 02:16 PM

    Brett's Avatar

    Ok, a few options. First, if the difference between the files happens to
    be location or extension based, e.g. the zotero link files are in one
    folder and the non-zotero are in another folder, you could split the
    script using MARKED_PATH or MARKED_EXT. But assuming that's not the
    case, you'd want your script to be able to read the YAML headers and do
    an if/else with the processing lines. This could be as simple as just
    using grep to see if the content contains "zotero_links: true", or by
    using a command line YAML tool like `shaml`. If it were me, I'd be doing
    this whole thing in Ruby, which would make processing the YAML a little

    It looks like the regex is matching something like your example
    `[@author2023](zotero://open-pdf/library/items/R3RXLUWV)`, correct? And
    then just either substituting the `[@author2023]` part or inserting an
    HTML link, depending on the context. If that's correct, I can whip it
    out in Ruby in a few minutes... I guarantee it will be a little easier
    to read and forking on a YAML key would be no issue.


    On 23 Oct 2023, at 22:27, aaaaaa wrote:

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac