Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Syntax highlighting: good, but I (should) have it already with Vim.
HTML preview: not really.
If the point of MD is "readable as is", that would narrow down what I want/imagined to: be able to use its links to other .md files automatically; seeing the formatting instead of the "source code" is nice, but not really necessary (where I have seen it, like *some bold text*). I imagine something similar to what the 'info' command does for documentation, which is browseable (to say the least).
Text mode: because I like it, because it should be enough for this. =)
This thread started because I stumbled in some documentation using Markdown: www.conversejs.org, and felt its format (with Vim, which is usually very good at highlighting several formats) a little clumsy. This documentation does not have cross-file links, but I know that Markdown may have, that is why I mentioned it.
And I have a few doubts in it, made here as comments:
Code:
#!/bin/bash
# Why /dev/shm? What is that? Why not /tmp? Because:
# http://www.cyberciti.biz/tips/what-is-devshm-and-its-practical-usage.html
tmpdir="/dev/shm" # must be writable
file="${tmpdir}/$(basename $1)-preview.html"
# Should I use my preferred graphical browser here?
# I do not have any of these programs.
# Possible option 1:
# browser='firefox'
# browser='opera'
# browser='links' # is this feasible?
#~ browser="/usr/bin/qupzilla -nw -pb"
#~ browser="uzbl-core -g 900x950 -n \"$(basename $1)\""
#~ browser="$BROWSER"
# "#~" is something special? No, just a comment, right?
# browser='dillo -f'
# Currently I do not have markdown. It should be installed, I assume. Right?
# I did not know about 'which'... (:
markdowncommand="$(which markdown)"
#debug:
#~ echo -e "$(date)\n$@\n$file" > ~/md-preview-test
echo '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>' > "$file"
echo "$(basename $1)" >> "$file"
echo '</title>
<style>
body {
background: #FFFCD9;
color: #1A1917;
padding: 0;
margin: 10px;
}
img {
max-width: 100%;
}
code, pre {
background: #E6DE8A;
}
code {
padding: 2px 2px 0 2px;
}
pre {
padding: 5px 5px 3px 5px;
margin: 0 10% 1rem 1rem;
}
</style>
</head>
<body>' >> "$file"
if [[ "$markdowncommand" == "" ]]
then
echo "<h2><code>markdown</code> not found.</h2>" >> "$file"
else
if [ "$#" != "1" ]
then
echo "<h2>Wrong number of arguments</h2>
<p>This argument list:
<pre>$@</pre>
is either too short or too long.
There should be only one argument.</p>
<p>Maybe you should enclose it in quotes: \"$@\"?</p>" >> "$file"
else
# THE MAIN PART OF THIS SCRIPT:
"$markdowncommand" "$1" >> "$file"
fi
fi
echo '</body></html>' >> "$file"
$browser "file://$file"
rm "$file"
Cannot wait to try it... (:
I imagine that with these questions I will be able to answer your previous post (to this one) and try something (probably after doing something).
No, I am not. That is the output that your script has in my computer, right now.
I read your script, trying to understand it, and made a few questions in my post above. You ignored them, which offended me a little. I did what you pointed, and that is the result. I hope someone else will answer the questions I have made.
Thank you, ondoho. I think this post is useful for more people with these confirmations. I added a few comments and formatting and ended with this script:
Code:
#!/bin/bash
# This script will call markdown to convert one .md file to html, and then
# call a browser. The browser may be changed as we prefer, and can be a
# textmode or graphical browser.
# /dev/shm or /tmp?
# http://www.cyberciti.biz/tips/what-is-devshm-and-its-practical-usage.html
#tmpdir='/tmp/ # must be writable
tmpdir="/dev/shm" # must be writable
file="${tmpdir}/$(basename $1)-preview.html"
# # # # # # # # #
# Uncomment just one preferred browser:
browser='links' # a great textmode browser
# browser='firefox'
# browser='opera'
# browser='links' # textmode
# browser="/usr/bin/qupzilla -nw -pb"
# browser="uzbl-core -g 900x950 -n \"$(basename $1)\""
# browser='dillo -f'
# # # # # # # # #
# Find where markdown is, if installed
markdowncommand="$(which markdown)"
#debug:
# echo -e "$(date)\n$@\n$file" > ~/md-preview-test
# # # # # # # # # # # #
# Mount the HTML file:
# header
echo '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>' > "$file"
# good title
echo "$(basename $1)" >> "$file"
# the rest of the header...
echo '</title>
<style>
body {
background: #FFFCD9;
color: #1A1917;
padding: 0;
margin: 10px;
}
img {
max-width: 100%;
}
code, pre {
background: #E6DE8A;
}
code {
padding: 2px 2px 0 2px;
}
pre {
padding: 5px 5px 3px 5px;
margin: 0 10% 1rem 1rem;
}
</style>
</head>
<body>' >> "$file"
# # # # # # # # # # # # # #
# Script's heart
# Found markdown?
if [[ "$markdowncommand" == "" ]]
then
echo "<h2><code>markdown</code> not found.</h2>" >> "$file"
else
if [ "$#" != "1" ]
then
echo "<h2>Wrong number of arguments</h2>
<p>There should be only one argument.</p>
<p>Maybe you should enclose it in quotes: \"$@\"?</p>" >> "$file"
else
"$markdowncommand" "$1" >> "$file"
fi
fi
# End the HTML file
echo '</body></html>' >> "$file"
# Ready, now show it
$browser "file://$file"
# Erase the file? Is shm cleared at every boot?
rm "$file"
Why do you spend your time answering if you only believe that I am trolling or that I just write the questions without looking around first? Please stop doing those unuseful posts, cancel your subscription for this thread: http://www.linuxquestions.org/questi...ewsubscription. Let other users answer the questions I make.
Is /dev/shm cleared at every boot, like /tmp is? /tmp files are deleted automatically when my system reboots, and I do not know if /dev/shm would too.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.