Add @@ markup for arbitrary command
This commit is contained in:
parent
18cbf10cbf
commit
289018f481
27
R
27
R
|
@ -7,37 +7,50 @@ BEGIN {
|
||||||
_el=" el "; _defel="p"
|
_el=" el "; _defel="p"
|
||||||
}
|
}
|
||||||
|
|
||||||
function start(el) {
|
function start(el, not_html) { # start an element
|
||||||
el = (el ? el : _defel)
|
el = (el ? el : _defel)
|
||||||
|
pre_el = (not_html ? "" : _el)
|
||||||
split(el, el_a, " ")
|
split(el, el_a, " ")
|
||||||
lvl[++i] = el_a[1]
|
lvl[++i] = el_a[1]
|
||||||
return "$(<<" _end i lvl[i] _el el "\n"
|
return "$(<<" _end i lvl[i] pre_el el "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
function end() {
|
function end() { # end an element
|
||||||
return "\n" _end i lvl[i--] "\n)"
|
return "\n" _end i lvl[i--] "\n)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrap(par) {
|
function wrap(par) { # wrap a non-delimited paragraph with <p>
|
||||||
if (par !~ /^<.*>$/)
|
if (par !~ /^<.*>$/)
|
||||||
return start() par end()
|
return start() par end()
|
||||||
else
|
else
|
||||||
return par
|
return par
|
||||||
}
|
}
|
||||||
|
|
||||||
/^@[^()]/ {
|
/^@[^@()]/ { # html element
|
||||||
$1 = start(substr($1, 2))
|
$1 = start(substr($1, 2))
|
||||||
sub(/\n?$/, end())
|
sub(/\n?$/, end())
|
||||||
print
|
print
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
|
|
||||||
/^@\(/ {
|
/^@@[^()]/ { # arbitrary command
|
||||||
|
$1 = start(substr($1, 3))
|
||||||
|
sub(/\n?$/, end())
|
||||||
|
print
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
/^@\(/ { # nested element begin
|
||||||
print start(substr($1, 3))
|
print start(substr($1, 3))
|
||||||
$1=""; $0=$0
|
$1=""; $0=$0
|
||||||
}
|
}
|
||||||
|
|
||||||
/@\)$/ {
|
/^@@\(/ { # nested arbitrary command begin
|
||||||
|
print start(substr($1, 4))
|
||||||
|
$1=""; $0=$0
|
||||||
|
}
|
||||||
|
|
||||||
|
/@@?\)$/ { # nested element end
|
||||||
nf=$NF; NF--; $0=$0; print
|
nf=$NF; NF--; $0=$0; print
|
||||||
if ($0) {
|
if ($0) {
|
||||||
print wrap($0)
|
print wrap($0)
|
||||||
|
|
Loading…
Reference in New Issue