Compare commits
2 Commits
035bfe5e81
...
0f3ed14575
| Author | SHA1 | Date | |
|---|---|---|---|
|
0f3ed14575
|
|||
|
089593bb0f
|
@@ -6,13 +6,13 @@
|
||||
# This is not intended to produce great output, merely useful output.
|
||||
# As such, input documents should restrict themselves as follows:
|
||||
#
|
||||
# - Attributes cannot be passed on the command line.
|
||||
# - In-line formatting sequences must not overlap,
|
||||
# cannot be escaped, and cannot span lines.
|
||||
# - Heading underlines must match in byte length exactly.
|
||||
# - Only a small subset of syntax is supported overall.
|
||||
#
|
||||
# Also beware that the output has only been tested with GNU troff.
|
||||
# Attributes can be passed via environment variables starting with "asciidoc-".
|
||||
|
||||
function fatal(message) {
|
||||
print ".\\\" " FILENAME ":" FNR ": fatal error: " message
|
||||
@@ -20,11 +20,18 @@ function fatal(message) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
function expand(s, attr) {
|
||||
function getattribute(name) {
|
||||
if (!(name in Attrs) && ("asciidoc-" name) in ENVIRON)
|
||||
Attrs[name] = ENVIRON["asciidoc-" name]
|
||||
return Attrs[name]
|
||||
}
|
||||
|
||||
function expand(s, attr, v) {
|
||||
# TODO: This should not expand unknown attribute names.
|
||||
while (match(s, /[{][^{}]*[}]/)) {
|
||||
attr = substr(s, RSTART + 1, RLENGTH - 2)
|
||||
s = substr(s, 1, RSTART - 1) Attrs[attr] substr(s, RSTART + RLENGTH)
|
||||
s = substr(s, 1, RSTART - 1) \
|
||||
getattribute(substr(s, RSTART + 1, RLENGTH - 2)) \
|
||||
substr(s, RSTART + RLENGTH)
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -66,19 +73,49 @@ NR == 1 {
|
||||
|
||||
# Requesting tbl(1), even though we currently do not support tables.
|
||||
print "'\\\" t"
|
||||
print ".TH \"" toupper(name) "\" \"" section "\""
|
||||
printf ".TH \"%s\" \"%s\" \"\" \"%s\"",
|
||||
toupper(name), section, getattribute("mansource")
|
||||
if (getattribute("manmanual"))
|
||||
printf " \"%s\"", getattribute("manmanual")
|
||||
print ""
|
||||
|
||||
# Hyphenation is indeed rather annoying, in particular with long links.
|
||||
print ".nh"
|
||||
}
|
||||
|
||||
function format(line, v) {
|
||||
# Pass-through, otherwise useful for hacks, is a bit of a lie here,
|
||||
# and formatting doesn't fully respect word boundaries.
|
||||
while (line) {
|
||||
if (match(line, /^[+][+][+][^+]+[+][+][+]/)) {
|
||||
v = v substr(line, RSTART + 3, RLENGTH - 6)
|
||||
} else if (match(line, /^__[^_]+__/)) {
|
||||
v = v "\\fI" substr(line, RSTART + 2, RLENGTH - 4) "\\fP"
|
||||
} else if (match(line, /^[*][*][^*]+[*][*]/)) {
|
||||
v = v "\\fB" substr(line, RSTART + 2, RLENGTH - 4) "\\fP"
|
||||
} else if (match(line, /^_[^_]+_/) &&
|
||||
substr(line, RSTART + RLENGTH) !~ /^[[:alnum:]]/) {
|
||||
v = v "\\fI" substr(line, RSTART + 1, RLENGTH - 2) "\\fP"
|
||||
} else if (match(line, /^[*][^*]+[*]/) &&
|
||||
substr(line, RSTART + RLENGTH) !~ /^[[:alnum:]]/) {
|
||||
v = v "\\fB" substr(line, RSTART + 1, RLENGTH - 2) "\\fP"
|
||||
} else {
|
||||
v = v substr(line, 1, 1)
|
||||
line = substr(line, 2)
|
||||
continue
|
||||
}
|
||||
line = substr(line, RSTART + RLENGTH)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
function inline(line) {
|
||||
if (!line) {
|
||||
print ".sp"
|
||||
return
|
||||
}
|
||||
|
||||
line = escape(expand(line))
|
||||
line = format(escape(expand(line)))
|
||||
|
||||
# Strip empty URL descriptions, otherwise useful for demarking the end.
|
||||
while (match(line, /[^[:space:]]+\[\]/)) {
|
||||
@@ -86,35 +123,6 @@ function inline(line) {
|
||||
substr(line, RSTART + RLENGTH)
|
||||
}
|
||||
|
||||
# Pass-through, otherwise useful for hacks, is a lie here.
|
||||
while (match(line, /[+][+][+][^+]+[+][+][+]/)) {
|
||||
line = substr(line, 1, RSTART - 1) \
|
||||
substr(line, RSTART + 3, RLENGTH - 6) \
|
||||
substr(line, RSTART + RLENGTH)
|
||||
}
|
||||
|
||||
# Italic and bold formatting doesn't respect any word boundaries.
|
||||
while (match(line, /__[^_]+__/)) {
|
||||
line = substr(line, 1, RSTART - 1) \
|
||||
"\\fI" substr(line, RSTART + 2, RLENGTH - 4) "\\fP" \
|
||||
substr(line, RSTART + RLENGTH)
|
||||
}
|
||||
while (match(line, /_[^_]+_/)) {
|
||||
line = substr(line, 1, RSTART - 1) \
|
||||
"\\fI" substr(line, RSTART + 1, RLENGTH - 2) "\\fP" \
|
||||
substr(line, RSTART + RLENGTH)
|
||||
}
|
||||
while (match(line, /[*][*][^*]+[*][*]/)) {
|
||||
line = substr(line, 1, RSTART - 1) \
|
||||
"\\fB" substr(line, RSTART + 2, RLENGTH - 4) "\\fP" \
|
||||
substr(line, RSTART + RLENGTH)
|
||||
}
|
||||
while (match(line, /[*][^*]+[*]/)) {
|
||||
line = substr(line, 1, RSTART - 1) \
|
||||
"\\fB" substr(line, RSTART + 1, RLENGTH - 2) "\\fP" \
|
||||
substr(line, RSTART + RLENGTH)
|
||||
}
|
||||
|
||||
# Enable double-spacing after the end of a sentence.
|
||||
gsub(/[.][[:space:]]+/, ".\n", line)
|
||||
gsub(/[!][[:space:]]+/, "!\n", line)
|
||||
|
||||
Reference in New Issue
Block a user