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.

ondoho 09-08-2016 10:27 AM

Quote:

Originally Posted by dedec0 (Post 5602368)
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.

why do you spend your time being hurt and telling me what to do (i will bloody well do as i please, thank you very much), instead of following my suggestions (it was you who asked after all)?

just try it, type "mount" in a terminal, press enter, and see what you see for /dev/shm and /tmp.

enough spoonfeeding.

dedec0 09-08-2016 11:01 AM

I did the mount command, found shm there... but what? Here:

Code:

$ mount
/dev/sdb5 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
none on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
gvfs-fuse-daemon on /home/ubuntu/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=ubuntu)
/dev/sdb1 on /media/A type vfat (rw,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,flush)
/dev/sda2 on /media/B type fuseblk (rw,nosuid,nodev,allow_other,blksize=4096,default_permissions)
/dev/sdc1 on /media/C type fuseblk (rw,nosuid,nodev,allow_other,blksize=4096,default_permissions)
12:53:24 [  0] me@here: ~
$

/tmp is not there (not alone) ...

Quote:

Tmpfs
tmpfs is a common name for a temporary file storage facility on many Unix-like operating systems. It is intended to appear as a mounted file system, but stored in volatile memory instead of a persistent storage device. A similar construction is a RAM disk, which appears as a virtual disk drive and hosts a disk file system. More at Wikipedia
Is this what I should have guessed before? It is a word. You are too different from what I have found many many times in these fora. I am glad that there are many users different from you in these aspects. Bye

dugan 09-08-2016 11:24 AM

pandoc can convert from markdown to txt and send the output to the console, can't it?

dugan 04-09-2018 12:00 PM

There is now:

https://github.com/joeyespo/grip

ondoho 04-11-2018 11:51 AM

^ that is a lot of code to view something that is designed to be human-readable anyhow.


All times are GMT -5. The time now is 10:20 AM.