less-style markdown viewer for UNIX systems

后端 未结 9 1429
刺人心
刺人心 2020-12-22 21:39

I have a Markdown string in JavaScript, and I\'d like to display it (with bolding, etc) in a less (or, I suppose, more)-style viewer for the comman

9条回答
  •  一整个雨季
    2020-12-22 22:37

    I personally use this script:

    #!/bin/bash
    id=$(uuidgen | cut -c -8)
    markdown $1 > /tmp/md-$id
    google-chrome --app=file:///tmp/md-$id
    

    It renders the markdown into HTML, puts it into a file in /tmp/md-... and opens that in a kiosk chrome session with no URI bar etc.. You just pass the md file as an argument or pipe it into stdin. Requires markdown and Google Chrome. Chromium should also work but you need to replace the last line with

    chromium-browser --app=file:///tmp/md-$id
    

    If you wanna get fancy about it, you can use some css to make it look nice, I edited the script and made it use Bootstrap3 (overkill) from a CDN.

    #!/bin/bash
    id=$(uuidgen | cut -c -8)
    markdown $1 > /tmp/md-$id
    sed -i "1i " /tmp/md-$id
    echo "" >> /tmp/md-$id
    google-chrome --app=file:///tmp/md-$id > /dev/null 2>&1 &
    

提交回复
热议问题