1 |
7431
|
aaronmk
|
#!/bin/sh
|
2 |
|
|
# Translates a Redmine HTML page to a thesaurus
|
3 |
|
|
# Usage: self <page
|
4 |
|
|
|
5 |
|
|
sedEreFlag="$(test "$(uname)" = Darwin && echo E || echo r)"
|
6 |
|
|
|
7 |
|
|
sed () { "$(which sed)" -"$sedEreFlag" "$@";}
|
8 |
|
|
|
9 |
7442
|
aaronmk
|
ambigTerm=
|
10 |
7431
|
aaronmk
|
term=
|
11 |
8233
|
aaronmk
|
sed -n 's/^<h[1-4][^>]*>(<del>)?(<img [^>]*title="([^"]*):"[^>]*>|([[:alpha:] ]+):)? *<a href="#[^"]+" class="wiki-page">([^<]+).*$/"\3\4" "\5"/p'\
|
12 |
7431
|
aaronmk
|
|while read -r line; do
|
13 |
7489
|
aaronmk
|
eval set -- $line # split to $@
|
14 |
|
|
type="$1" name="$2"
|
15 |
7442
|
aaronmk
|
|
16 |
|
|
# Handle synonyms
|
17 |
7489
|
aaronmk
|
if test "$type" = Synonym; then echo "$name,$term"
|
18 |
7442
|
aaronmk
|
else
|
19 |
|
|
term="$name"
|
20 |
|
|
|
21 |
|
|
# Handle ambiguous terms
|
22 |
7490
|
aaronmk
|
if test -n "$type"; then # alternative of ambiguous term
|
23 |
|
|
echo "$ambigTerm,$term"
|
24 |
|
|
else # potentially ambiguous term
|
25 |
7442
|
aaronmk
|
ambigTerm="$term"
|
26 |
|
|
fi
|
27 |
7431
|
aaronmk
|
fi
|
28 |
|
|
done
|