html(n)
π NAME π
okay so this is html(n), the HTML Generation manual page, and html is literally just Procedures to generate HTML structures β¨ like that's the whole vibe.
π SYNOPSIS π
package require Tcl 8.5 9
package require html ?1.6?
::html::author author
::html::bodyTag args
::html::cell param value ?tag?
::html::checkbox name value
::html::checkSet key sep list
::html::checkValue name ?value?
::html::closeTag
::html::default key ?param?
::html::description description
::html::end
::html::eval arg ?args?
::html::extractParam param key ?varName?
::html::font args
::html::for start test next body
::html::foreach varlist1 list1 ?varlist2 list2 ...? body
::html::formValue name ?defvalue?
::html::getFormInfo args
::html::getTitle
::html::h level string ?param?
::html::h1 string ?param?
::html::h2 string ?param?
::html::h3 string ?param?
::html::h4 string ?param?
::html::h5 string ?param?
::html::h6 string ?param?
::html::hdrRow args
::html::head title
::html::headTag string
::html::html_entities string
::html::if expr1 body1 ?elseif expr2 body2 ...? ?else bodyN?
::html::init ?list?
::html::keywords args
::html::mailto email ?subject?
::html::meta args
::html::meta_name args
::html::meta_equiv args
::html::meta_charset charset
::html::css href
::html::css-clear
::html::js href
::html::js-clear
::html::minorList list ?ordered?
::html::minorMenu list ?sep?
::html::nl2br string
::html::openTag tag ?param?
::html::paramRow list ?rparam? ?cparam?
::html::passwordInput ?name?
::html::passwordInputRow label ?name?
::html::quoteFormValue value
::html::radioSet key sep list
::html::radioValue name value
::html::refresh seconds url
::html::row args
::html::select name param choices ?current?
::html::selectPlain name param choices ?current?
::html::set var val
::html::submit label ?name? ?title?
::html::tableFromArray arrname ?param? ?pat?
::html::tableFromList querylist ?param?
::html::textarea name ?param? ?current?
::html::textInput name value args
::html::textInputRow label name value args
::html::varEmpty name
::html::while test body
::html::doctype id
::html::wrapTag tag ?text? ?args?
β¨ DESCRIPTION β¨
okay bestie, here's the tea π΅ β the html package is your personal HTML string factory. These commands generate HTML, and they hand it back to you as their result. And this is the part where I need you to lock in: they do NOT output their result to stdout π
ββοΈ. Like, they return it. They don't just yeet it into your terminal. okay? good.
You should call ::html::init early to initialize the module. And plot twist π
β you can also use that same procedure to define default values for your HTML tag parameters. two birds, one slay.
::html::author authorβ Side effect only, so it doesn't return anything cute, it just does a thing. Call this before::html::headto define an author for the page. The author gets noted in a comment in the HEAD section π.::html::bodyTag argsβ Generates a body tag. The tag parameters come fromargsor from thebody.*attributes define with::html::init.::html::cell param value ?tag?β Generates atd(orth) tag, a value, and a closingtd(orth) tag. The tag parameters come fromparamorTD.*attributes defined with::html::init. This uses::html::fontto insert a standard font tag into the table cell. Thetagargument defaults to"td".::html::checkbox name valueβ Generates a checkbox form element with the specifiednameandvalue. This uses::html::checkValue. β::html::checkSet key sep listβ Generates a whole set of checkbox form elements and their associated labels. Thelistshould contain an alternating list of labels and values. This uses::html::checkbox. All the checkbox buttons share the samekeyfor their name. Thesepis the text used to separate the elements.::html::checkValue name ?value?β Generates the"name=name value=value"for a checkbox form element. If the CGI variablenamehas the valuevalue, thenSELECTEDis added to the return value.valuedefaults to"1".::html::closeTagβ Pops a tag off the stack created by::html::openTagand generates the corresponding close tag (e.g.,</body>). π«Ά::html::default key ?param?β This procedure is used by::html::tagParamto generate the name, value list of parameters for a tag. The::html::defaultprocedure is used to generate default values for those items not already inparam. If the value identified bykeymatches a value inparamthen this procedure returns the empty string. Otherwise, it returns a"parameter=value"string for a form element identified bykey. Thekeyhas the form"tag.parameter"(e.g.,body.bgcolor). Use::html::initto register default values.paramdefaults to the empty string.::html::description descriptionβ Side effect only. Call this before::html::headto define a description meta tag for the page. This tag is generated later in the call to::html::head.::html::endβ Pops all open tags from the stack and generates the corresponding close HTML tags, (e.g.,</body></html>). closing time, you don't gotta go home but you gotta get out of here π::html::eval arg ?args?β This procedure is similar to the built-in Tclevalcommand. The only difference is that it returns""so it can be called from an HTML template file without appending unwanted results. sneaky clean β¨::html::extractParam param key ?varName?β This is a parsing procedure that extracts the value ofkeyfromparam, which is a HTML-style"name=quotedvalue"list.varNameis used as the name of a Tcl variable that is changed to have the value found in the parameters. The function returns1if the parameter was found inparam, otherwise it returns0. If thevarNameis not specified, thenkeyis used as the variable name.::html::font argsβ Generates a standard font tag. The parameters to the tag are taken fromargsand the HTML defaults defined with::html::init.::html::for start test next bodyβ This procedure is similar to the built-in Tclforcontrol structure. Rather than evaluating thebody, it returns the subst'edbody. Each iteration of the loop causes another string to be concatenated to the result value. π::html::foreach varlist1 list1 ?varlist2 list2 ...? bodyβ This procedure is similar to the built-in Tclforeachcontrol structure. Rather than evaluating thebody, it returns the subst'edbody. Each iteration of the loop causes another string to be concatenated to the result value.::html::formValue name ?defvalue?β Returns a name and value pair, where the value is initialized from existing CGI data, if any. The result has this form:
name="fred" value="freds value"
::html::getFormInfo argsβ Generates hidden fields to capture form values. Ifargsis empty, then hidden fields are generated for all CGI values. Otherwiseargsis a list of string match patterns for form element names. π΅οΈββοΈ::html::getTitleβ Returns the title string, with out the surrounding title tag, set with a previous call to::html::title.::html::h level string ?param?β Generates a heading (e.g.,hlevel) tag. Thestringis nested in the heading, andparamis used for the tag parameters.::html::h1 string ?param?β Generates anh1tag. See::html::h.::html::h2 string ?param?β Generates anh2tag. See::html::h.::html::h3 string ?param?β Generates anh3tag. See::html::h.::html::h4 string ?param?β Generates anh4tag. See::html::h.::html::h5 string ?param?β Generates anh5tag. See::html::h.::html::h6 string ?param?β Generates anh6tag. See::html::h.::html::hdrRow argsβ Generates a table row, includingtrandthtags. Each value inargsis place into its own table cell. This uses::html::cell. π::html::head titleβ Generates the head section that includes the page title. If previous calls have been made to::html::author,::html::keywords,::html::description, or::html::metathen additional tags are inserted into the head section. This leaves an open html tag pushed on the stack with::html::openTag.::html::headTag stringβ Saves a tag for inclusion in the head section generated by::html::head. Thestringis everything in the tag except the enclosing angle brackets,< >.::html::html_entities stringβ This command replaces all special characters in thestringwith their HTML entities and returns the modified text. glow up for your ampersands fr π::html::if expr1 body1 ?elseif expr2 body2 ...? ?else bodyN?β This procedure is similar to the built-in Tclifcontrol structure. Rather than evaluating the body of the branch that is taken, it returns the subst'ed body. Note that the syntax is slightly more restrictive than that of the built-in Tclifcontrol structure.::html::init ?list?β::html::initaccepts a Tcl-style name-value list that defines values for items with a name of the form"tag.parameter". For example, a default with key"body.bgcolor"defines the background color for the body tag.::html::keywords argsβ Side effect only. Call this before::html::headto define a keyword meta tag for the page. The meta tag is included in the result of::html::head.::html::mailto email ?subject?β Generates a hypertext link to amailto:URL. π§::html::meta argsβ Compatibility name forhtml::meta_name.::html::meta_name argsβ Side effect only. Call this before::html::headto define a meta tag for the page. The arguments (args) are a Tcl-style name, value list that is used for thename=andcontent=attributes of the meta tag. The meta tag is included in the result of::html::head.::html::meta_equiv argsβ Side effect only. Call this before::html::headto define a meta tag for the page. The arguments (args) are a Tcl-style name, value list that is used for thehttp-equiv=andcontent=attributes of the meta tag. The meta tag is included in the result of::html::head.
part 2 incoming bestie, don't go anywhere π
::html::meta_charset charsetβ Side effect only. Call this before::html::headto define a meta tag for the page. The charset is used with thecharset=attribute of the meta tag. The meta tag is included in the result of::html::head.::html::css hrefβ Side effect only. Call this before::html::headto define a link tag for a linked CSS document. Thehrefvalue is a HTTP URL to a CSS document. The link tag is included in the result of::html::head.- Multiple calls of this command are allowed, enabling the use of multiple CSS document references. In other words, the arguments of multiple calls are accumulated, and do not overwrite each other.
::html::css-clearβ Side effect only. Call this before::html::headto clear all links to CSS documents.- Multiple calls of this command are allowed, doing nothing after the first of a sequence with no intervening
::html::css.
- Multiple calls of this command are allowed, doing nothing after the first of a sequence with no intervening
::html::js hrefβ Side effect only. Call this before::html::headto define a script tag for a linked JavaScript document. Thehrefis a HTTP URL to a JavaScript document. The script tag is included in the result of::html::head.- Multiple calls of this command are allowed, enabling the use of multiple JavaScript document references. In other words, the arguments of multiple calls are accumulated, and do not overwrite each other.
::html::js-clearβ Side effect only. Call this before::html::headto clear all links to JavaScript documents.- Multiple calls of this command are allowed, doing nothing after the first of a sequence with no intervening
::html::js.
- Multiple calls of this command are allowed, doing nothing after the first of a sequence with no intervening
::html::minorList list ?ordered?β Generate an ordered or unordered list of links. Thelistis a Tcl-style name, value list of labels and urls for the links.orderedis a boolean used to choose between an ordered or unordered list. It defaults tofalse.::html::minorMenu list ?sep?β Generate a series of hypertext links. Thelistis a Tcl-style name, value list of labels and urls for the links. Thesepis the text to put between each link. It defaults to" | ".::html::nl2br stringβ This command replaces all line-endings in thestringwith abrtag and returns the modified text.::html::openTag tag ?param?β Pushtagonto a stack and generate the opening tag fortag. Use::html::closeTagto pop the tag from the stack. The second argument provides any tag arguments, as a list whose elements are formatted to be in the form"key=value".::html::paramRow list ?rparam? ?cparam?β Generate a table row, includingtrandtdtags. Each value inlistis placed into its own table cell. This uses::html::cell. The value ofrparamis used as parameter for thetrtag. The value ofcparamis passed to::html::cellas parameter for thetdtags.::html::passwordInput ?name?β Generate aninputtag of typepassword. Thenamedefaults to"password".::html::passwordInputRow label ?name?β Format a table row containing alabeland aninputtag of typepassword. Thenamedefaults to"password".::html::quoteFormValue valueβ Quote special characters invalueby replacing them with HTML entities for quotes, ampersand, and angle brackets.::html::radioSet key sep listβ Generate a set ofinputtags of typeradioand an associated text label. All the radio buttons share the samekeyfor theirname. Thesepis text used to separate the elements. Thelistis a Tcl-style label, value list.::html::radioValue name valueβ Generate the"name=name value=value"for a radio form element. If the CGI variablenamehas the valuevalue, thenSELECTEDis added to the return value.::html::refresh seconds urlβ Set up a refresh meta tag. Call this before::html::headand the HEAD section will contain a meta tag that causes the document to refresh insecondsseconds. Theurlis optional. If specified, it specifies a new page to load after the refresh interval.::html::row argsβ Generate a table row, includingtrandtdtags. Each value inargsis placed into its own table cell. This uses::html::cell. Ignores any default information set up via::html::init.::html::select name param choices ?current?β Generate aselectform element and nestedoptiontags. Thenameandparamare used to generate theselecttag. Thechoiceslist is a Tcl-style name, value list.::html::selectPlain name param choices ?current?β Like::html::selectexcept thatchoicesis a Tcl list of values used for theoptiontags. The label and the value for each option are the same.::html::set var valβ This procedure is similar to the built-in Tclsetcommand. The main difference is that it returns""so it can be called from an HTML template file without appending unwanted results. The other difference is that it must take two arguments.::html::submit label ?name? ?title?β Generate aninputtag of typesubmit. Thenamedefaults to"submit". When a non-emptytitlestring is specified the button gains atitle=attribute with that value.::html::tableFromArray arrname ?param? ?pat?β Generate a two-column table and nested rows to display a Tcl array. The table gets a heading that matches the array name, and each generated row contains a name, value pair. The array names are sorted (lsortwithout special options). The argumentparamis for thetabletag and has to contain a pre-formatted string. Thepatis a string match pattern used to select the array elements to show in the table. It defaults to*, i.e. the whole array is shown.::html::tableFromList querylist ?param?β Generate a two-column table and nested rows to displayquerylist, which is a Tcl dictionary. Each generated row contains a name, value pair. The information is shown in the same order as specified in the dictionary. The argumentparamis for thetabletag and has to contain a pre-formatted string.::html::textarea name ?param? ?current?β Generate atextareatag wrapped around its current values.::html::textInput name value argsβ Generate aninputform tag with typetext. This uses::html::formValue. Theargsis any additional tag attributes you want to put into theinputtag.::html::textInputRow label name value argsβ Generate aninputform tag with typetextformatted into a table row with an associated label. Theargsis any additional tag attributes you want to put into theinputtag.::html::varEmpty nameβ This returns1if the named variable either does not exist or has the empty string for its value.::html::while test bodyβ This procedure is similar to the built-in Tclwhilecontrol structure. Rather than evaluating thebody, it returns thesubst'ed body. Each iteration of the loop causes another string to be concatenated to the result value.::html::doctype idβ This procedure can be used to build the standard DOCTYPE declaration string. It will return the standard declaration string for theid, or throw an error if theidis not known. The followingid's are defined:HTML32HTML40HTML40THTML40FHTML401HTML401THTML401FXHTML10SXHTML10TXHTML10FXHTML11XHTMLB
::html::wrapTag tag ?text? ?args?β A helper to wrap a text in a pair of open/close tags. The arguments (args) are a Tcl-style name, value list that is used to provide attributes and associated values to the opening tag. The result is a string with the open tag along with the optional attributes, the optionaltext, and the closed tag.
π BUGS, IDEAS, FEEDBACK π
Okay bestie, real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category html of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. Please also report any ideas for enhancements you may have for either package and/or documentation.
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.
π SEE ALSO β¨
htmlparsencgi
π KEYWORDS π
checkboxcheckbuttonformhtmlradiobuttontable
π·οΈ CATEGORY π
CGI programming
That's the whole vibe, bestie! This page is from tcllib 1.6 and it's the html(n) manual. Slay! π β¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms