xrfragment/doc/generate.awk

34 lines
1.1 KiB
Awk
Raw Permalink Normal View History

2023-04-02 21:19:03 +02:00
# a no-nonsense source-to-markdown generator which scans for:
#
# /**
# * # foo
# *
# * this is markdown $(cat bar.md)
# */
#
# var foo; // comment with 2 leading spaces is markdown too $(date)
#
2023-04-02 21:37:38 +02:00
# easily refactorable to hash-based languages (py/bash/perl/lua e.g.)
# by changing the regexes
#
2023-04-02 21:19:03 +02:00
/\$\(/ { cmd=$0;
2023-04-02 21:38:52 +02:00
gsub(/^.*\$\(/,"",cmd);
gsub(/\).*/,"",cmd);
cmd | getline stdout; close(cmd);
2023-04-02 21:19:03 +02:00
sub(/\$\(.*\)/,stdout);
}
2023-04-02 21:38:52 +02:00
/\/\*\*/ { doc=1; sub(/^.*\/\*/,""); }
2023-04-02 21:19:03 +02:00
doc && /\*\// { doc=0;
2023-04-02 21:38:52 +02:00
sub(/[[:space:]]*\*\/.*/,"");
sub(/^[[:space:]]*\*[[:space:]]?/,"");
print
}
2023-04-02 21:19:03 +02:00
doc && /^[[:space:]]*\*/ { sub(/^[[:space:]]*\*[[:space:]]?/,"");
2023-04-02 21:38:52 +02:00
print
2023-04-02 21:19:03 +02:00
}
!doc && /\/\/ / { sub(".*// ","");
2023-04-02 21:38:52 +02:00
sub("# ","\n# ");
sub("> ","\n> ");
print
}