tazpkg rev 894
Append README.devel
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Sat Dec 19 15:39:06 2015 +0200 (2015-12-19) |
parents | 92d8376cbf06 |
children | 9575613271cf |
files | README.devel modules/help |
line diff
1.1 --- a/README.devel Sat Dec 19 14:09:22 2015 +0100 1.2 +++ b/README.devel Sat Dec 19 15:39:06 2015 +0200 1.3 @@ -105,3 +105,66 @@ 1.4 undigest repositories. We can set up special scripts and test repository on the 1.5 existing server (cook.slitaz.org). 1.6 1.7 + 1.8 +HTML terminal converter 1.9 +----------------------- 1.10 + 1.11 +In the module "help" was an attempt to write code that could easily display the 1.12 +HTML-help in a terminal. The idea is to re-use TazPkg help files, which are 1.13 +intended for display in the browser. 1.14 + 1.15 +I'll tell you about the most interesting and complex part of the script that 1.16 +starts like this: 1.17 + 1.18 + PRE=$(echo "$HLP" | sed ... 1.19 + 1.20 +Here $HLP is a part of the HTML page that we are going to show. Next the chain 1.21 +of sed commands are transformed this HTML source in the next way. 1.22 + 1.23 + * `/^$/d;` remove blank lines; 1.24 + * `/<pre>/,/<\/pre\>/{s|.*| &|; s| |·|g};` prepend lines within <pre>*</pre> 1.25 + tags with two unbreakable spaces, temporarily change spaces to middle dot; 1.26 + * `s|^ </*pre>$||; s|<pre>||; s|</pre>||;` remove "<pre>" tags; 1.27 + * `s| ·#| #|;` remove specified extra-space (converted to middle dot); 1.28 + * `tr '\n' ' '` convert all the newlines to spaces. Now we get one long line. 1.29 + Note that we already marked beginning of the pre-lines with two unbreakable 1.30 + spaces; 1.31 + * `s|[ ][ ]*| |g;` combine all the successive spaces and/or tabs into 1.32 + single space; 1.33 + * `s|[ ]*<dl>|O\n|g;` change opening tag "<dl>" into "O<backspace>". 1.34 + Note, here and below I use "<backspace>" character because later I'll break 1.35 + long lines using function "longline()" from libtaz.sh, which in turn uses 1.36 + Busybox function "fold". In the final step sequences like "O<backspace>" 1.37 + will be changed to "invisible" color codes, and they should have "zero 1.38 + width" when they are processed by `fold` to break long lines in the right 1.39 + places. Fortunately, Busybox `fold` knows about "<backspace>" character and 1.40 + processes it correctly, so sequence like "O<backspace>" have "zero width" 1.41 + for `fold`; 1.42 + * `s|[ ]*</dl>|L\n|g;` change closing tag "</dl>" into "L<backspace>"; 1.43 + * `s|[ ]*</*dt>||g;` remove opening and closing tags "<dt>"; 1.44 + * `s|[ ]*<dd>| |g; s|</dd>|\n|g;` now lines within tags "<dd>" are 1.45 + prepended by tabulation; 1.46 + * `s|<h4>|<b>|g; s|</h4>|</b>\n|g` change header "<h4>" into separate line 1.47 + with code `<b>...</b>\n`; 1.48 + * `s|[ ]*<p>[ ]*||g;` remove opening tag "<p>" both with extra-space; 1.49 + * `s|[ ]*</p>|\n \n|g;` remove closing tag "</p>" and append it with 1.50 + "<newline><single unbreakable space><newline>"; 1.51 + * `s| |\n |g` prepend each line of the <pre> block (marked before with the 1.52 + double unbreakable spaces) with <newline>; 1.53 + * Now we have: individual lines prepended by two unbreakable spaces for <pre> 1.54 + block, individual lines for paragraphs, as well for content of "<dt>" tag, 1.55 + individual lines prepended by tabulation for content of "<dd>" tag, 1.56 + individual lines "O<backspace>" and "L<backspace>" for begin and end of the 1.57 + "<dl>" block; 1.58 + * `s|<a [^>]*>||g; s|</a>||g;` remove links, leaving only link text; 1.59 + * `s|·| |g` change back middle dots into spaces; 1.60 + * `s|</*nobr>||g; s|­||g;` remove tags "<nobr>" and soft hyphens; 1.61 + * `s|^[ ]*||` remove space in the beginning of each line; 1.62 + * `/^$/d` remove empty lines. Note, we already have line with the single 1.63 + unbreakable space as separator between paragraphs; 1.64 + * `s|<tt>|A|g; s|<code>|A|g;` change open tags to "A<backspace>"; in the 1.65 + final step it will be changed to the color code; 1.66 + * `s|<em>|B|g; s|<strong>|B|g;` other color code; 1.67 + * `s|</tt>|D|g; s|</code>|D|g; s|</em>|D|g;` here will be code that 1.68 + cancel previous color code; 1.69 + * `s|DD|D|g;` clean doubles.
2.1 --- a/modules/help Sat Dec 19 14:09:22 2015 +0100 2.2 +++ b/modules/help Sat Dec 19 15:39:06 2015 +0200 2.3 @@ -139,7 +139,6 @@ 2.4 2.5 PRE=$(echo "$HLP" | sed "/^$/d; /<pre>/,/<\/pre\>/{s|.*| &|; s| |·|g}; \ 2.6 s|^ </*pre>$||; s|<pre>||; s|</pre>||; s| ·#| #|;" | tr '\n' ' ' | \ 2.7 - sed '/^[ ]*$/d' | \ 2.8 sed 's|[ ][ ]*| |g;' | \ 2.9 sed 's|[ ]*<dl>|O\n|g; s|[ ]*</dl>|L\n|g; s|[ ]*</*dt>||g;' | \ 2.10 sed 's|[ ]*<dd>| |g; s|</dd>|\n|g;' | \ 2.11 @@ -164,5 +163,5 @@ 2.12 [ ! -z "$TA" ] && T="$T, $TA" 2.13 2.14 title '%s' "$title" 2.15 -emsg "$(longline "$PRE2" | sed 's|A|<c 33>|g; s|B|<c 36>|g; s|C|<b>|g; s|D|</c>|g; ')" 2.16 +emsg "$(longline "$PRE2" | sed 's|A|<c 33>|g; s|B|<c 36>|g; s|C|</b>|g; s|D|</c>|g; ')" 2.17 newline