LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 09-04-2016, 06:23 PM   #1
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,010

Rep: Reputation: 34
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.

(=
 
Old 09-05-2016, 01:48 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,639
Blog Entries: 9

Rep: Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755
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"
 
Old 09-05-2016, 07:11 AM   #3
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,010

Original Poster
Rep: Reputation: 34
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. =)
 
Old 09-05-2016, 08:55 AM   #4
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,010

Original Poster
Rep: Reputation: 34
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.
 
Old 09-05-2016, 11:54 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,639
Blog Entries: 9

Rep: Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755
Quote:
Originally Posted by dedec0 View Post
Is there a Markdown (.md files) text mode viewer for linux?
Quote:
Originally Posted by dedec0 View Post
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?
 
Old 09-06-2016, 07:01 AM   #6
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,010

Original Poster
Rep: Reputation: 34
Question

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

Last edited by dedec0; 09-06-2016 at 09:22 AM.
 
Old 09-07-2016, 01:31 PM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,639
Blog Entries: 9

Rep: Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755
Quote:
Originally Posted by dedec0 View Post
But how do I use your script?
Code:
scriptname file.md
 
Old 09-07-2016, 01:44 PM   #8
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,010

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by ondoho View Post
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.
 
Old 09-07-2016, 02:30 PM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,639
Blog Entries: 9

Rep: Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755
^ you're trolling me, right?
 
Old 09-07-2016, 02:39 PM   #10
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,010

Original Poster
Rep: Reputation: 34
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.
 
Old 09-07-2016, 03:26 PM   #11
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,639
Blog Entries: 9

Rep: Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755
: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.
 
Old 09-07-2016, 04:44 PM   #12
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,010

Original Poster
Rep: Reputation: 34
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"
 
Old 09-07-2016, 04:49 PM   #13
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,010

Original Poster
Rep: Reputation: 34
Is /dev/shm cleared at every boot, like /tmp is?
 
Old 09-07-2016, 11:28 PM   #14
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,639
Blog Entries: 9

Rep: Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755Reputation: 3755
Quote:
Originally Posted by dedec0 View Post
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
 
Old 09-08-2016, 06:24 AM   #15
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,010

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by ondoho View Post
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.

Last edited by dedec0; 09-08-2016 at 06:33 AM.
 
  


Reply

Tags
markdown


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Best image viewer,djvu viewer pdf viewer cd/dvd writer for debian 7 rubankumars Debian 2 05-15-2013 08:23 AM
LXer: ReText 3.0 Released (Text Editor For Markdown And reStructuredText) LXer Syndicated Linux News 0 03-09-2012 03:41 PM
LXer: ReText: A Text Editor with Support for reStructuredText and Markdown LXer Syndicated Linux News 0 11-24-2011 08:21 PM
LXer: Howto Boot debian in text mode instead of graphical mode (GUI) LXer Syndicated Linux News 0 09-09-2007 07:41 PM
less (the text viewer) configuration zokik Linux - General 1 08-17-2003 05:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration