Rules for creating custom processor
What are the requirements/rules for creating a custom processor script? I help run a blogging platform for programmers, http://codrspace.com, that allows markdown editing along with some additional syntax for rendering github gists, etc. Most of our markdown processing is done with a Django template tag that could easily be put into a stand-alone script.
So, what all do I need to look out for when writing this script? Does it have to be ruby (our app is Python) or can it be anything I can execute from the command-line? Does the script just take the text as an argument and return HTML?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | 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
Support Staff 1 Posted by Brett on 09 Sep, 2012 05:50 PM
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.
2 Posted by durdenmisc on 09 Sep, 2012 05:52 PM
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.
Brett closed this discussion on 24 Sep, 2012 11:54 PM.
durdenmisc re-opened this discussion on 02 Oct, 2012 02:53 AM
3 Posted by durdenmisc on 02 Oct, 2012 02:53 AM
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:
cat markdownfile.md | short_code.py
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?
I put my very rudimentary script as a gist if it helps to see it.
Support Staff 4 Posted by Brett on 02 Oct, 2012 01:37 PM
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.
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.
Let me know if you have any ideas along the environment line, if not I'll see if I can figure out another possibility.
5 Posted by durdenmisc on 02 Oct, 2012 01:47 PM
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.
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.
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?
6 Posted by durdenmisc on 02 Oct, 2012 01:50 PM
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?
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.
Support Staff 7 Posted by Brett on 02 Oct, 2012 02:17 PM
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.
8 Posted by durdenmisc on 03 Oct, 2012 12:16 AM
Brett,
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.
I updated my gist 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!
durdenmisc closed this discussion on 03 Oct, 2012 12:47 AM.