Hacker News new | ask | show | jobs
by contingencies 475 days ago
IMHO electron based markdown editors are generally slow, bloated, short-lived, and often platform-limited.

Use this and add sed lines for any required non-breakyness per normal CSS, rules can be specific to @media print as required.

  $ cat ~/bin/mdview 
  #!/bin/bash
  # markdown viewer
  tmpfile=.mdview.tmp-`uuidgen`.html
  # start html
  echo "<html><head><style>img{margin:20px;max-width:100%}@media print{img{max-height:90%;max-width:90%;page-break-after:always}}body{margin:6em;font-family:sans}pre,code{font-weight:bold;font-size:110%;font-family:Ubuntu Mono}</style></head><body>" >${tmpfile}
  # duplicate markdown for modification
  cp ${1} ${1}.mdtmp
  # add extra newline after trailing :
  sed -i -e 's/: \*$/:\r\r\n\n/' ${1}.mdtmp
  # generate HTML from markdown
  #  note the --html-no-skiphtml --html-no-escapehtml allows the preservation
  #  of <a name="blah"></a> anchors within text to allow [link][#anchorname]
  lowdown --html-no-skiphtml --html-no-escapehtml -thtml ${1}.mdtmp >>${tmpfile}
  # remove the temporary markdown file
  rm ${1}.mdtmp
  # add newline before images
  sed -i -e 's/<img/<br><img/' ${tmpfile}
  # view result
  firefox $tmpfile &
  # sleep for a short moment
  sleep 1.25
  # remove the temporary file
  rm ${tmpfile}