wok-current view tazwikiss/stuff/var/www/wiki/plugins/wkp_Tables.sh @ rev 5859
Add tazwikiss
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Jul 18 12:02:49 2010 +0200 (2010-07-18) |
parents | |
children |
line source
1 plugin="Tables"
2 description_fr="Syntaxe de tables"
3 description="Table syntax"
5 formatBegin()
6 {
7 CONTENT=$(sed -e 's/\[\([^]]*\)|\([^]]*\)|\([^]]*\)\]/[\1{WKP_TBL_BAR}\2{WKP_TBL_BAR}\3]/g' \
8 -e 's/\[\([^]]*\)|\([^]]*\)\]/[\1{WKP_TBL_BAR}\2]/g' -e 's,|,||,g' \
9 -e 's,^\( *|\)|,\1,' -e 's/|\( *\)$/\1/' <<EOT | awk '
10 {
11 if (/^ *\|.*\|$/) {
12 if (in_array == 0) printf "<table class=\"wikitable\">"
13 in_array = 1
14 s = $0
15 printf "<tr>"
16 while (match(s,/\|[^\|]*\|/)) {
17 q = substr(s,RSTART+1,RLENGTH-2)
18 s = substr(s,RSTART+RLENGTH)
19 c=""; lr=""; tb=""
20 if (match(q,/^[hlrtb]+ /)) {
21 for (i = 0; i < RLENGTH; i++) {
22 if (q ~ /^h/) c=" class=\"em\""
23 if (q ~ /^l/) lr="text-align: left; "
24 if (q ~ /^r/) lr="text-align: right; "
25 if (q ~ /^t/) tb="vertical-align: top; "
26 if (q ~ /^b/) tb="vertical-align: bottom; "
27 q = substr(q,2)
28 }
29 }
30 if (lr != "" || tb != "") c = c " style=\"" lr tb "\""
31 if (match(q,/^[0-9]+ */)) {
32 n = RLENGTH
33 match(q,/^[0-9]+/)
34 c = c " colspan=\"" substr(q,1,RLENGTH) "\""
35 q = substr(q,n+1)
36 }
37 if (match(q,/^,[0-9]+ */)) {
38 n = RLENGTH
39 match(q,/^,[0-9]+/)
40 c = c " rowspan=\"" substr(q,2,RLENGTH-1) "\""
41 q = substr(q,n+1)
42 }
43 printf " <td" c ">" q "</td>"
44 }
45 printf "</tr>"
46 }
47 else {
48 if (in_array != 0) print "</table>"
49 in_array = 0
50 print
51 }
52 } END { if (in_array != 0) print "</table>" }' | \
53 sed -e 's/{WKP_TBL_BAR}/|/g' -e 's,||,|,g'
54 $CONTENT
55 EOT
56 )
57 }