Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 16 Nov 2018, 05:45
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
mdview, a markdown viewer
Post new topic   Reply to topic View previous topic :: View next topic
Page 3 of 5 [63 Posts]   Goto page: Previous 1, 2, 3, 4, 5 Next
Author Message
musher0

Joined: 04 Jan 2009
Posts: 12972
Location: Gatineau (Qc), Canada

PostPosted: Wed 13 May 2015, 17:08    Post subject:  

@jamesbond:
Thanks for shedding much needed add'l light on the subject.

BFN.

musher0

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 3431
Location: www.eussenheim.de/

PostPosted: Fri 15 May 2015, 09:51    Post subject: run action
Subject description: text_x-markdown
 

01micko wrote:
How about a run action?

Code:
#!/bin/sh
DIR=${@%/*}
FILE=${@##*/}
HOME=$FILE
TITLE=${FILE%.*}
mdview $DIR $FILE "$HOME" "$TITLE"


text_x-markdown (replace the current symlink in fatdog)

In older pups with older shared-mime-info it is reported wrongly as application_x-genesis-rom .. see https://bugs.freedesktop.org/show_bug.cgi?id=27441


Excellent.
Extended for use in Fatdog's Help-Home&FAQ:
Code:
#! /bin/sh

DIR=${@%/*}
FILE=${@##*/}
TITLE=${FILE%.*}

case $DIR in
 /usr/share/doc/faqs)  # fd64-701
  HOME=index.md
  TEXTDOMAIN=fatdoghelp mdview -x $DIR $FILE "$HOME" "$TITLE"
  ;;
 *)
  HOME=$FILE
  mdview $DIR $FILE "$HOME" "$TITLE"
  ;;
esac

This way it can easily be further extended.
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 8680
Location: qld

PostPosted: Sat 16 May 2015, 16:29    Post subject:  

Dunno what on earth I was thinking ( Rolling Eyes Laughing ), but maybe $HOME should be something else as to not cause conflict with the environmental variable, user's $HOME.
_________________
Puppy Linux Blog - contact me for access
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 3431
Location: www.eussenheim.de/

PostPosted: Sun 17 May 2015, 06:00    Post subject: mdview, a markdown viewer
Subject description: conflict
 

01micko wrote:
Dunno what on earth I was thinking ( Rolling Eyes Laughing ), but maybe $HOME should be something else as to not cause conflict with the environmental variable, user's $HOME.


Maybe it is not always necessary to think much Rolling Eyes
I had not noticed any conflict. Cool

This HOME is mdview s Home (just the icon I am thinking now).
In Fatdog Help the Home icon refers to index.md
and Home has to be a link of its own....

Another non issue: TEXTDOMAIN does work without being exported.
HOME.png
 Description   LOL
 Filesize   15.46 KB
 Viewed   461 Time(s)

HOME.png

Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 3431
Location: www.eussenheim.de/

PostPosted: Mon 18 May 2015, 09:34    Post subject: Re: mdview, a markdown viewer
Subject description: conflict
 

L18L wrote:
01micko wrote:
Dunno what on earth I was thinking ( Rolling Eyes Laughing ), but maybe $HOME should be something else as to not cause conflict with the environmental variable, user's $HOME.


Maybe it is not always necessary to think much Rolling Eyes
I had not noticed any conflict. Cool


Yes you are right!
There is a conflict of course.

I have renamed HOME to thisHOME
... and added README

my /etc/xdg/rox.surceforge.net/MIME-types/text_x-markdown wrote:
#! /bin/sh

DIR=${@%/*}
FILE=${@##*/}
TITLE=${FILE%.*}
thisHOME=$FILE

case $FILE in
README*)
mdview -x $DIR $FILE "$thisHOME" "$TITLE"
;;
esac

case $DIR in
/usr/share/doc/faqs)
thisHOME=index.md
TITLE=Fatdog64
TEXTDOMAIN=fatdoghelp mdview -x $DIR $FILE "$thisHOME" "$TITLE"
;;
*)
mdview $DIR $FILE "$thisHOME" "$TITLE"
;;
esac
README.md.png
 Description   
 Filesize   39.81 KB
 Viewed   447 Time(s)

README.md.png

Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 3431
Location: www.eussenheim.de/

PostPosted: Mon 18 May 2015, 14:53    Post subject: mdview, a markdown viewer  

Suggest this /etc/xdg/rox.surceforge.net/MIME-types/text_x-markdown:
Code:
#! /bin/sh

[ $(readlink $@) ] && FILE=$(readlink $@) || FILE=$@

DIR=${@%/*}
FILE=${FILE##*/}
TITLE=${FILE%.*}
thisHOME=$FILE
thisTEXTDOMAIN=$TEXTDOMAIN

case $FILE in
 README*)
  TITLE=${@%.*}
  thisTEXTDOMAIN=README
  ;;
esac

case $DIR in
 /usr/share/doc/faqs)
  thisHOME=index.md
  TITLE=Fatdog64
  thisTEXTDOMAIN=fatdoghelp
  ;;
esac

TEXTDOMAIN=$thisTEXTDOMAIN mdview -x $DIR $FILE "$thisHOME" "$TITLE"

tested with translated README.md
LIESMICH.md symlinked
README_gettexted.png
 Description   
 Filesize   25.97 KB
 Viewed   552 Time(s)

README_gettexted.png

Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 3168
Location: The Blue Marble

PostPosted: Tue 19 May 2015, 11:36    Post subject:  

Following suggestion by disciple, the latest fossil version of mdview now supports output to console (stdout), as plain text (--text), text with vt100 codes (bold/color, works with urxvt/xterm/console) (--tty), and as html (--html); so in a way it is now compatible with "mad" (or in other words, subsumes "mad" functionality for converting markdown to decorated text).

Pipe --tty output to "less -R" for paging, if wished.

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread.
Back to top
View user's profile Send private message 
step

Joined: 04 May 2012
Posts: 1099

PostPosted: Tue 19 May 2015, 13:57    Post subject:  

jamesbond wrote:
Following suggestion by disciple, the latest fossil version of mdview now supports output to console (stdout), as plain text (--text), text with vt100 codes (bold/color, works with urxvt/xterm/console) (--tty), and as html (--html); so in a way it is now compatible with "mad" (or in other words, subsumes "mad" functionality for converting markdown to decorated text).

Pipe --tty output to "less -R" for paging, if wished.
Great. Markdown was also born to be neat and readable on terminals. This feature makes a lot of sense. Thanks.
_________________
Fatdog64-800|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
charlie6


Joined: 30 Jun 2008
Posts: 1211
Location: Saint-Gérard / Walloon part of Belgium

PostPosted: Mon 01 Jun 2015, 10:36    Post subject: GLIB error opening html files  

Hi jamesbond,

i got mdview compiled on wheezy-3.5.2.11;
it opens the .md file coming with the tarball file (file.md, README.md, index.md)

i'd hope to open html files as the ones present in /usr/share/doc using the following command line:


Code:
# mdview --html /usr/share/doc/ pburn.html

(process:29936): GLib-GObject-CRITICAL **: /build/buildd-glib2.0_2.33.12+really2.32.4-5-i386-eISom6/glib2.0-2.33.12+really2.32.4/./gobject/gtype.c:2722: You forgot to call g_type_init()

(process:29936): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed

(process:29936): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed
^C


although this displays the raw pburn.html:
Code:
# mdview -x /usr/share/doc pburn.html


I might have missed something...
Could you help me please ?

Thanks in advance
Charlie
mdview_pbrun.dothtml.jpg
 Description   # mdview -x /usr/share/doc pburn.html
 Filesize   38.84 KB
 Viewed   464 Time(s)

mdview_pbrun.dothtml.jpg

Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 3431
Location: www.eussenheim.de/

PostPosted: Tue 02 Jun 2015, 10:34    Post subject: Re: GLIB error opening html files  

Hi charlie6,

html is markup language
and md means mark down which is much simpler.

You might have expected to get an html viewer.
But it is a md viewer.

mdview --html generates fragments of html.

If you like to see pburn in markdown see attached file.
(It was just fun to copy it from browser into the .md file and do a few modifications)
pburn.md.gz
Description  remove fake .gz and have fun
gz

 Download 
Filename  pburn.md.gz 
Filesize  14.99 KB 
Downloaded  222 Time(s) 
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 3431
Location: www.eussenheim.de/

PostPosted: Tue 02 Jun 2015, 13:49    Post subject: mdview, a markdown viewer
Subject description: md-translator.sh a tool for translating .md file(s)
 

Made in Fatdog64_701 where
xgettext msguniq msgunfmt msgmerge msgfmt
are included.
Code:
#!/bin/sh

TITLE='translate .md files'

usage () {
  die  "
  Create / edit translation file (GNU message catalog) from md files
  usage: $0 [file.md|directory]
 
    case file.md then each file under /etc /root /usr /var  will be processed
    in case of directory then each file *.md in this directory will be processed   
       
   example 1: $0 README.md
   example 2: $0 /usr/share/doc/faqs/
   
   At least one file must contain %%textdomain <TEXTDOMAIN>
   Translation is stored in $TEXTDOMAIN/${LANG%_*}/LC_MESSAGES/<TEXTDOMAIN>.mo
   Existing translations are always being re-used (msgmerge)
 "   
}

die () { [ $DISPLAY ] && Xdialog --title="$TITLE" --msgbox "$1" 0 0 || echo $1; exit 1; }

[ `whoami` = root ] || die "This tool is for root only."

create_pot () {
  # create ${WD}/${aTEXTDOMAIN}.pot file from .md file(s) using xgettext and mdview --po
  aTEXTDOMAIN=$1
  FILES=$2
  local MD=MD$$
 
  echo " " | xgettext -o ${WD}/${aTEXTDOMAIN}_.pot -L shell --package-name=$aTEXTDOMAIN --from-code=UTF-8 --force-po -
  sed -i 's/charset=CHARSET/charset=UTF-8/' ${WD}/${aTEXTDOMAIN}_.pot
  echo "" >> ${WD}/${aTEXTDOMAIN}_.pot

  for aFILE in $FILES; do
    grep -v '$(g' ${aFILE} > $MD
    mdview --po        ""   $MD >> ${WD}/${aTEXTDOMAIN}_.pot
    xgettext -L shell $aFILE -j -o ${WD}/${aTEXTDOMAIN}_.pot
  done

  msguniq -u --to-code=UTF-8 -o ${WD}/${aTEXTDOMAIN}.pot ${WD}/${aTEXTDOMAIN}_.pot
  rm ${WD}/${aTEXTDOMAIN}_.pot
  rm $MD
}

create_po () {
  aTEXTDOMAIN=$1
  if [ -f "${TRANSLATED}" ]; then
    msgunfmt ${TRANSLATED} -o - > ${WD}/${aTEXTDOMAIN}_OLD.po
  else
    urxvt -e msginit --no-translator --no-wrap --locale=${transLANG} --input=${WD}/${aTEXTDOMAIN}.pot --output-file=${WD}/${aTEXTDOMAIN}_OLD.po
  fi
}


translate_until_error_free  () {
  ATEXTDOMAIN=$1
  #code from momanager by Barry Kauler   
  #130502 L18L/BK: stay in a loop if there is an error converting .po to .mo...
  ABORTFLG=0
  cp -f $WD/${ATEXTDOMAIN}.po $WD/${ATEXTDOMAIN}.poBACKUP1
  while true ; do
    killall geany 2> /dev/null #otherwise geany will return immediately and continue executing this script.
    sleep 0.5

    geany $WD/${ATEXTDOMAIN}.po

    if [ ! diff -q $WD/${ATEXTDOMAIN}.poBACKUP1 $WD/${ATEXTDOMAIN}.po  >/dev/null 2>&1 ] ; then
      ABORTFLG=8
      break
    fi
    msgfmt --output-file=- $WD/${ATEXTDOMAIN}.po >/dev/null 2> $WD/po-2-mo.err
    [ ! -s $WD/po-2-mo.err ] && break

    pupdialog --background '#FF8080' --backtitle "${0##/*}: po to mo fail" --extra-button --yes-label "Fix" --no-label "Abort" --extra-label "Revert" --yesno "There are errors in the .po file:

`cat $WD/po-2-mo.err`

NOTE: The above error message is logged to $WD/po-2-mo.err

Click the 'Fix' button to edit the .po file again...
Click 'Revert' to go back to original .po file, and try again...
Click 'Abort' to give up..." 0 0
    case $? in
      0)  continue  ;; #Fix
      3)  cp -f $WD/${ATEXTDOMAIN}.poBACKUP1 $WD/${ATEXTDOMAIN}.po ; continue ;; #Revert
      *)  ABORTFLG=9 ; break ;; #1=Abort
    esac
  done
 
  if [ $ABORTFLG -eq 0 ];then
    rxvt -e msgfmt --check --output-file=$WD/${ATEXTDOMAIN}.mo $WD/${ATEXTDOMAIN}.po
    pupdialog --background yellow --colors --backtitle "${0##/*}: post-edit mo" --yes-label "OK" --no-label "Cancel" --yesno "The file $WD/${ATEXTDOMAIN}.po has been edited and converted to $WD/${ATEXTDOMAIN}.mo. If all went well, click the \ZbOK\ZB button to copy it to \Zb${TRANSLATED}\ZB. Note, as a precaution, the old mo file is at $WD/${ATEXTDOMAIN}.moOLD." 0 0
    ABORTFLG=$?
  fi

  if [ $ABORTFLG -eq 0 ];then
    cp -f $WD/${ATEXTDOMAIN}.mo "${TRANSLATED}"
  else
    pupdialog --background pink --backtitle "${0##/*}: mo edit aborted" --msgbox "You have declined to update the mo file. Ok, the previous one has been retained." 0 0
  fi
}

##############################

case $1 in -*) usage ;; esac

read transLANG < $FATDOG_STATE_DIR/language #ex:de_BE.UTF-8
[ "$transLANG" ] || transLANG=$LANG
[ "$transLANG" ] || die "Sorry, need language LANG."
transLANG=${transLANG%_*} #ex:de

WD=/tmp/md; mkdir -p $WD

[ "$1" ] && FROM=`realpath "$1" 2>/dev/null`

[ $FROM ] || FROM=$(Xdialog --title "$TITLE to $transLANG" --backtitle="Choose .md file \n(or cancel to select a directory)" --no-buttons --fselect $HOME 0 0 2>&1)
[ "${FROM##*.}" = "md" ] || [ -d $FROM ] || die "no .md file selected"

[ $FROM ] || FROM=$(eval Xdialog --title \"$TITLE to $transLANG\" --backtitle=\"All .md files in directory:\" --no-buttons --dselect /usr/share/doc/faqs/ 0 0 2>&1)
[ ${FROM##*.} = md ] || [ -d $FROM ] || die "no .md file found in $FROM"

if [ -d $FROM ]; then
  FILES="`ls ${FROM}/*.md`"
else
  FILES="`find /etc /root /usr /var -maxdepth 3 -wholename ${FROM}`"
fi
aTEXTDOMAIN="`grep -m1 %%textdomain $FILES | cut -d' ' -f2  | uniq `"
[ "$aTEXTDOMAIN" ] || die "no %%textdomain found"

TRANSLATED=${TEXTDOMAINDIR}/${transLANG}/LC_MESSAGES/${aTEXTDOMAIN}.mo

create_pot $aTEXTDOMAIN "$FILES"
create_po $aTEXTDOMAIN
msgmerge ${WD}/${aTEXTDOMAIN}_OLD.po ${WD}/${aTEXTDOMAIN}.pot -o - > $WD/${aTEXTDOMAIN}.po

# remove comment sign, ex: change #~ msgid "bla" to msgid "bla"
sed -i 's/^#~ //' $WD/${aTEXTDOMAIN}.po #that is: keep unused translations !
sync
translate_until_error_free $aTEXTDOMAIN

exit 0

Used to translate mdview's examples/.
(small changes in index.md [attached])
25 messages....
mdview_examples_translated.png
 Description   
 Filesize   63.34 KB
 Viewed   361 Time(s)

mdview_examples_translated.png

domain.mo.gz
Description  remove fake .gz
save as /usr/share/locale/de/LC_MESSAGES/domain.mo
gz

 Download 
Filename  domain.mo.gz 
Filesize  3.33 KB 
Downloaded  194 Time(s) 
index.md.gz
Description  remove fake .gz
gz

 Download 
Filename  index.md.gz 
Filesize  1.28 KB 
Downloaded  189 Time(s) 
Back to top
View user's profile Send private message 
step

Joined: 04 May 2012
Posts: 1099

PostPosted: Mon 29 Jun 2015, 04:43    Post subject:  

@jamesbond, is there a way to start mdview with X11 geometry arguments like WxH+X+Y, or any way to start it in a given screen position with given window dimensions?
_________________
Fatdog64-800|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 3431
Location: www.eussenheim.de/

PostPosted: Tue 29 Sep 2015, 11:12    Post subject: howto translate .md docs
Subject description: the Puppy method
 

Recent momanager can.

mdview --po is automatically used with .md files that have a %%textdomain.

Note, you must have installed latest mdview, see 1st post of this thread, download,
Code:
make

and copy executable mdview to /usr/bin.

Example file :
Code:
%%textdomain mdview

This document contains list of all supported features.

------------------------------------------------------

%%nopot yes
**%%textdomain** domain

%%nopot no

The above line should be invisible, it sets the translation domain
for use with this document (no-standard).

# Heading 1

This is also heading 1
===

## Heading 2

This is also heading 2
---

### Heading 3

This is a ruler

---

This one too

***

Bullets (only unordered supported for now)

%%nopot yes

 * a
 * b
 * c
 
%%nopot no

Codeblocks (4 spaces or tabs preceded everyline):
   function a()
     b="*c*"
   }

### Inline styles

*italic1*, _italic2_, **bold1**, __bold2__, `inline code`, and `inline code again`, then
**_bold-italic1_**, __*bold-italic2*__, and
"Smart double-quoting", 'smart single-quoting', em-dash: -- .

We also have non-standard ---strikethrough---.

Links:
* [Link to another file](file.md)
* [HTTP link to google](http://www.google.com) "Google Search"
* [HTTPS link to google](https://www.google.com)
* This is not a link: http://www.google.com
* This is not a link: https://www.google.com

Inline image support: ![Tux](linux3.png)

(image path is always relative to document directory)

If you use the -x option, executable code is supported: $(echo '$LANG') is $(echo $LANG).
[Quoting-test for exec mode](quote-test.md).

**The End**

---

## Appendix: About translations

Default is create translation for **entire line** which can be a very long line (a paragraph <p> in terms of markup).

### No ---Translation---

A line starting with **tab** or **4 spaces** is NOT translated.

If you have a line which must **not** be translated (always code, maybe a name, parameter, etc) mark the line by %%nopot tags (nopot yes and nopot no) :

%%nopot yes

**%%nopot** yes

Let these English lines stay English only.

Nothing inside these tags will go into translation file.

**%%nopot** no

%%nopot no

Save it to e.g. /root/examples/mdview.md
and new momanager will present it for translation.

Feedback welcome.

EDIT: Here i s how it looks (untranslated)
mdview.png
 Description   
 Filesize   30.91 KB
 Viewed   333 Time(s)

mdview.png

Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 3431
Location: www.eussenheim.de/

PostPosted: Fri 04 Dec 2015, 13:11    Post subject: mdview, a markdown viewer  

bump
not just because I am always unseccessfully searching this in "Documents"...

mdview uses internal gettext i.e. entire line is a translatable message.

This is not really new,
But really new is:

You can use one textdomain for scripts and .md file.
This should be conveniant for help and/or README files.

ex: the app has textdomain apple.
define
Code:
export TEXTDOMAIN=apple
in the scripts
and define
Code:
%%textdomain apple
in their .md files.
Next version of momanager can handle this so that translators see and translate just one file apple.po.

( Next version of momanager can handle also technosaurus' method additionally so that translators see and translate just one translation file.)
Back to top
View user's profile Send private message 
step

Joined: 04 May 2012
Posts: 1099

PostPosted: Sat 05 Dec 2015, 05:58    Post subject:  

I tried to make me like this type of convenience several times, but I couldn't convince myself for the following reasons:
1. mdview is not a puppy standard, it's a Fatdog add-on.
2. mdview markdown support has some limits
3. What are the advantages of creating HTML documentation and giving that out to translate vs giving the md file out to translate? I still need to figure that out.
If the perceived benefits aren't readily apparent, gettexting md files is a hard sell, IMO.

_________________
Fatdog64-800|+Packages|Kodi|Findnrun|+forum|gtkmenuplus
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 3 of 5 [63 Posts]   Goto page: Previous 1, 2, 3, 4, 5 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1732s ][ Queries: 13 (0.0584s) ][ GZIP on ]