- a web building block for the desperatecloc, ~1200 lines total) portable web "anti-framework" foundation made in AWK,
compatible with pretty much all AWKs out there, so you can even use teg on Plan 9.
.teg files.
== This is a comment
== This is NOT a comment
All comments are skipped.
!exec_raw echo 'Hello, World!'
If the call exists, it will be executed, and the line replaced with the call's return.
Set variable to value!var variable=value
The variable is being filled with the contents of all the following lines until a line consisting of just "delim" is found.!var variable<delim
...
delim
Declare the start of the webpage.!start
Cleanly abort execution, return exit code!abort exit code
Include a file!inc file
Print text to stderr!log text
Run a command in your system's command interpreter and give its output to the Markdown processor!exec_raw command
Run a command and paste its output as a code block. Disables the Markdown processor for the contents of the code block!exec_fmt command
Run a command and include its output as teg code!exec_inc command
Open an HTML tag on first call, close the tag on the second call for the same class!e element class options
!e div #some-id;some-class1;some-class2
!e div _ style="font-size: 90%" -> <div style="font-size: 90%">
!e pre #container;containers;borders; style="padding: 1em; border: 2px dotted black; font-family: monospace"
Hello, world!
This is a demo of the teg element call.
!e
Same as !e, just don't close the tag on a second call for the same class!eo element class options
Same as !eo, just immediately close the tag!eoc element class options
{$variable$}{!call!}!var osname={!exec_raw . /etc/os-release&&echo $PRETTY_NAME||echo unknown!}
!start
My current distro is `{$osname$}`
Inline calls can be nested:
!var ls_args=-lF
!start
ls output: {!exec_fmt ls {$ls_args$}!}
... but please keep in mind that nesting can sometimes be very broken and cause unexpected issues.
hello {$who$} <- NO!
hello \{$who$} <- Yes!
Page titletitle=file
Page description for OpenGraph embedsdescription
Page localelang=en-US
Return an HTTP status for use with CGIstatus
Content type for use with CGIctype=text/html
Favicon pathicon
Browser style color (only for mobile)color_chrome
Add an image embedembed_img
Enable OpenGraph embeds (embed_og=0
<meta property="og:.." ...>)
Enable Twitter embeds (embed_twt=0
<meta name="twitter:.." ...>)
External CSS stylesheet to reference, specified as a list of files separated by a semicolonstyle
!var style=/data/main.css;custom.css
CSS stylesheet files to include in HTMLstyle_inline
!var style_inline<eol
body {
font: monospace;
}
eol
JS file to reference in <head>script
JS files to include at the start of <body>script_inline
Enable / disable debug loggingdebug=0
Abort processing and exit on errorexit_on_error=1
Do not put line breaks for the next N linesno_br=0
Halt processing for the next N linesno_proc=0
File that is currently being processedfile
code and some missing complex features like tables.
||[Click me]Boo!||
Line 1
Same line
Line 2
Line 4?
formats as
Line 1 Same line
Line 2
Line 4?
~~strikethrough!~~
-# I am tiny!
I am tiny!
TEG_AS_LIBRARY = 1, then include teg.awk like so:
BEGIN { TEG_AS_LIBRARY = 1 }
@include "teg.awk"
Some of the more useful functions you get access to are:
Initialize tegTEG_init()
Process a line, returns formatted lineTEG_proc(src)
Finalize processing, returns end of HTMLTEG_end()
Convert markdown to HTML, returns converted HTMLTEG_md_fmt(str)
Process a teg call, return its outputTEG_callproc(str, explicit)
!start yet
Read each file from a list delimited by delim and return all of their contentsTEG_read_list(list, delim)
Escape some symbols in string for inclusion in HTML, returns escaped stringTEG_escape_html(str)
Print a marker to stderr with a number incrementing each call, useful for debuggingTEG_MARK(optional_str)
Pretty print for arrays, useful for debuggingTEG_explode_arr(array)
Debug, warning and error loggingTEG_logt(str, type)
TEG_c_vars["exit_on_error"] is set to 1 and an error is logged, the script will exit
Complete the input path with currently running/included teg script's path and return a relative path to the fileTEG_relpath(path)
Check if a file exists, returns 1 if yes and 0 if noTEG_exists(file)
Check if a string is empty or made of purely whitespace, returns 1 if yes and 0 if notTEG_is_null(str)
The variables you can set withTEG_c_vars[]
!var
An array of various REGEX for matching various thingsTEG_reglist[]
Current and previous markdown list typesTEG_list_type[0,1]
Current and previous markdown list levelsTEG_list_lvl[0,1]
Current and previous markdown blockquote levelsTEG_blockquote_lvl[0,1]
extra/library_use.awk.
TEG_md_fmt() or TEG_proc() make sure to run TEG_init() to prepare all variables they expect.
TEG_proc(), run TEG_end() (and print / append its return) to put the finishing HTML.