LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Is there a Markdown text mode viewer? (https://www.linuxquestions.org/questions/linux-software-2/is-there-a-markdown-text-mode-viewer-4175588731/)

dedec0 09-04-2016 06:23 PM

Is there a Markdown text mode viewer?
 
Is there a Markdown (.md files) text mode viewer for linux?

I see that there are some with windows, graphical, but I want one that will inherit my terminal colors with the features that these files may have.

(=

ondoho 09-05-2016 01:48 AM

what do you want?

syntax highlighting for markdown? i think all IDEs have that.

a preview of the html? make yourself a script (*).

why in text mode? the whole point of markdown is that it is readable as-is, in text mode.

(*)
Code:

#!/bin/bash

tmpdir="/dev/shm" # must be writable
file="${tmpdir}/$(basename $1)-preview.html"

#~ browser="/usr/bin/qupzilla -nw -pb"
#~ browser="uzbl-core -g 900x950 -n \"$(basename $1)\""
#~ browser="$BROWSER"
browser='dillo -f'
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
                "$markdowncommand" "$1" >> "$file"
        fi
fi

echo '</body></html>' >> "$file"

$browser "file://$file"
rm "$file"


dedec0 09-05-2016 07:11 AM

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. =)

dedec0 09-05-2016 08:55 AM

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.

ondoho 09-05-2016 11:54 AM

Quote:

Originally Posted by dedec0 (Post 5600724)
Is there a Markdown (.md files) text mode viewer for linux?

Quote:

Originally Posted by dedec0 (Post 5600930)
be able to use its links to other .md files automatically;

no, i still don't get it.

what other .md files?
you want clickable links? try my script.
or do you want only "half-way" formatting? use a textmode browser with my script.

or something else entirely? :scratch:

dedec0 09-06-2016 07:01 AM

But how do I use your script?

Is it "[name of its file] <md filename>" ?

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).

ondoho 09-07-2016 01:31 PM

Quote:

Originally Posted by dedec0 (Post 5601407)
But how do I use your script?

Code:

scriptname file.md

dedec0 09-07-2016 01:44 PM

Quote:

Originally Posted by ondoho (Post 5602013)
Code:

scriptname file.md

Really? It is not. From my terminal now:

Code:

15:42:03 me@there:~
$ ./md.sh README.md
./md.sh: line 65: dillo: command not found
15:42:11 me@there:~
$

I wrote more, there. You do not seem to have read it.

ondoho 09-07-2016 02:30 PM

^ you're trolling me, right?

dedec0 09-07-2016 02:39 PM

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.

ondoho 09-07-2016 03:26 PM

:sigh:

ok, you obviously need markdown to parse markdown to html, so just
Code:

apt-get install markdown
or whatever the equivalent command on your system is.

then you need a command line for a browser of your choice to open a local html file. most browsers, you just use "browser file.html".

dillo is a graphical browser, but extremely lightweight.

i understand you have a wish for doing things non-gui, so just replace dillo with e.g. w3m or links or whatevs.

and yes, use /tmp for the queen's sake.

dedec0 09-07-2016 04:44 PM

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"


dedec0 09-07-2016 04:49 PM

Is /dev/shm cleared at every boot, like /tmp is?

ondoho 09-07-2016 11:28 PM

Quote:

Originally Posted by dedec0 (Post 5602122)
Is /dev/shm cleared at every boot, like /tmp is?

do some research yourself, for $deity's sake.
on your machine:
Code:

mount
on the www:
https://lmddgtfy.net/?q=Is%20%2Fdev%...0like%20%2Ftmp

dedec0 09-08-2016 06:24 AM

Quote:

Originally Posted by ondoho (Post 5602256)
do some research yourself, for $deity's sake.
on your machine:
Code:

mount
on the www:
https://lmddgtfy.net/?q=Is%20%2Fdev%...0like%20%2Ftmp

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.


All times are GMT -5. The time now is 07:54 PM.