tag:support.markedapp.com,2011-09-11:/discussions/questions/237-rules-for-creating-custom-processorMarked: Discussion 2012-12-13T02:01:30Ztag:support.markedapp.com,2011-09-11:Comment/186217502012-09-09T17:50:31Z2012-09-09T17:50:31ZRules for creating custom processor<div><p>Anything you can run from the command line will work. Input is
passed via STDIN and needs to be returned as HTML to STDOUT. Use an
absolute path to the script and the rest will be handled
automatically.</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/186217502012-09-09T17:52:02Z2012-10-03T00:47:11ZRules for creating custom processor<div><p>Excellent. I'll probably get around to turning that template tag
into an easy script this week. Can't wait to try it out. Marked is
the missing piece of my blogging puzzle! Easy editing with VIM and
nice preview. Perfect combo.</p></div>durdenmisctag:support.markedapp.com,2011-09-11:Comment/186217502012-10-02T02:53:14Z2012-10-03T00:47:11ZRules for creating custom processor<div><p>I finally got around to creating my own little python script to
do some processing. The script appears to work by itself with
something like this:</p>
<p>cat markdownfile.md | short_code.py</p>
<p>The short_code.py just reads from stdin and uses 'print' to
write to stdout. When I run it from the command-line I don't see
any problems. However, when I connect this into marked app I just
see an empty file (with a correct word count). Is there an easy way
to debug what is going on?</p>
<p>I put my very rudimentary script as a <a href=
"https://gist.github.com/3815902">gist</a> if it helps to see
it.</p></div>durdenmisctag:support.markedapp.com,2011-09-11:Comment/186217502012-10-02T13:37:36Z2012-10-02T13:37:36ZRules for creating custom processor<div><p>Hm, I'm getting the same issue. I haven't tried to figure out
all of the code yet, but is there anything in there that depends on
environment variables aside from the hashbang? That wasn't the
issue, I tried hardcoding the path to the interpreter to no
avail.</p>
<p>When Marked executes the custom processor it does so in a
protected shell that won't have any of your normal path settings in
it. It may be worth creating a wrapper for the script that sets
PYTHONPATH before passing the input on to the Python script. Might
even just be unable to find the modules it needs to import, but
it's not giving me any console errors when it runs.</p>
<p>Let me know if you have any ideas along the environment line, if
not I'll see if I can figure out another possibility.</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/186217502012-10-02T13:47:53Z2012-10-03T00:47:11ZRules for creating custom processor<div><p>Ah, your onto something there. I know one problem is that I
might not have 2 of the modules I'm importing available in the
default 'env' python installation. I'm guessing when marked
executes the script it gets an ImportError.</p>
<p>However, this brings up a good point. Maybe marked should be
looking at the exit status of the script and display something. The
script will return a non-zero/failed status when the ImportError is
encountered.</p>
<p>I guess marked could also capture stdout and display it in the
case of a non-zero exit status? That kind of behavior would clearly
show what is happening in this particular case. However, in general
that might not always be helpful since it's highly dependent on the
script printing to stdout and/or stderr. Maybe this is something
for a future release?</p></div>durdenmisctag:support.markedapp.com,2011-09-11:Comment/186217502012-10-02T13:50:27Z2012-10-03T00:47:12ZRules for creating custom processor<div><p>I can't access the code right now, but I'm guessing I could just
use the os.setenv API to set my PYTHONPATH to a location where I
know those missing modules are installed?</p>
<p>Also, does the custom processor script run before, after, or
completely replace marked's processing of the markdown text? In my
case I can do the syntax highlighting in my script, but it requires
a few more dependencies. It's not a huge deal, but I wasn't sure
how the custom processor script actually worked in relation to the
default marked processing.</p></div>durdenmisctag:support.markedapp.com,2011-09-11:Comment/186217502012-10-02T14:17:00Z2012-10-02T14:17:00ZRules for creating custom processor<div><p>It completely replaces the Markdown processor. Syntax
highlighting in Marked is done via JavaScript, so if you run your
own pygments-based (or whatever) highlight, just make sure to
disable the highlighter in preferences.</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/186217502012-10-03T00:16:12Z2012-10-03T00:47:12ZRules for creating custom processor<div><p>Brett,</p>
<p>Thanks so much for the help. The only problem was my environment
setup. I just hard-coded my path so the missing modules could be
found and had no issues.</p>
<p>I updated my <a href="https://gist.github.com/3815902">gist</a>
with the changes just for reference. I'll be cleaning up that
script quite a bit now that I know it will all work. Thanks again!
Love the app and the vim integration!</p></div>durdenmisc