diff options
Diffstat (limited to 'trbldoc.sh')
| -rw-r--r-- | trbldoc.sh | 42 |
1 files changed, 34 insertions, 8 deletions
@@ -183,18 +183,23 @@ BEGIN { program_p = "" ref_p = "" } -{sub(/\r$/, "", $0)} /^[[:blank:]]*@file / && from_p == "" { from_p = $0 sub(/^[[:blank:]]*@file /, "", from_p) } -/^[[:blank:]]*@name / && namespace_p == "" { namespace_p = $2 } -/^[[:blank:]]*@priority / && priority_p == "" { priority_p = $2 } +/^[[:blank:]]*@name / && namespace_p == "" { + namespace_p = $2 +} +/^[[:blank:]]*@priority / && priority_p == "" { + priority_p = $2 +} /^[[:blank:]]*@exec / && program_p == "" { program_p = $0 sub(/^[[:blank:]]*@exec /, "", program_p) } -/^[[:blank:]]*@ref / && ref_p == "" { ref_p = $2 } +/^[[:blank:]]*@ref / && ref_p == "" { + ref_p = $2 +} END { printf "%s%s%s%s%s%s%s%s%s\n", from_p, us, namespace_p, us, priority_p, us, program_p, us, ref_p } @@ -452,15 +457,27 @@ lua,\]\],\-\-\[\[ # Helper: write comment-extraction awk script from start/end regex pair. # Uses single-quote splicing to inject shell variables into awk source. +# Opening-tag indent (spaces/tabs before the start delimiter) is recorded and +# stripped from subsequent body lines so indented source comments do not become +# accidental Markdown code blocks. _write_comment_form() { printf '%s\n' ' BEGIN{} /'"$2"'/ { if(in_comment) {print "EOF"} in_comment=0 + indent="" +} +in_comment { + line=$0 + if (indent != "" && index(line, indent) == 1) { + line=substr(line, length(indent)+1) + } + print line } -in_comment {print} /'"$3"' .+/ && !/'"$2"'$/ { + indent=$0 + sub(/[^[:space:]].*/, "", indent) print "chunkfile=$(mktemp -p '"${cache_dir}"'/chunks)" print "cat > $chunkfile << \"EOF\"\n@file " name ":" NR ; if($2) {$1=""; print "@exec " $0} @@ -488,17 +505,26 @@ for _alias_ext in moon tl; do cp "$comment_form_dir/lua.awk" "$comment_form_dir/${_alias_ext}.awk" 2>/dev/null || true done -# Python: ''' is both the open and close delimiter. Renderer name is +# Python: ''' is both the open and close delimiter; the renderer name is # glued directly after the opening ''' with no space required (e.g. '''md). -# Custom AWK uses sub() for renderer extraction instead of field splitting. +# A custom AWK uses sub() for renderer extraction instead of field splitting. sed "s|__PY_CACHE__|${cache_dir}|g" << 'PYAWK' > "$comment_form_dir/py.awk" BEGIN{} /'''/ { if(in_comment) {print "EOF"} in_comment=0 + indent="" +} +in_comment { + line=$0 + if (indent != "" && index(line, indent) == 1) { + line=substr(line, length(indent)+1) + } + print line } -in_comment {print} /'''.+/ && !/'''$/ { + indent=$0 + sub(/[^[:space:]].*/, "", indent) print "chunkfile=$(mktemp -p __PY_CACHE__/chunks)" print "cat > $chunkfile << \"EOF\"\n@file " name ":" NR ; renderer = $0 |
