html(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

html(3tcl) β€” HTML Generation πŸ¦‹βœ¨

πŸŽ€ NAME πŸŽ€

html β€” Procedures to generate HTML structures πŸ’…

✨ 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 so the package html is literally your bestie for generating HTML. These commands typically return an HTML string as their result. In particular, they do not output their result to stdout. So no surprise text spam in your terminal, periodt. πŸ’…

The command ::html::init should be called early to initialize the module. You can also use this procedure to define default values for HTML tag parameters. Think of it as setting the vibe before the party starts. πŸŽ‰

::html::author author

Side effect only. Call this before ::html::head to define an author for the page. The author is noted in a comment in the HEAD section. So it’s like a little signature in the code, not visible on the page itself. πŸ–‹οΈ

::html::bodyTag args

Generate a body tag. The tag parameters are taken from args or from the body.* attributes defined with ::html::init. It’s giving main character energy for your whole page. πŸ’ƒ

::html::cell param value ?tag?

Generate a td (or th) tag, a value, and a closing td (or th) tag. The tag parameters come from param or TD.* attributes defined with ::html::init. This uses ::html::font to insert a standard font tag into the table cell. The tag argument defaults to "td". Table cells but make it cute. ✨

::html::checkbox name value

Generate a checkbox form element with the specified name and value. This uses ::html::checkValue. Check it and slay. βœ…

::html::checkSet key sep list

Generate a set of checkbox form elements and associated labels. The list should contain an alternating list of labels and values. This uses ::html::checkbox. All the checkbox buttons share the same key for their name. The sep is text used to separate the elements. So it’s a whole squad of checkboxes, no cap. πŸŽ€

::html::checkValue name ?value?

Generate the "name=name value=value" for a checkbox form element. If the CGI variable name has the value value, then SELECTED is added to the return value. value defaults to "1". So it remembers if you already checked it. Memory? Iconic. 🧠

::html::closeTag

Pop a tag off the stack created by ::html::openTag and generate the corresponding close tag (e.g., </body>). It’s the closing parenthesis of your HTML drama. 🎬

::html::default key ?param?

This procedure is used by ::html::tagParam to generate the name, value list of parameters for a tag. The ::html::default procedure is used to generate default values for those items not already in param. If the value identified by key matches a value in param then this procedure returns the empty string. Otherwise, it returns a "parameter=value" string for a form element identified by key. The key has the form "tag.parameter" (e.g., body.bgcolor). Use ::html::init to register default values. param defaults to the empty string. It’s the backup dancer that fills in when nobody else shows up. πŸ’ƒ

::html::description description

Side effect only. Call this before ::html::head to define a description meta tag for the page. This tag is generated later in the call to ::html::head. SEO but make it fashion. πŸ“

::html::end

Pop all open tags from the stack and generate the corresponding close HTML tags, (e.g., </body></html>). The grand finale, the mic drop. 🎀

::html::eval arg ?args?

This procedure is similar to the built-in Tcl eval command. The only difference is that it returns "" so it can be called from an HTML template file without appending unwanted results. So it’s eval but with a silent exit, lowkey. 🀫

::html::extractParam param key ?varName?

This is a parsing procedure that extracts the value of key from param, which is a HTML-style "name=quotedvalue" list. varName is used as the name of a Tcl variable that is changed to have the value found in the parameters. The function returns 1 if the parameter was found in param, otherwise it returns 0. If the varName is not specified, then key is used as the variable name. Detective work but for HTML params. πŸ”

::html::font args

Generate a standard font tag. The parameters to the tag are taken from args and the HTML defaults defined with ::html::init. It’s the glow-up your text needed. πŸ’…

::html::for start test next body

This procedure is similar to the built-in Tcl for control structure. Rather than evaluating the body, it returns the subst'ed body. Each iteration of the loop causes another string to be concatenated to the result value. Loops but make it HTML. πŸ”

::html::foreach varlist1 list1 ?varlist2 list2 ...? body

This procedure is similar to the built-in Tcl foreach control structure. Rather than evaluating the body, it returns the subst'ed body. Each iteration of the loop causes another string to be concatenated to the result value. Same energy as for, but for each item. πŸ¦‹

::html::formValue name ?defvalue?

Return 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"

So it’s pre-filled and ready to go. πŸ’–

::html::getFormInfo args

Generate hidden fields to capture form values. If args is empty, then hidden fields are generated for all CGI values. Otherwise args is a list of string match patterns for form element names. Sneaky but useful. πŸ•΅οΈβ€β™€οΈ

::html::getTitle

Return the title string, without the surrounding title tag, set with a previous call to ::html::title. It’s like getting the tea without the cup. β˜•

::html::h level string ?param?

Generate a heading (e.g., hlevel) tag. The string is nested in the heading, and param is used for the tag parameters. Headings but customizable. πŸ‘‘

::html::h1 string ?param?

Generate an h1 tag. See ::html::h. The biggest drama heading. πŸ’₯

::html::h2 string ?param?

Generate an h2 tag. See ::html::h. Slightly less main character. ✨

::html::h3 string ?param?

Generate an h3 tag. See ::html::h. Still iconic. πŸŽ€

::html::h4 string ?param?

Generate an h4 tag. See ::html::h. The vibe continues. 🌸

::html::h5 string ?param?

Generate an h5 tag. See ::html::h. Small but mighty. πŸ¦‹

::html::h6 string ?param?

Generate an h6 tag. See ::html::h. The whisper of headings. 🀫

::html::hdrRow args

Generate a table row, including tr and th tags. Each value in args is placed into its own table cell. This uses ::html::cell. Table header row, slay. πŸ“Š

::html::head title

Generate the head section that includes the page title. If previous calls have been made to ::html::author, ::html::keywords, ::html::description, or ::html::meta then additional tags are inserted into the head section. This leaves an open html tag pushed on the stack with ::html::openTag. The head is where the behind-the-scenes magic happens. πŸͺ„

::html::headTag string

Save a tag for inclusion in the head section generated by ::html::head. The string is everything in the tag except the enclosing angle brackets, < >. So you bring the tag, it brings the brackets. 🎁

::html::html_entities string

This command replaces all special characters in the string with their HTML entities and returns the modified text. Escape room but for characters. πŸ”

::html::if expr1 body1 ?elseif expr2 body2 ...? ?else bodyN?

This procedure is similar to the built-in Tcl if control 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 Tcl if control structure. Conditional but with boundaries. 🚧

::html::init ?list?

::html::init accepts 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. This is your setup era. πŸ› οΈ

::html::keywords args

Side effect only. Call this before ::html::head to define a keyword meta tag for the page. The meta tag is included in the result of ::html::head. Keywords but make it meta. πŸ”‘

::html::mailto email ?subject?

Generate a hypertext link to a mailto: URL. Email link, but make it clickable. πŸ“§

::html::meta args

Compatibility name for html::meta_name. It’s the alias that still shows up to the party. πŸ‘―β€β™€οΈ

::html::meta_name args

Side effect only. Call this before ::html::head to define a meta tag for the page. The arguments (args) are a Tcl-style name, value list that is used for the name= and content= attributes of the meta tag. The meta tag is included in the result of ::html::head. Meta but with name. 🏷️

::html::meta_equiv args

Side effect only. Call this before ::html::head to define a meta tag for the page. The arguments (args) are a Tcl-style name, value list that is used for the http-equiv= and content= attributes of the meta tag. The meta tag is included in the result of ::html::head. Meta but with http-equiv. 🌐

  • ::html::meta_charset charset β€” side effect only, bestie! Call this before ::html::head to define a meta tag for the page. The charset gets used with the charset= attribute of the meta tag. That meta tag then shows up in the result of ::html::head. πŸ’–
  • ::html::css href β€” side effect only. Call this before ::html::head to define a link tag for a linked CSS document. The href value is a HTTP URL to a CSS document. The link tag is included in the result of ::html::head. You can call this multiple times β€” it's giving multiple CSS document references! The arguments of multiple calls are accumulated, and do not overwrite each other. Periodt. ✨
  • ::html::css-clear β€” side effect only. Call this before ::html::head to 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. 🧹
  • ::html::js href β€” side effect only. Call this before ::html::head to define a script tag for a linked JavaScript document. The href is a HTTP URL to a JavaScript document. The script tag is included in the result of ::html::head. Multiple calls are allowed, enabling multiple JavaScript document references. The arguments of multiple calls are accumulated, and do not overwrite each other. Slay. πŸ”₯
  • ::html::js-clear β€” side effect only. Call this before ::html::head to 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. 🧼
  • ::html::minorList list ?ordered? β€” Generate an ordered or unordered list of links. The list is a Tcl-style name, value list of labels and urls for the links. ordered is a boolean used to choose between an ordered or unordered list. It defaults to false. πŸ’…
  • ::html::minorMenu list ?sep? β€” Generate a series of hypertext links. The list is a Tcl-style name, value list of labels and urls for the links. The sep is the text to put between each link. It defaults to " | ". 🌸
  • ::html::nl2br string β€” This command replaces all line-endings in the string with a br tag and returns the modified text. No cap. πŸ¦‹
  • ::html::openTag tag ?param? β€” Push tag onto a stack and generate the opening tag for tag. Use ::html::closeTag to 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, including tr and td tags. Each value in list is placed into its own table cell. This uses ::html::cell. The value of rparam is used as parameter for the tr tag. The value of cparam is passed to ::html::cell as parameter for the td tags. πŸ“Š
  • ::html::passwordInput ?name? β€” Generate an input tag of type password. The name defaults to "password". πŸ”’
  • ::html::passwordInputRow label ?name? β€” Format a table row containing a label and an input tag of type password. The name defaults to "password". πŸ”
  • ::html::quoteFormValue value β€” Quote special characters in value by replacing them with HTML entities for quotes, ampersand, and angle brackets. ✨
  • ::html::radioSet key sep list β€” Generate a set of input tags of type radio and an associated text label. All the radio buttons share the same key for their name. The sep is text used to separate the elements. The list is a Tcl-style label, value list. πŸ“»
  • ::html::radioValue name value β€” Generate the "name=name value=value" for a radio form element. If the CGI variable name has the value value, then SELECTED is added to the return value. βœ…
  • ::html::refresh seconds url β€” Set up a refresh meta tag. Call this before ::html::head and the HEAD section will contain a meta tag that causes the document to refresh in seconds seconds. The url is optional. If specified, it specifies a new page to load after the refresh interval. πŸ”„
  • ::html::row args β€” Generate a table row, including tr and td tags. Each value in args is place 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 a select form element and nested option tags. The name and param are used to generate the select tag. The choices list is a Tcl-style name, value list. πŸ“‹
  • ::html::selectPlain name param choices ?current? β€” Like ::html::select except that choices is a Tcl list of values used for the option tags. The label and the value for each option are the same. 🫢
  • ::html::set var val β€” This procedure is similar to the built-in Tcl set command. 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 an input tag of type submit. The name defaults to "submit". When a non-empty title string is specified the button gains a title= 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 (lsort without special options). The argument param is for the table tag and has to contain a pre-formatted string. The pat is 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 display querylist, 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 argument param is for the table tag and has to contain a pre-formatted string. πŸ“š
  • ::html::textarea name ?param? ?current? β€” Generate a textarea tag wrapped around its current values. ✍️
  • ::html::textInput name value args β€” Generate an input form tag with type text. This uses ::html::formValue. The args is any additional tag attributes you want to put into the input tag. ⌨️
  • ::html::textInputRow label name value args β€” Generate an input form tag with type text formatted into a table row with an associated label. The args is any additional tag attributes you want to put into the input tag. πŸ“
  • ::html::varEmpty name β€” This returns 1 if 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 Tcl while control structure. Rather than evaluating the body, it returns the subst'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 the id, or throw an error if the id is not known. The following id's are defined:
    • [1] HTML32
    • [2] HTML40
    • [3] HTML40T
    • [4] HTML40F
    • [5] HTML401
    • [6] HTML401T
    • [7] HTML401F
    • [8] XHTML10S
    • [9] XHTML10T
    • [10] XHTML10F
    • [11] XHTML11
    • [12] XHTMLB
  • ::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 optional text, and the closed tag. 🎁

πŸ› BUGS, IDEAS, FEEDBACK πŸ›

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 [http://core.tcl.tk/tcllib/reportlist](http://core.tcl.tk/tcllib/reportlist). Please also report any ideas for enhancements you may have for either package and/or documentation. We love a glow-up. πŸ’–

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 πŸ‘€

htmlparse, ncgi


πŸ”‘ KEYWORDS πŸ”‘

checkbox, checkbutton, form, html, radiobutton, table


πŸ“‚ CATEGORY πŸ“‚

CGI programming


Okay bestie, that's the whole html(3tcl) page from tcllib, version 1.6 β€” literally every flag, every default, every vibe. Go build something iconic. πŸ’…βœ¨

πŸ“¦ where this page comes from