Standalone wysiwyg markdown editor

10
2013-10
  • jmad

    I seek a markdown editor (on unix/linux) with the following features:

    1. standalone – must edit local files (so probably not in javascript),
    2. wysiwyg – can write into the formatted output,
    3. editor – open and save markdown files (not something that just outputs code),
    4. live preview in editor mode.

    These features would be appreciated, too:

    1. clickable links,
    2. in wysiwyg mode, markdown code converted on the fly (if I type foo _bar_ then the bar is converted in italic)

    I know retext which is good but is not wysiwyg. Also the links are not clickable. Also gedit-markdown meets some of these features but is quite invasive. Basicly I want what kompozer does but for markdown.

    Does this editor exist?

    Should I even ask this question here? This is some kind of source code edition.

  • Answers
  • braveterry
  • Fyodor Sheremetyev

    Try Texts. There are versions for Windows and for Mac.

    Texts Screenshot


  • Related Question

    To convert markdown -files effectively to HTML -files
  • Masi

    I have the following file structure

    |--folder1
    |   |---1.markdown
    |--folder2
    |   |---2.markdown
    |--folder3
    |   |---3.markdown
    ...
    

    I would like to convert the markdown -files to HTML files such that the HTML -files are created to each specific folder. For instance 1.html should be at folder1.

    I can convert one markdown -file by

    markdown.py-2.6 1.markdown > 1.html
    

    So we should somehow be able to get the word before the suffix before each HTML files.

    How can you convert many markdown -files to their corresponding HTML files effectively?


  • Related Answers
  • evilsoup

    The existing bash-based answers will break on files with spaces in their names, and call unnecessary external commands to boot.

    Assuming bash 4+ is available (it probably is, check with bash --version), you can set globstar for recursive globbing:

    shopt -s globstar
    for f in ./**/*.markdown; do markdown.py-2.6 "$f" > "${f%.markdown}.html"; done
    

    This can also be done with find; for absolute bulletproof-ness, you should use a nullbyte delimiter:

    find . -name '*.markdown' -print0 | while read -d $'\0' f; do
      markdown.py-2.6 "$f" > "${f%.markdown}.html"
    done
    

    This particular problem could also be solved using find's -exec option, like so:

    find . -name '*.markdown' -exec bash -c 'markdown.py-2.6 "$0" > "${0%.markdown}.html" '{}' \;
    

    However, this is not as easy to extend to multi-line scripts.

  • jamuraa

    You can do this with a small bash script:

    for i in `find . -name "*.markdown"`; do 
      markdown.py-2.6 $i > `dirname $i`/`basename -s .markdown $i`.html
    done
    
  • quark

    You will probably find it easier to do this in bash (as in, once you understand the syntax it's only one or two lines), but for the record, here is how to do it in Python. You want to use two functions os.walk, and fnmatch.fnmatch to match the files you want in each directory. It looks like this:

    #!/usr/bin/env python
    
    import os, sys
    from fnmatch import fnmatch
    
    if len(sys.argv) != 2:
        print "Usage:", sys.argv[0], "<directory>"
        sys.exit()
    
    markdown = # <path to markdown.py>
    directory = sys.argv[1]
    
    for path, directory, files in os.walk(directory):
        for file in files:
            if fnmatch(file, "*.html"):
                html_file = "%s/%s" % (path, file)
                markdown_file = html_file.replace(".html", ".markdown")
                os.system("python %s %s > %s" % (markdown, markdown_file, html_file))
    

    The main things to take away:

    • The os.walk function traverses a directory structure (using an generator). It returns three variables:
      • The current directory (path)
      • The list of directories found in the current directory (directories). You don't need this in this case.
      • The list of files found in the current directory (files). You do need this.
    • The fnmatch.fnmatch function takes a list of files and tells you if it matches a pattern. This is a shell "glob" pattern, and not a regular expression. You can use regular expressions here, but fnmatch is just easier for a simple case like this.

    Note that you need to specify the path to the markdown script. Even better would be to not use os.system but instead to import markdown the module and call it's primary function, but this generalizes to non-Python programs. (Plus, I don't know exactly what that function would be :).

  • jtbandes

    A modification of jamuraa's answer:

    for i in `find . -name "*.markdown"`; do
      pushd `dirname $i`
      markdown.py-2.6 $i > `basename -s .markdown $i`.html
      popd
    done