File: w3m.sh

package info (click to toggle)
tuxpaint 1%3A0.9.35-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 64,512 kB
  • sloc: ansic: 62,209; makefile: 1,425; sh: 790; objc: 303; cpp: 186; python: 182; php: 43
file content (51 lines) | stat: -rwxr-xr-x 1,534 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash

infile=${@: -1}
args=${@:1:${#}-1}

# Add some visual indicators around some text
# to make their context -- heading ("<h2>", "<h3", etc.),
# description term ("<dt>"), etc -- more obvious in
# the plain text version of the documentation:

H2_OPEN_MUNGE="s/<h2\([^>]*\)>/<h2\1><center>### /"
H2_CLOSE_MUNGE="s/<\/h2>/ ###<\/center><\/h2>/"
H3_OPEN_MUNGE="s/<h3\([^>]*\)>/<h3\1>## /"
H3_CLOSE_MUNGE="s/<\/h3>/ ##<\/h3>/"
H4_OPEN_MUNGE="s/<h4\([^>]*\)>/<h4\1># /"
H4_CLOSE_MUNGE="s/<\/h4>/ #<\/h4>/"
DT_OPEN_MUNGE="s/<dt>/<dt>\&rarr; /"
DT_CLOSE_MUNGE="s/<\/dt>/ \&larr;<\/dt>/"
DD_CLOSE_MUNGE="s/<\/dd>/<br\/>\&nbsp;<br\/><\/dd>/"

# FIXME: https://en.wikipedia.org/wiki/Line_breaking_rules_in_East_Asian_languages
# | sed -e "s/\(.[、。)]\)/<nobr>\\1<\\/nobr>/g" \
# This needs expanding & to not mess with <img> `alt` tag attributes or anything inside HTML tags (e.g., " quotes)!
# -bjk 2023.07.17

if [[ "$infile" =~ ja_JP ]]; then
  sed $infile \
    -e "$H2_OPEN_MUNGE" \
    -e "$H2_CLOSE_MUNGE" \
    -e "$H3_OPEN_MUNGE" \
    -e "$H3_CLOSE_MUNGE" \
    -e "$H4_OPEN_MUNGE" \
    -e "$H4_CLOSE_MUNGE" \
    -e "$DT_OPEN_MUNGE" \
    -e "$DT_CLOSE_MUNGE" \
    -e "$DD_CLOSE_MUNGE" \
    | php ./nobr_forbidden.php \
    | w3m $args
else
  sed $infile \
    -e "$H2_OPEN_MUNGE" \
    -e "$H2_CLOSE_MUNGE" \
    -e "$H3_OPEN_MUNGE" \
    -e "$H3_CLOSE_MUNGE" \
    -e "$H4_OPEN_MUNGE" \
    -e "$H4_CLOSE_MUNGE" \
    -e "$DT_OPEN_MUNGE" \
    -e "$DT_CLOSE_MUNGE" \
    -e "$DD_CLOSE_MUNGE" \
    | w3m $args
fi