Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active March 31, 2023 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderofsalvation/f714d76a26d98bcb14e128288efd377c to your computer and use it in GitHub Desktop.
Save coderofsalvation/f714d76a26d98bcb14e128288efd377c to your computer and use it in GitHub Desktop.
deadsimple literal-ish documentation-generator using awk #tiny #superflexible #markdown

Foo

bar is printed

The code


//  # Foo
//

function foo(){
  console.log("bar")            //  bar is printed

}

//  # The code
//
//  #code foo.js

//  # My ip
//  
//  #sh curl -s icanhazip.com
//   
//  # My hostname
//  
//  #include /etc/hostname

My ip

80.99.73.15

My hostname

ls540

// # Foo
//
function foo(){
console.log("bar") // bar is printed
}
// # The code
//
// #code foo.js
// # My ip
//
// #sh curl -s icanhazip.com
//
// # My hostname
//
// #include /etc/hostname
#!/bin/sh
generate(){
cat $1 | awk '/\/\/ / {
gsub(".*// ","",$0);
gsub("# ","\n# ",$0);
if( match($0,/^#include /) ){ system("cat "$2); next; }
if( match($0,/^#code /) ){ print "```\n"; system("cat "$2); print "```\n"; next; }
if( match($0,/^#sh /) ){ $1=""; system($0); next; }
print $0;
}'
}
generate *.js > README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment