less-style markdown viewer for UNIX systems

后端 未结 9 1308
刺人心
刺人心 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:25

    Using OSX I prefer to use this command

    brew install pandoc
    pandoc -s -f markdown -t man README.md | groff -T utf8 -man | less
    

    Convert markupm, format document with groff, and pipe into less

    credit: http://blog.metamatt.com/blog/2013/01/09/previewing-markdown-files-from-the-terminal/

    0 讨论(0)
  • 2020-12-22 22:27

    I'll post my unix page answer here, too:

    An IMHO heavily underestimated command line markdown viewer is the markdown-cli.

    Installation

    npm install markdown-cli --global
    

    Usage

    markdown-cli <file>
    

    Features

    Probably not noticed much, because it misses any documentation...
    But as far as I could figure out by some example markdown files, some things that convinced me:

    • handles ill formatted files much better (similarly to atom, github, etc.; eg. when blank lines are missing before lists)
    • more stable with formatting in headers or lists (bold text in lists breaks sublists in some other viewers)
    • proper table formatting
    • syntax highlightning
    • resolves footnote links to show the link instead of the footnote number (not everyone might want this)

    Screenshot

    example.png

    Drawbacks

    I have realized the following issues

    • code blocks are flattened (all leading spaces disappear)
    • two blank lines appear before lists
    0 讨论(0)
  • 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 <html><head><style>body{padding:24px;}</style><link rel=\"stylesheet\" type=\"text/css\" href=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css\"></head><body>" /tmp/md-$id
    echo "</body>" >> /tmp/md-$id
    google-chrome --app=file:///tmp/md-$id > /dev/null 2>&1 &
    
    0 讨论(0)
提交回复
热议问题