How to run a Python preprocessor?

Thomas's Avatar

Thomas

17 Mar, 2017 10:04 AM

OK, very basic question: since I use a lot of asterisks (*) to denote reconstructed word-forms, I do not use asterisks for italics in Markdown, and I would like to avoid typing “\*” all the time. So I thought the best way to solve this problem would be to use a custom preprocessor that inserted a “\” before any asterisk.

I think I could do this in Python, but I can’t find out how I get in contact with my Python script. I have added a path to a Python script under “Advanced” in Marked preferences (see screenshot), but the script doesn’t seem to be run, or at least nothing happens in the rendering of my text in Marked. Any ideas as to what I could be doing wrong would be welcome. Also, is there an easy way to check if the script is actually run?

Thomas

  1. 1 Posted by Thomas on 17 Mar, 2017 10:14 AM

    Thomas's Avatar

    Now I found out that when I press the little white “Toggle Custom Preprocessor” circle in the Marked window, Marked crashes.

    Thomas

  2. 2 Posted by Thomas on 20 Mar, 2017 12:55 PM

    Thomas's Avatar

    OK, it works now. The problems were due to a lack of the most basic understanding of coding on my part. Here is what my Python script looks like:

    #!/usr/bin/env python
    #coding: utf-8
    import sys, re
    for line in sys.stdin:
        print(re.sub('*', '\*', line))
    
    Thomas
  3. 3 Posted by Thomas on 20 Mar, 2017 12:59 PM

    Thomas's Avatar

    (Line 5 should be “print(re.sub('\*', '\\\*', line))”.)

  4. Support Staff 4 Posted by Brett on 21 Mar, 2017 09:34 PM

    Brett's Avatar

    Sorry for the delayed reply, I'm glad it's working. I'd be curious what was going wrong, I hate the idea of Marked crashing instead of offering a graceful error notification.

  5. 5 Posted by Thomas on 22 Mar, 2017 08:07 AM

    Thomas's Avatar

    If I use the following Python script as a preprocessor, Marked 2 (Version 2.5.10 (930)) consistently crashes:

    #!/usr/local/bin/python
    print 'hello'
    
    Thomass
  6. Support Staff 6 Posted by Brett on 22 Mar, 2017 03:40 PM

    Brett's Avatar

    For testing on my end, are you on the MAS or direct (Paddle) version?

    -Brett

  7. 7 Posted by Thomas on 22 Mar, 2017 06:31 PM

    Thomas's Avatar

    I’m on the direct version via Paddle.
    By the way, I should have mentioned that I really like Marked (if not I wouldn’t have bothered to ask for help).
    Thomas

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • marked-preprocessor.png 33.1 KB

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

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