• Publicity: Public Only All

text-html-procs.tcl

Contains procs used to manipulate chunks of text and html, most notably converting between them.

Location:
packages/acs-tcl/tcl/text-html-procs.tcl
Created:
19 July 2000
Author:
Lars Pind <lars@pinds.com>
CVS Identification:
$Id: text-html-procs.tcl,v 1.109.2.27 2022/03/09 17:14:01 gustafn Exp $

Procedures in this file

Detailed information

ad_convert_to_html (public)

 ad_convert_to_html [ -html_p html_p ] text

Convenient interface to convert text or html into html. Does the same as ad_html_text_convert -to html.

Switches:
-html_p (defaults to "f") (optional)
specify t if the value of text is formatted in HTML, or f if text is plaintext.
Parameters:
text
Author:
Lars Pind <lars@pinds.com>
Created:
19 July 2000

Partial Call Graph (max 5 caller/called nodes):
%3 test_general_comments_create_link general_comments_create_link (test general-comments) ad_convert_to_html ad_convert_to_html test_general_comments_create_link->ad_convert_to_html ad_html_text_convert ad_html_text_convert (public) ad_convert_to_html->ad_html_text_convert general_comments_new general_comments_new (public) general_comments_new->ad_convert_to_html

Testcases:
general_comments_create_link

ad_convert_to_text (public)

 ad_convert_to_text [ -html_p html_p ] text

Convenient interface to convert text or html into plaintext. Does the same as ad_html_text_convert -to text.

Switches:
-html_p (defaults to "t") (optional)
specify t if the value of text is formatted in HTML, or f if text is plaintext.
Parameters:
text
Author:
Lars Pind <lars@pinds.com>
Created:
19 July 2000

Partial Call Graph (max 5 caller/called nodes):
%3 ad_html_text_convert ad_html_text_convert (public) ad_convert_to_text ad_convert_to_text ad_convert_to_text->ad_html_text_convert

Testcases:
No testcase defined.

ad_dom_sanitize_html (public)

 ad_dom_sanitize_html -html html [ -allowed_tags allowed_tags ] \
    [ -allowed_attributes allowed_attributes ] \
    [ -allowed_protocols allowed_protocols ] \
    [ -unallowed_tags unallowed_tags ] \
    [ -unallowed_attributes unallowed_attributes ] \
    [ -unallowed_protocols unallowed_protocols ] [ -no_js ] \
    [ -no_outer_urls ] [ -validate ] [ -fix ]

Sanitizes HTML by specified criteria, basically removing unallowed tags and attributes, JavaScript or outer references into page URLs. When desired, this proc can act also as just a validator in order to enforce some markup policies.

Switches:
-html (required)
the markup to be checked.
-allowed_tags (optional)
list of tags we allow in the markup.
-allowed_attributes (optional)
list of attributes we allow in the markup.
-allowed_protocols (optional)
list of attributes we allow into links
-unallowed_tags (optional)
list of tags we don't allow in the markup.
-unallowed_attributes (optional)
list of attributes we don't allow in the markup.
-unallowed_protocols (optional)
list of protocols we don't allow in the markup. Protocol-relative URLs are allowed, but only if proc is called from a connection thread, as we need to determine our current connection protocol.
-no_js (boolean) (optional)
this flag decides whether every script tag, inline event handlers and the javascript: pseudo-protocol should be stripped from the markup.
-no_outer_urls (boolean) (optional)
this flag tells the proc to remove every reference to external addresses. Proc will try to distinguish between external URLs and fine fully specified internal ones. Acceptable URLs will be transformed in absolute local references, others will be just stripped together with the attribute. Absolute URLs referring to our host are allowed, but require the proc being called from a connection thread in order to determine the proper current url.
-validate (boolean) (optional)
This flag will avoid the creation of the stripped markup and just report whether the original one respects all the specified requirements.
-fix (boolean) (optional)
When parsing fails on markup as it is, try to fix it by, for example, closing unclosed tags or normalizing attribute specification. This operation will remove most of plain whitespace into text content of original HTML, together with every comment and the eventually present DOCTYPE declaration.
Returns:
sanitized markup or a (0/1) truth value when the -validate flag is specified
Author:
Antonio Pisano

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_dom_sanitize_html ad_dom_sanitize_html (test acs-tcl) ad_dom_sanitize_html ad_dom_sanitize_html test_ad_dom_sanitize_html->ad_dom_sanitize_html ad_conn ad_conn (public) ad_dom_sanitize_html->ad_conn ad_dom_fix_html ad_dom_fix_html (private) ad_dom_sanitize_html->ad_dom_fix_html ad_log ad_log (public) ad_dom_sanitize_html->ad_log ad_parameter_all_values_as_list ad_parameter_all_values_as_list (public) ad_dom_sanitize_html->ad_parameter_all_values_as_list dom dom ad_dom_sanitize_html->dom

Testcases:
ad_dom_sanitize_html

ad_enhanced_text_to_html (public)

 ad_enhanced_text_to_html text

Converts enhanced text format to normal HTML.

Parameters:
text
Author:
Lars Pind <lars@pinds.com>
Created:
2003-01-27

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_tcl__process_enhanced_correctly acs_tcl__process_enhanced_correctly (test acs-tcl) ad_enhanced_text_to_html ad_enhanced_text_to_html test_acs_tcl__process_enhanced_correctly->ad_enhanced_text_to_html test_ad_enhanced_text_to_html ad_enhanced_text_to_html (test acs-tcl) test_ad_enhanced_text_to_html->ad_enhanced_text_to_html test_ad_html_text_convert ad_html_text_convert (test acs-tcl) test_ad_html_text_convert->ad_enhanced_text_to_html ad_text_to_html ad_text_to_html (public) ad_enhanced_text_to_html->ad_text_to_html ad_enhanced_text_to_plain_text ad_enhanced_text_to_plain_text (public) ad_enhanced_text_to_plain_text->ad_enhanced_text_to_html ad_html_text_convert ad_html_text_convert (public) ad_html_text_convert->ad_enhanced_text_to_html xowiki::Page instproc substitute_markup xowiki::Page instproc substitute_markup xowiki::Page instproc substitute_markup->ad_enhanced_text_to_html

Testcases:
ad_enhanced_text_to_html, ad_html_text_convert, acs_tcl__process_enhanced_correctly

ad_enhanced_text_to_plain_text (public)

 ad_enhanced_text_to_plain_text [ -maxlen maxlen ] text

Converts enhanced text format to normal plaintext format.

Switches:
-maxlen (defaults to "70") (optional)
Parameters:
text
Author:
Lars Pind <lars@pinds.com>
Created:
2003-01-27

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_html_text_convert ad_html_text_convert (test acs-tcl) ad_enhanced_text_to_plain_text ad_enhanced_text_to_plain_text test_ad_html_text_convert->ad_enhanced_text_to_plain_text ad_enhanced_text_to_html ad_enhanced_text_to_html (public) ad_enhanced_text_to_plain_text->ad_enhanced_text_to_html ad_html_to_text ad_html_to_text (public) ad_enhanced_text_to_plain_text->ad_html_to_text ad_html_text_convert ad_html_text_convert (public) ad_html_text_convert->ad_enhanced_text_to_plain_text

Testcases:
ad_html_text_convert

ad_html_qualify_links (public)

 ad_html_qualify_links [ -location location ] [ -path path ] html

Convert in the HTML text relative URLs into fully qualified URLs including the hostname. It performs the following operations: 1. prepend paths starting with a "/" by the location (protocol and host). 2. prepend paths not starting a "/" by the path, in case it was passed in. Links, which are already fully qualified are not modified.

Switches:
-location (optional)
protocol and host (defaults to [ad_url])
-path (optional)
optional path to be prepended to paths not starting with a "/"
Parameters:
html - HTML text, in which substitutions should be performed.

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_html_qualify_links ad_html_qualify_links (test acs-tcl) ad_html_qualify_links ad_html_qualify_links test_ad_html_qualify_links->ad_html_qualify_links util_current_location util_current_location (public) ad_html_qualify_links->util_current_location notification::email::send notification::email::send (public) notification::email::send->ad_html_qualify_links xowiki::notification::do_notifications xowiki::notification::do_notifications (public) xowiki::notification::do_notifications->ad_html_qualify_links

Testcases:
ad_html_qualify_links

ad_html_security_check (public)

 ad_html_security_check [ -allowed_tags allowed_tags ] \
    [ -allowed_attributes allowed_attributes ] \
    [ -allowed_protocols allowed_protocols ] html

Returns a human-readable explanation if the user has used any HTML tag other than the allowed ones. It uses for checking the provided values. If these values are not provided the function takes the union of the per-package instance value and the values from the "antispam" section of the kernel parameters.

Switches:
-allowed_tags (optional)
-allowed_attributes (optional)
-allowed_protocols (optional)
Parameters:
html - The HTML text being validated.
Returns:
a human-readable, plaintext explanation of what's wrong with the user's input. If everthing is ok, return an empty string.
Author:
Lars Pind <lars@pinds.com>
Created:
20 July 2000

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_html_security_check_forbidden_protolcols ad_html_security_check_forbidden_protolcols (test acs-tcl) ad_html_security_check ad_html_security_check test_ad_html_security_check_forbidden_protolcols->ad_html_security_check test_ad_html_security_check_forbidden_tags ad_html_security_check_forbidden_tags (test acs-tcl) test_ad_html_security_check_forbidden_tags->ad_html_security_check test_ad_html_security_check_href_allowed ad_html_security_check_href_allowed (test acs-tcl) test_ad_html_security_check_href_allowed->ad_html_security_check ad_parameter_all_values_as_list ad_parameter_all_values_as_list (public) ad_html_security_check->ad_parameter_all_values_as_list ad_parse_html_attributes_upvar ad_parse_html_attributes_upvar (public) ad_html_security_check->ad_parse_html_attributes_upvar ad_page_contract_filter_proc_html ad_page_contract_filter_proc_html (public) ad_page_contract_filter_proc_html->ad_html_security_check packages/calendar/www/cal-item-new.tcl packages/calendar/ www/cal-item-new.tcl packages/calendar/www/cal-item-new.tcl->ad_html_security_check packages/news/www/preview.tcl packages/news/ www/preview.tcl packages/news/www/preview.tcl->ad_html_security_check template::data::validate::richtext template::data::validate::richtext (public) template::data::validate::richtext->ad_html_security_check template::data::validate::richtext_or_file template::data::validate::richtext_or_file (public) template::data::validate::richtext_or_file->ad_html_security_check

Testcases:
ad_html_security_check_href_allowed, ad_html_security_check_forbidden_protolcols, ad_html_security_check_forbidden_tags

ad_html_text_convert (public)

 ad_html_text_convert [ -from from ] [ -to to ] [ -maxlen maxlen ] \
    [ -truncate_len truncate_len ] [ -ellipsis ellipsis ] \
    [ -more more ] text

Converts a chunk of text from a variety of formats to either text/html or text/plain.

Example: ad_html_text_convert -from "text/html" -to "text/plain" -- "text"

Putting in the -- prevents Tcl from treating a - in text portion from being treated as a parameter.

Html to html closes any unclosed html tags (see util_close_html_tags).

Text to HTML does ad_text_to_html, and HTML to text does an ad_html_to_text. See those procs for details.

When text is empty, then an empty string will be returned regardless of any format. This is especially useful when displaying content that was created with the richtext widget and might contain empty values for content and format.

Switches:
-from (defaults to "text/plain") (optional)
specify what type of text you're providing. Allowed values:
  • text/plain
  • text/enhanced
  • text/markdown
  • text/fixed-width
  • text/html
-to (defaults to "text/html") (optional)
specify what format you want this translated into. Allowed values:
  • text/plain
  • text/html
-maxlen (defaults to "70") (optional)
The maximum line width when generating text/plain
-truncate_len (defaults to "0") (optional)
The maximum total length of the output, included ellipsis.
-ellipsis (defaults to "...") (optional)
This will get put at the end of the truncated string, if the string was truncated. However, this counts towards the total string length, so that the returned string including ellipsis is guaranteed to be shorter than the 'truncate_len' provided.
-more (optional)
This will get put at the end of the truncated string, if the string was truncated.
Parameters:
text
Author:
Lars Pind <lars@pinds.com>
Created:
19 July 2000

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_html_text_convert ad_html_text_convert (test acs-tcl) ad_html_text_convert ad_html_text_convert test_ad_html_text_convert->ad_html_text_convert test_ad_text_html_convert_outlook_word_comments ad_text_html_convert_outlook_word_comments (test acs-tcl) test_ad_text_html_convert_outlook_word_comments->ad_html_text_convert test_ad_text_html_convert_to_plain ad_text_html_convert_to_plain (test acs-tcl) test_ad_text_html_convert_to_plain->ad_html_text_convert Markdown::convert Markdown::convert ad_html_text_convert->Markdown::convert Markdown::get_lang_counter Markdown::get_lang_counter ad_html_text_convert->Markdown::get_lang_counter Markdown::register Markdown::register ad_html_text_convert->Markdown::register Markdown::reset_lang_counter Markdown::reset_lang_counter ad_html_text_convert->Markdown::reset_lang_counter ad_enhanced_text_to_html ad_enhanced_text_to_html (public) ad_html_text_convert->ad_enhanced_text_to_html ad_convert_to_html ad_convert_to_html (public) ad_convert_to_html->ad_html_text_convert ad_convert_to_text ad_convert_to_text (public) ad_convert_to_text->ad_html_text_convert auth::get_local_account auth::get_local_account (private) auth::get_local_account->ad_html_text_convert bug_tracker::bug_convert_comment_to_html bug_tracker::bug_convert_comment_to_html (public) bug_tracker::bug_convert_comment_to_html->ad_html_text_convert bug_tracker::bug_convert_comment_to_text bug_tracker::bug_convert_comment_to_text (public) bug_tracker::bug_convert_comment_to_text->ad_html_text_convert

Testcases:
ad_html_text_convert, ad_text_html_convert_outlook_word_comments, ad_text_html_convert_to_plain

ad_html_text_convertable_p (public, deprecated)

 ad_html_text_convertable_p [ -from from ] [ -to to ]
Deprecated. Invoking this procedure generates a warning.

The name of this proc has an spelling error. Use ad_html_text_convertible_p instead.

Switches:
-from (optional)
-to (optional)

See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 ad_get_tcl_call_stack ad_get_tcl_call_stack (public) ad_html_text_convertible_p ad_html_text_convertible_p (public) ad_html_text_convertable_p ad_html_text_convertable_p ad_html_text_convertable_p->ad_get_tcl_call_stack ad_html_text_convertable_p->ad_html_text_convertible_p

Testcases:
No testcase defined.

ad_html_text_convertible_p (public)

 ad_html_text_convertible_p [ -from from ] [ -to to ]

Returns true of ad_html_text_convert can handle the given from and to mime types.

Switches:
-from (optional)
-to (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_html_text_convert ad_html_text_convert (test acs-tcl) ad_html_text_convertible_p ad_html_text_convertible_p test_ad_html_text_convert->ad_html_text_convertible_p ad_html_text_convert ad_html_text_convert (public) ad_html_text_convert->ad_html_text_convertible_p ad_html_text_convertable_p ad_html_text_convertable_p (public, deprecated) ad_html_text_convertable_p->ad_html_text_convertible_p

Testcases:
ad_html_text_convert

ad_html_to_text (public)

 ad_html_to_text [ -maxlen maxlen ] [ -showtags ] [ -no_format ] html

Returns a best-guess plain text version of an HTML fragment. Parses the HTML and does some simple formatting. The parser and formatting is pretty stupid, but it's better than nothing.

Switches:
-maxlen (defaults to "70") (optional)
the line length you want your output wrapped to.
-showtags (boolean) (optional)
causes any unknown (and uninterpreted) tags to get shown in the output.
-no_format (boolean) (optional)
causes hyperlink tags not to get listed at the end of the output.
Parameters:
html
Authors:
Lars Pind <lars@pinds.com>
Aaron Swartz <aaron@swartzfam.com>
Created:
19 July 2000

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_html_to_text_anchor ad_html_to_text_anchor (test acs-tcl) ad_html_to_text ad_html_to_text test_ad_html_to_text_anchor->ad_html_to_text test_ad_html_to_text_bold ad_html_to_text_bold (test acs-tcl) test_ad_html_to_text_bold->ad_html_to_text test_ad_html_to_text_clipped_link ad_html_to_text_clipped_link (test acs-tcl) test_ad_html_to_text_clipped_link->ad_html_to_text test_ad_html_to_text_image ad_html_to_text_image (test acs-tcl) test_ad_html_to_text_image->ad_html_to_text test_html_to_text html_to_text (test acs-tcl) test_html_to_text->ad_html_to_text ad_html_to_text_put_newline ad_html_to_text_put_newline (private) ad_html_to_text->ad_html_to_text_put_newline ad_html_to_text_put_text ad_html_to_text_put_text (private) ad_html_to_text->ad_html_to_text_put_text ad_parse_html_attributes ad_parse_html_attributes (public) ad_html_to_text->ad_parse_html_attributes acs_admin::check_expired_certificates acs_admin::check_expired_certificates (private) acs_admin::check_expired_certificates->ad_html_to_text acs_mail_lite::utils::build_body acs_mail_lite::utils::build_body (public) acs_mail_lite::utils::build_body->ad_html_to_text ad_enhanced_text_to_plain_text ad_enhanced_text_to_plain_text (public) ad_enhanced_text_to_plain_text->ad_html_to_text ad_html_text_convert ad_html_text_convert (public) ad_html_text_convert->ad_html_to_text ad_parse_incoming_email ad_parse_incoming_email (public) ad_parse_incoming_email->ad_html_to_text

Testcases:
html_to_text, ad_html_to_text_bold, ad_html_to_text_anchor, ad_html_to_text_image, ad_html_to_text_clipped_link, text_to_html

ad_js_escape (public)

 ad_js_escape string

Return supplied string with invalid javascript characters property escaped. This makes possible to use the string safely inside javascript code.

Parameters:
string
Author:
Antonio Pisano

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_js_escape ad_js_escape (test acs-tcl) ad_js_escape ad_js_escape test_ad_js_escape->ad_js_escape

Testcases:
ad_js_escape

ad_looks_like_html_p (public)

 ad_looks_like_html_p text

Tries to guess whether the text supplied is text or html.

Parameters:
text - the text you want tested.
Returns:
1 if it looks like html, 0 if not.
Author:
Lars Pind <lars@pinds.com>
Created:
19 July 2000

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_api_browser_api_describe_function acs_api_browser_api_describe_function (test acs-api-browser) ad_looks_like_html_p ad_looks_like_html_p test_acs_api_browser_api_describe_function->ad_looks_like_html_p test_acs_api_browser_api_proc_documentation acs_api_browser_api_proc_documentation (test acs-api-browser) test_acs_api_browser_api_proc_documentation->ad_looks_like_html_p test_acs_api_browser_api_script_documentation acs_api_browser_api_script_documentation (test acs-api-browser) test_acs_api_browser_api_script_documentation->ad_looks_like_html_p test_acs_api_browser_apidoc_format_see acs_api_browser_apidoc_format_see (test acs-api-browser) test_acs_api_browser_apidoc_format_see->ad_looks_like_html_p test_acs_api_browser_apidoc_tclcode_to_html acs_api_browser_apidoc_tclcode_to_html (test acs-api-browser) test_acs_api_browser_apidoc_tclcode_to_html->ad_looks_like_html_p

Testcases:
acs_api_browser_api_describe_function, acs_api_browser_api_proc_documentation, acs_api_browser_api_script_documentation, acs_api_browser_apidoc_format_see, acs_api_browser_apidoc_tclcode_to_html, ad_looks_like_html_p

ad_pad (public)

 ad_pad [ -left ] [ -right ] string length padstring

Tcl implementation of the pad string function found in many DBMSs. One of the directional flags -left or -right must be specified and will dictate whether this will be a lpad or a rpad.

Switches:
-left (boolean) (optional)
text will be appended left of the original string.
-right (boolean) (optional)
text will be appended right of the original string.
Parameters:
string
length
padstring
Returns:
padded string

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_pad ad_pad (test acs-tcl) ad_pad ad_pad test_ad_pad->ad_pad auth::password::email_password auth::password::email_password (private) auth::password::email_password->ad_pad template::widget::dateFragment template::widget::dateFragment (public) template::widget::dateFragment->ad_pad template::widget::numericRange template::widget::numericRange (public) template::widget::numericRange->ad_pad

Testcases:
ad_pad

ad_parse_html_attributes (public)

 ad_parse_html_attributes [ -attribute_array attribute_array ] html \
    [ pos ]

This is a wrapper proc for ad_parse_html_attributes_upvar, so you can parse attributes from a string without upvar'ing. See the documentation for the other proc.

Switches:
-attribute_array (optional)
Parameters:
html
pos (defaults to "0")
Author:
Lars Pind <lars@pinds.com>
Created:
November 10, 2000

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_parse_html_attributes ad_parse_html_attributes (test acs-tcl) ad_parse_html_attributes ad_parse_html_attributes test_ad_parse_html_attributes->ad_parse_html_attributes ad_parse_html_attributes_upvar ad_parse_html_attributes_upvar (public) ad_parse_html_attributes->ad_parse_html_attributes_upvar ad_html_to_text ad_html_to_text (public) ad_html_to_text->ad_parse_html_attributes

Testcases:
ad_parse_html_attributes

ad_parse_html_attributes_upvar (public)

 ad_parse_html_attributes_upvar [ -attribute_array attribute_array ] \
    html_varname pos_varname

Parse attributes in an HTML fragment and return them as a list of lists.

Each element of that list is either a single element, if the attribute had no value, or a two-tuple, with the first element being the name of the attribute and the second being the value. The attribute names are all converted to lowercase.

If you don't really care what happens when the same attribute is present twice, you can also use the attribute_array argument, and the attributes will be set there. For attributes without any value, we'll use the empty string.

Example:

set html {<tag foo = bar baz greble="&quot;hello you sucker&quot;" foo='blah' Heres = '  something for   you to = "consider" '>}
    set pos 5 ; # the 'f' in the first 'foo'

    set attribute_list [ad_parse_html_attributes_upvar -attribute_array attribute_array html pos]
attribute_list will contain the following:
{foo bar} baz {greble {"hello you sucker"}} {foo blah} {heres {  something for   you to = "consider" }}
attribute_array will contain:
attribute_array(foo)='blah'
    attribute_array(greble)='"hello you sucker"'
    attribute_array(baz)=''
    attribute_array(heres)='  something for   you to = "consider" '

Won't alter the string passed in .. promise! We will modify pos_var. Pos_var should point to the first character inside the tag, after the tag name (we don't care if you let if there's some whitespace before the first attribute)

Switches:
-attribute_array (optional)
This is an alternate way of returning the attributes, if you don't care about what happens when the same attribute name is defined twice.
Parameters:
html_varname - the name of the variable holding the HTML fragment. We promise that we won't change the contents of this variable.
pos_varname - the name of the variable holding the position within the html_varname string from which we should start. This should point to a character inside the tag, just after the tag name, and before the first attribute. Note that we will modify this variable. When this proc is done, this variable will point to the tag-closing >. Example: if the tag is <img src="foo">, pos_varname should point to either the space between img and src, or the s in src.
Returns:
A list of list holding the attribute names and values. Each element of that list is either a single element, if the attribute had no value, or a two-tuple, with the first element being the name of the attribute and the second being the value. The attribute names are all converted to lowercase.
Author:
Lars Pind <lars@pinds.com>
Created:
November 10, 2000

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_html_security_check_forbidden_protolcols ad_html_security_check_forbidden_protolcols (test acs-tcl) ad_parse_html_attributes_upvar ad_parse_html_attributes_upvar test_ad_html_security_check_forbidden_protolcols->ad_parse_html_attributes_upvar test_ad_html_security_check_href_allowed ad_html_security_check_href_allowed (test acs-tcl) test_ad_html_security_check_href_allowed->ad_parse_html_attributes_upvar test_ad_html_text_convert ad_html_text_convert (test acs-tcl) test_ad_html_text_convert->ad_parse_html_attributes_upvar test_ad_html_to_text_anchor ad_html_to_text_anchor (test acs-tcl) test_ad_html_to_text_anchor->ad_parse_html_attributes_upvar test_ad_html_to_text_bold ad_html_to_text_bold (test acs-tcl) test_ad_html_to_text_bold->ad_parse_html_attributes_upvar util_expand_entities_ie_style util_expand_entities_ie_style (public) ad_parse_html_attributes_upvar->util_expand_entities_ie_style ad_html_security_check ad_html_security_check (public) ad_html_security_check->ad_parse_html_attributes_upvar ad_parse_html_attributes ad_parse_html_attributes (public) ad_parse_html_attributes->ad_parse_html_attributes_upvar

Testcases:
ad_html_to_text_bold, ad_html_to_text_anchor, ad_html_to_text_image, ad_html_security_check_href_allowed, ad_html_security_check_forbidden_protolcols, ad_html_text_convert

ad_quotehtml (public, deprecated)

 ad_quotehtml arg
Deprecated. Invoking this procedure generates a warning.

Quotes ampersands, double-quotes, and angle brackets in $arg. Analogous to ns_quotehtml except that it quotes double-quotes (which ns_quotehtml does not).

Parameters:
arg

See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 ad_get_tcl_call_stack ad_get_tcl_call_stack (public) ad_quotehtml ad_quotehtml ad_quotehtml->ad_get_tcl_call_stack

Testcases:
No testcase defined.

ad_string_truncate (public)

 ad_string_truncate [ -len len ] [ -ellipsis ellipsis ] [ -more more ] \
    [ -equal ] string

Truncates a string to len characters adding the string provided in the ellipsis parameter if the string was truncated. The length of the resulting string, including the ellipsis, is guaranteed to be shorter or equal than the len specified. Should always be called as ad_string_truncate [-flags ...] -- string since otherwise strings which start with a - will treated as switches, and will cause an error.

Switches:
-len (defaults to "200") (optional)
The length to truncate to. If zero, no truncation will occur.
-ellipsis (defaults to "...") (optional)
This will get put at the end of the truncated string, if the string was truncated. However, this counts towards the total string length, so that the returned string including ellipsis is guaranteed to be shorter or equal than the 'len' provided.
-more (optional)
This will get put at the end of the truncated string, if the string was truncated.
-equal (boolean) (optional)
Parameters:
string - The string to truncate.
Returns:
The truncated string
Author:
Lars Pind <lars@pinds.com>
Created:
September 8, 2002

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_string_truncate ad_string_truncate (test acs-tcl) ad_string_truncate ad_string_truncate test_ad_string_truncate->ad_string_truncate ad_html_text_convert ad_html_text_convert (public) ad_html_text_convert->ad_string_truncate bug_tracker::bug::get_multirow bug_tracker::bug::get_multirow (public) bug_tracker::bug::get_multirow->ad_string_truncate notification::new notification::new (public) notification::new->ad_string_truncate packages/acs-admin/www/auth/authority.tcl packages/acs-admin/ www/auth/authority.tcl packages/acs-admin/www/auth/authority.tcl->ad_string_truncate packages/acs-admin/www/auth/batch-job.tcl packages/acs-admin/ www/auth/batch-job.tcl packages/acs-admin/www/auth/batch-job.tcl->ad_string_truncate

Testcases:
ad_string_truncate

ad_string_truncate_middle (public)

 ad_string_truncate_middle [ -ellipsis ellipsis ] [ -len len ] string

Cut middle part of a string in case it is too long.

Switches:
-ellipsis (defaults to "...") (optional)
placeholder for the portion of text being left out
-len (defaults to "100") (optional)
length after which we are starting cutting text
Parameters:
string
Returns:
truncated string

See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_string_truncate_middle ad_string_truncate_middle (test xotcl-request-monitor) ad_string_truncate_middle ad_string_truncate_middle test_ad_string_truncate_middle->ad_string_truncate_middle packages/xotcl-request-monitor/www/last-requests.tcl packages/xotcl-request-monitor/ www/last-requests.tcl packages/xotcl-request-monitor/www/last-requests.tcl->ad_string_truncate_middle packages/xotcl-request-monitor/www/stat-details.tcl packages/xotcl-request-monitor/ www/stat-details.tcl packages/xotcl-request-monitor/www/stat-details.tcl->ad_string_truncate_middle string_truncate_middle string_truncate_middle (public, deprecated) string_truncate_middle->ad_string_truncate_middle

Testcases:
ad_string_truncate_middle

ad_text_to_html (public)

 ad_text_to_html [ -no_links ] [ -no_lines ] [ -no_quote ] \
    [ -includes_html ] [ -encode ] text

Converts plaintext to html. Also translates any recognized email addresses or URLs into a hyperlink.

Switches:
-no_links (boolean) (optional)
will prevent it from highlighting
-no_lines (boolean) (optional)
-no_quote (boolean) (optional)
will prevent it from HTML-quoting output, so this can be run on semi-HTML input and preserve that formatting. This will also cause spaces/tabs to not be replaced with nbsp's, because this can too easily mess up HTML tags.
-includes_html (boolean) (optional)
Set this if the text parameter already contains some HTML which should be preserved.
-encode (boolean) (optional)
This will encode international characters into its html equivalent, like "ü" into ü
Parameters:
text
Authors:
Branimir Dolicki <branimir@arsdigita.com>
Lars Pind <lars@pinds.com>
Created:
19 July 2000

Partial Call Graph (max 5 caller/called nodes):
%3 test_create_form_with_form_instance create_form_with_form_instance (test xowiki) ad_text_to_html ad_text_to_html test_create_form_with_form_instance->ad_text_to_html test_xowiki_test_cases xowiki_test_cases (test xowiki) test_xowiki_test_cases->ad_text_to_html ad_log ad_log (public) ad_text_to_html->ad_log ad_text_cite_to_blockquote ad_text_cite_to_blockquote (private) ad_text_to_html->ad_text_cite_to_blockquote util_convert_line_breaks_to_html util_convert_line_breaks_to_html (public) ad_text_to_html->util_convert_line_breaks_to_html acs_messaging_format_as_html acs_messaging_format_as_html (private) acs_messaging_format_as_html->ad_text_to_html ad_enhanced_text_to_html ad_enhanced_text_to_html (public) ad_enhanced_text_to_html->ad_text_to_html ad_html_text_convert ad_html_text_convert (public) ad_html_text_convert->ad_text_to_html packages/acs-lang/www/admin/batch-editor.tcl packages/acs-lang/ www/admin/batch-editor.tcl packages/acs-lang/www/admin/batch-editor.tcl->ad_text_to_html packages/acs-lang/www/admin/edit-localized-message.tcl packages/acs-lang/ www/admin/edit-localized-message.tcl packages/acs-lang/www/admin/edit-localized-message.tcl->ad_text_to_html

Testcases:
xowiki_test_cases, create_form_with_form_instance

ad_unquotehtml (public)

 ad_unquotehtml arg

reverses ns_quotehtml

Parameters:
arg

See Also:
  • ns_quotehtml

Partial Call Graph (max 5 caller/called nodes):
%3 test_quote_unquote_html quote_unquote_html (test acs-tcl) ad_unquotehtml ad_unquotehtml test_quote_unquote_html->ad_unquotehtml

Testcases:
quote_unquote_html

string_truncate (public, deprecated)

 string_truncate [ args... ]
Deprecated. Invoking this procedure generates a warning.

Truncates a string to len characters adding the string provided in the ellipsis parameter if the string was truncated. The length of the resulting string, including the ellipsis, is guaranteed to be shorter or equal than the len specified. Should always be called as ad_string_truncate [-flags ...] -- string since otherwise strings which start with a - will treated as switches, and will cause an error.

Returns:
The truncated string
Author:
Lars Pind <lars@pinds.com>
Created:
September 8, 2002 DEPRECATED: does not comply with OpenACS naming convention

See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 ad_get_tcl_call_stack ad_get_tcl_call_stack (public) ad_string_truncate ad_string_truncate (public) string_truncate string_truncate string_truncate->ad_get_tcl_call_stack string_truncate->ad_string_truncate

Testcases:
No testcase defined.

string_truncate_middle (public, deprecated)

 string_truncate_middle [ args... ]
Deprecated. Invoking this procedure generates a warning.

Cut middle part of a string in case it is too long DEPRECATED: does not comply with OpenACS naming convention


See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 ad_get_tcl_call_stack ad_get_tcl_call_stack (public) ad_string_truncate_middle ad_string_truncate_middle (public) string_truncate_middle string_truncate_middle string_truncate_middle->ad_get_tcl_call_stack string_truncate_middle->ad_string_truncate_middle

Testcases:
No testcase defined.

util_close_html_tags (public)

 util_close_html_tags html_fragment [ break_soft ] [ break_hard ] \
    [ ellipsis ] [ more ]

Given an HTML fragment, this procedure will close any tags that have been left open. The optional arguments let you specify that the fragment is to be truncated to a certain number of displayable characters. After break_soft, it truncates and closes open tags unless you're within non-breaking tags (e.g., Af). After break_hard displayable characters, the procedure simply truncates and closes any open HTML tags that might have resulted from the truncation.

Note that the internal syntax table dictates which tags are non-breaking. The syntax table has codes:

  • nobr -- treat tag as nonbreaking.
  • discard -- throws away everything until the corresponding close tag.
  • remove -- nuke this tag and its closing tag but leave contents.
  • close -- close this tag if left open.

Parameters:
html_fragment
break_soft (defaults to "0") - the number of characters you want the HTML fragment truncated to. Will allow certain tags (A, ADDRESS, NOBR) to close first.
break_hard (defaults to "0") - the number of characters you want the HTML fragment truncated to. Will truncate, regardless of what tag is currently in action.
ellipsis (optional) - This will get put at the end of the truncated string, if the string was truncated. However, this counts towards the total string length, so that the returned string including ellipsis is guaranteed to be shorter than the 'len' provided.
more (optional) - This will get put at the end of the truncated string, if the string was truncated.
Author:
Jeff Davis <davis@xarg.net>

Partial Call Graph (max 5 caller/called nodes):
%3 test_util_close_html_tags util_close_html_tags (test acs-tcl) util_close_html_tags util_close_html_tags test_util_close_html_tags->util_close_html_tags ad_log ad_log (public) util_close_html_tags->ad_log dom dom util_close_html_tags->dom ad_html_text_convert ad_html_text_convert (public) ad_html_text_convert->util_close_html_tags packages/categories/lib/tree-form.tcl packages/categories/ lib/tree-form.tcl packages/categories/lib/tree-form.tcl->util_close_html_tags packages/categories/www/cadmin/category-form.tcl packages/categories/ www/cadmin/category-form.tcl packages/categories/www/cadmin/category-form.tcl->util_close_html_tags packages/news/www/preview.tcl packages/news/ www/preview.tcl packages/news/www/preview.tcl->util_close_html_tags

Testcases:
util_close_html_tags

util_convert_line_breaks_to_html (public)

 util_convert_line_breaks_to_html [ -includes_html ] text

Convert line breaks to <p> and <br> tags, respectively.

Switches:
-includes_html (boolean) (optional)
Parameters:
text

Partial Call Graph (max 5 caller/called nodes):
%3 test_util_convert_line_breaks_to_html util_convert_line_breaks_to_html (test acs-tcl) util_convert_line_breaks_to_html util_convert_line_breaks_to_html test_util_convert_line_breaks_to_html->util_convert_line_breaks_to_html ad_text_to_html ad_text_to_html (public) ad_text_to_html->util_convert_line_breaks_to_html

Testcases:
util_convert_line_breaks_to_html

util_expand_entities (public)

 util_expand_entities html

Replaces all occurrences of common HTML entities with their plaintext equivalents in a way that's appropriate for pretty-printing.

Currently, the following entities are converted: &lt;, &gt;, &apm;quot;, &amp;, &mdash; and &#151;.

This proc is more suitable for pretty-printing that its sister-proc, util_expand_entities_ie_style. The two differences are that this one is more strict: it requires proper entities i.e., both opening ampersand and closing semicolon, and it doesn't do numeric entities, because they're generally not safe to send to browsers. If we want to do numeric entities in general, we should also consider how they interact with character encodings.

Parameters:
html

Partial Call Graph (max 5 caller/called nodes):
%3 ad_html_to_text_put_text ad_html_to_text_put_text (private) util_expand_entities util_expand_entities ad_html_to_text_put_text->util_expand_entities

Testcases:
No testcase defined.

util_expand_entities_ie_style (public)

 util_expand_entities_ie_style html

Replaces all occurrences of &#111; and &x0f; type HTML character entities to their ASCII equivalents. It also handles lt, gt, quot, ob, cb and amp.

This proc does the expansion in the style of IE and Netscape, which is to say that it doesn't require the trailing semicolon on the entity to replace it with something else. The reason we do that is that this proc was designed for checking HTML for security-issues, and since entities can be used for hiding malicious code, we'd better simulate the liberal interpretation that browsers does, even though it complicates matters.

Unlike its sister proc, util_expand_entities, it also expands numeric entities (#999 or #xff style).

Parameters:
html
Author:
Lars Pind <lars@pinds.com>
Created:
October 17, 2000

Partial Call Graph (max 5 caller/called nodes):
%3 ad_parse_html_attributes_upvar ad_parse_html_attributes_upvar (public) util_expand_entities_ie_style util_expand_entities_ie_style ad_parse_html_attributes_upvar->util_expand_entities_ie_style

Testcases:
No testcase defined.

util_remove_html_tags (public)

 util_remove_html_tags html

Removes everything between < and > from the string.

Parameters:
html

Partial Call Graph (max 5 caller/called nodes):
%3 test_util_remove_html_tags util_remove_html_tags (test acs-tcl) util_remove_html_tags util_remove_html_tags test_util_remove_html_tags->util_remove_html_tags

Testcases:
util_remove_html_tags

wrap_string (public, deprecated)

 wrap_string input [ width ]
Deprecated. Invoking this procedure generates a warning.

wraps a string to be no wider than 80 columns by inserting line breaks

Parameters:
input
width (defaults to "80")

See Also:
  • ns_reflow_text

Partial Call Graph (max 5 caller/called nodes):
%3 packages/acs-subsite/www/admin/system/db-stats.tcl packages/acs-subsite/ www/admin/system/db-stats.tcl wrap_string wrap_string packages/acs-subsite/www/admin/system/db-stats.tcl->wrap_string ad_get_tcl_call_stack ad_get_tcl_call_stack (public) wrap_string->ad_get_tcl_call_stack

Testcases:
No testcase defined.
[ show source ]