A script to restore MMD footnotes in Scrivener

I’ve written a little Perl script that reformats MultiMarkdown footnotes with Scrivener’s special syntax for inline footnotes. In other words, it turns this:

[code]Footnotes are very easy to implement in MultiMarkdown, as described in the MultiMarkdown Syntax Guide.[^somesamplefootnote]

[^somesamplefootnote]: Here is the text of the footnote itself.[/code]

back into this:

Bild 1.png

The script takes two arguments:

$ perl mmd2scriv.pl Inputfile.txt Outputfile.txt

There’s also a droplet version of the script, that writes its output to “.txt” (I know, this is stupid…did you read the disclaimer?)

I can’t guarantee that the script is 100% fail-safe as it still needs some thorough testing. Feel free to experiment :stuck_out_tongue:

Oh, in case you’re wondering why anyone would need something like this: The script makes it a bit more convenient to exchange files between Scrivener and gedit, which is the editor that runs on my Acer Aspire One:


Interesting. I tend to keep my footnotes in MMD syntax anyway, but this is still a neat trick.


a very useful script - how do I install it as a service in 10.6 ?

I tried the “run shell script” command in automator, with the usr/bin/perl shell and the copied script either as an argumet or “to stdin”, whatever this means - I have no experience in perl, and I can’t get it to work.

Getting this script to work as a service would be very useful - I frequently write text on my iPod touch and it would be great to use mmd syntax fr footnotes on the go! Finally, this is the missing link!

Any ideas?

That might not be a good idea. The script is intended to run against a text file as source, not an RTFD file as source. If you did run it against an open document in the buffer, strange things might happen. I haven’t tested it though, so I’m just speculating.

For making a service out of this script, you’ll need to alter it to work with STDIN and STDOUT instead of file points. Service scripts need STDIN to get the buffer data, and what they produce to STDOUT will be written back to the buffer. It’s a UNIX thing. Command line applications use these two pipes to handle real-time data.

Honestly it probably just be easier (and maybe safer) to open Terminal and run the script when you need it. :slight_smile:

Here’s a slightly modified perl script wrapped up in a Snow Leopard service. Open the workflow in Automator and save it under a new name to install it. I’m not sure if the Perl code is quite right, but it shouldn’t be harmful as long as you can still undo the replacement. The service only works in applications that use the OS X text system (Scrivener, Textedit, etc.), which apparently is a limitation of Automator’s shell script services (?). It won’t do you much good in TextWrangler. :wink:

EDIT: The easiest way to use this in TextWrangler is to create a “Unix Filter”. Simply copy the script from Automator and save it as a .pl file in ~/Library/Application Support/TextWrangler/Unix Support/Unix Filters/

Great Script. It is of great help in going back and forth from Scrivener to MMD in text only wordprocessor (such as WriteRoom on Iphone/Ipod).
It would be great if someone could create a script that does something similar with annotations.
Annotations are not recognized as such by MMD in the text conversion (they can in converting to LaTeX, but this is not what I’m looking for).

RIght now I mark the beginning of an annotation with ≤ and the end with ≥
so that I can recognize them in the text file, but when I import the text back to Scrivener I have to manually restore the annotations. I wish I knew perl to write the script myself. Anyone could help? Or offer some other solution to restore annotations in Scrivener? Thanks

Here’s a simple script that uses STDIN/STDOUT:

[code]#!/usr/bin/perl -w

while (<>) {
s/≤/{\SCRV_ANNOT \COLOR={\R=1.0\G=0.0\B=0.0} \TEXT=/g;
perl scriptname.pl file1.txt > file2.txt

This should also work with Automator Services or as a “Unix Filter” in TextWrangler.

Great ! Thanks a lot.
I just made a small change to the script so that the markers for the annotations (≤ and ≥ ) are preserved when converting back into Scrivener so that I can still go back and forth from Scrivener and MMD txt files

[code]#!/usr/bin/perl -w

while (<>) {
s/≤/{\SCRV_ANNOT \COLOR={\R=1.0\G=0.0\B=0.0} \TEXT=≤/g;

I hate to admit it, but either the script does not function properly, or there is an error on my side of the Leine. After saving the service in Automator, I tried the script with the MMD example text, but it only renders


[^footnote]: this is the footnote text

to the following:

Test{\SCRV_FN=this is the footnote text\END_SCRV_FN}

Venting my inability to fix the problem, at least I managed to install pandoc, which is great for converting to odt format and such. But still, one-click conversion in scrivener would be the icing on the cake.

Anyway, thanks for your help!

(By the way, speaking about fixing stuff:slight_smile: )

Have you tried importing the documents with the result you posted into Scrivener? That’s a Scrivener footnote by the way, not an RTF footnote. It won’t do anything anywhere except in Scrivener. You can even copy and paste that code you posted right into Scrivener, re-open the project, and it will turn into a footnote. I just tried this myself:

Amber, that did it - thank you! Maybe Apimac’s clean text can save a few clicks in the future, but I am glad this is finally working more or less by itself. My iPod touch has just become a footnote machine!