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.113 2024/10/27 16:51:11 gustafn Exp $

Procedures in this file

Detailed information

ad_convert_to_html (public, deprecated)

 ad_convert_to_html [ -html_p html_p ] text
Deprecated. Invoking this procedure generates a warning.

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

Switches:
-html_p (optional, defaults to "f")
specify t if the value of text is formatted in HTML, or f if text is plaintext. DEPRECATED: this proc is a trivial wrapper for ad_html_text_convert
Parameters:
text (required)
Author:
Lars Pind <lars@pinds.com>
Created:
19 July 2000
See Also:

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

Testcases:
No testcase defined.

ad_convert_to_text (public, deprecated)

 ad_convert_to_text [ -html_p html_p ] text
Deprecated. Invoking this procedure generates a warning.

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

Switches:
-html_p (optional, defaults to "t")
specify t if the value of text is formatted in HTML, or f if text is plaintext. DEPRECATED: this proc is a trivial wrapper for ad_html_text_convert
Parameters:
text (required)
Author:
Lars Pind <lars@pinds.com>
Created:
19 July 2000
See Also:

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

Testcases:
No testcase defined.

ad_docbook_xml_to_html (private)

 ad_docbook_xml_to_html text

Converts DocBook XML as used in the OpenACS documentation to HTML. This is not a full implementation of all possible DocBook markup, but just a subset sufficient for rendering a substantial subset of the OpenACS documentation.

Parameters:
text (required)
input text
Author:
Gustaf Neumann
Created:
2024-10-27

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

Testcases:
No testcase defined.

ad_dom_fix_html (private)

 ad_dom_fix_html -html html [ -marker marker ] [ -dom ]

Similar in spirit to the famous Tidy command line utility, this proc takes a piece of possibly invalid markup and returns a 'fixed' version where unopened tags have been closed and attribute specifications have been normalized by transforming them in the form attribute-name="attribute value". All attributes with an invalid (non-alphanumeric) name will be stripped.

Be aware that every comment and also the possibly present DOCTYPE declaration will be stripped from the markup. Also, most of tag's internal whitespace will be trimmed. This behavior comes from the htmlparse library used in this implementation.

Switches:
-html (required)
Markup to process
-marker (optional, defaults to "root")
Root element use to enforce a single root of the DOM tree.
-dom (optional, boolean)
When this flag is set, instead of returning markup, the proc will return the tDOM object built during the operation. Useful when the result should be used by tDOM anyway, so we can avoid superfluous parsing.
Returns:
markup or a tDOM document object if the -dom flag is specified
Author:
Antonio Pisano

Partial Call Graph (max 5 caller/called nodes):
%3 ad_dom_sanitize_html ad_dom_sanitize_html (public) ad_dom_fix_html ad_dom_fix_html ad_dom_sanitize_html->ad_dom_fix_html dom dom ad_dom_fix_html->dom

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 on user-submitted content.

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 (optional, boolean)
this flag decides whether every script tag, inline event handlers and the javascript: pseudo-protocol should be stripped from the markup.
-no_outer_urls (optional, boolean)
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 (optional, boolean)
This flag will avoid the creation of the stripped markup and just report whether the original one respects all the specified requirements.
-fix (optional, boolean)
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 aa_test_running_p aa_test_running_p (public) ad_dom_sanitize_html->aa_test_running_p 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 dom dom ad_dom_sanitize_html->dom parameter::get parameter::get (public) ad_dom_sanitize_html->parameter::get ad_page_contract_filter_proc_general_comments_safe ad_page_contract_filter_proc_general_comments_safe (public) ad_page_contract_filter_proc_general_comments_safe->ad_dom_sanitize_html

Testcases:
ad_dom_sanitize_html

ad_enhanced_text_escape_disallowed (private)

 ad_enhanced_text_escape_disallowed text
Parameters:
text (required)

Partial Call Graph (max 5 caller/called nodes):
%3 ad_text_to_html ad_text_to_html (public) ad_enhanced_text_escape_disallowed ad_enhanced_text_escape_disallowed ad_text_to_html->ad_enhanced_text_escape_disallowed acs::icanuse acs::icanuse (public) ad_enhanced_text_escape_disallowed->acs::icanuse

Testcases:
No testcase defined.

ad_enhanced_text_to_html (public)

 ad_enhanced_text_to_html text

Converts enhanced text format to normal HTML.

Parameters:
text (required)
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 (optional, defaults to "70")
Parameters:
text (required)
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 (required)
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 (required)
The HTML text being validated.
Returns:
a human-readable, plaintext explanation of what's wrong with the user's input. If everything 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_html_security_check_helper ad_html_security_check_helper (private) ad_html_security_check->ad_html_security_check_helper parameter::get parameter::get (public) ad_html_security_check->parameter::get 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_security_check_helper (private)

 ad_html_security_check_helper -allowed_tags allowed_tags \
    -allowed_attributes allowed_attributes \
    -allowed_protocols allowed_protocols html

Helper proc for ad_html_security_check doing the hard work

Switches:
-allowed_tags (required)
-allowed_attributes (required)
-allowed_protocols (required)
Parameters:
html (required)
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 ad_html_security_check ad_html_security_check (public) ad_html_security_check_helper ad_html_security_check_helper ad_html_security_check->ad_html_security_check_helper ad_html_security_check_protocol ad_html_security_check_protocol (private) ad_html_security_check_helper->ad_html_security_check_protocol

Testcases:
No testcase defined.

ad_html_security_check_protocol (private)

 ad_html_security_check_protocol [ -attr_name attr_name ] \
    [ -attr_value attr_value ] \
    [ -allowed_protocols allowed_protocols ]

Check for allowed protocol in attribute value

Switches:
-attr_name (optional)
-attr_value (optional)
-allowed_protocols (optional)

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

Testcases:
No testcase defined.

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 (optional, defaults to "text/plain")
specify what type of text you're providing. Allowed values:
  • text/plain
  • text/enhanced
  • text/markdown
  • text/fixed-width
  • text/html
-to (optional, defaults to "text/html")
specify what format you want this translated into. Allowed values:
  • text/plain
  • text/html
-maxlen (optional, defaults to "70")
The maximum line width when generating text/plain
-truncate_len (optional, defaults to "0")
The maximum total length of the output, included ellipsis.
-ellipsis (optional, defaults to "...")
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 (required)
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 test_general_comments_create_link general_comments_create_link (test general-comments) test_general_comments_create_link->ad_html_text_convert ad_docbook_xml_to_html ad_docbook_xml_to_html (private) ad_html_text_convert->ad_docbook_xml_to_html ad_enhanced_text_to_html ad_enhanced_text_to_html (public) ad_html_text_convert->ad_enhanced_text_to_html ad_enhanced_text_to_plain_text ad_enhanced_text_to_plain_text (public) ad_html_text_convert->ad_enhanced_text_to_plain_text ad_html_text_convertible_p ad_html_text_convertible_p (public) ad_html_text_convert->ad_html_text_convertible_p ad_html_to_text ad_html_to_text (public) ad_html_text_convert->ad_html_to_text ad_convert_to_html ad_convert_to_html (public, deprecated) ad_convert_to_html->ad_html_text_convert ad_convert_to_text ad_convert_to_text (public, deprecated) 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, general_comments_create_link

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_html_text_convertible_p ad_html_text_convertible_p (public) ad_log_deprecated ad_log_deprecated (public) ad_html_text_convertable_p ad_html_text_convertable_p ad_html_text_convertable_p->ad_html_text_convertible_p ad_html_text_convertable_p->ad_log_deprecated

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 packages/news/lib/news.tcl packages/news/ lib/news.tcl packages/news/lib/news.tcl->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 (optional, defaults to "70")
the line length you want your output wrapped to.
-showtags (optional, boolean)
causes any unknown (and uninterpreted) tags to get shown in the output.
-no_format (optional, boolean)
causes hyperlink tags not to get listed at the end of the output.
Parameters:
html (required)
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 (private) 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_html_to_text_put_newline (private)

 ad_html_to_text_put_newline output_var

Helper proc for ad_html_to_text

Parameters:
output_var (required)
Authors:
Lars Pind <lars@pinds.com>
Aaron Swartz <aaron@swartzfam.com>
Created:
22 September 2000

Partial Call Graph (max 5 caller/called nodes):
%3 ad_html_to_text ad_html_to_text (public) ad_html_to_text_put_newline ad_html_to_text_put_newline 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_put_text->ad_html_to_text_put_newline

Testcases:
No testcase defined.

ad_html_to_text_put_text (private)

 ad_html_to_text_put_text output_var text

Helper proc for ad_html_to_text

Parameters:
output_var (required)
text (required)
Authors:
Lars Pind <lars@pinds.com>
Aaron Swartz <aaron@swartzfam.com>
Created:
19 July 2000

Partial Call Graph (max 5 caller/called nodes):
%3 ad_html_to_text ad_html_to_text (public) ad_html_to_text_put_text ad_html_to_text_put_text ad_html_to_text->ad_html_to_text_put_text acs::icanuse acs::icanuse (public) ad_html_to_text_put_text->acs::icanuse ad_html_to_text_put_newline ad_html_to_text_put_newline (private) ad_html_to_text_put_text->ad_html_to_text_put_newline

Testcases:
No testcase defined.

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 (required)
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 (required)
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 template::data::validate::nomarkup template::data::validate::nomarkup (public) template::data::validate::nomarkup->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_dimensional

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 (optional, boolean)
text will be appended left of the original string.
-right (optional, boolean)
text will be appended right of the original string.
Parameters:
string (required)
length (required)
padstring (required)
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 packages/calendar/www/view-one-day-display.tcl packages/calendar/ www/view-one-day-display.tcl packages/calendar/www/view-one-day-display.tcl->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 (required)
pos (optional, 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 (private) 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 (private)

 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 (required)
the name of the variable holding the HTML fragment. We promise that we won't change the contents of this variable.
pos_varname (required)
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 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 (required)
See Also:

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

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 (optional, defaults to "200")
The length to truncate to. If zero, no truncation will occur.
-ellipsis (optional, defaults to "...")
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 (optional, boolean)
Parameters:
string (required)
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 (optional, defaults to "...")
placeholder for the portion of text being left out
-len (optional, defaults to "100")
length after which we are starting cutting text
Parameters:
string (required)
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_cite_to_blockquote (private)

 ad_text_cite_to_blockquote text

Convert freestanding paragraphs with lines starting with a ">" into blockquotes.

Parameters:
text (required)

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

Testcases:
No testcase defined.

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 (optional, boolean)
will prevent it from highlighting
-no_lines (optional, boolean)
-no_quote (optional, boolean)
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 (optional, boolean)
Set this if the text parameter already contains some HTML which should be preserved.
-encode (optional, boolean)
This will encode international characters into its html equivalent, like "ü" into ü
Parameters:
text (required)
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_ad_text_to_html ad_text_to_html (test acs-tcl) ad_text_to_html ad_text_to_html test_ad_text_to_html->ad_text_to_html test_create_form_with_form_instance create_form_with_form_instance (test xowiki) 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_enhanced_text_escape_disallowed ad_enhanced_text_escape_disallowed (private) ad_text_to_html->ad_enhanced_text_escape_disallowed 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_close_html_tags_ns_parsehtml util_close_html_tags_ns_parsehtml (private) ad_text_to_html->util_close_html_tags_ns_parsehtml 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:
ad_text_to_html, xowiki_test_cases, create_form_with_form_instance

ad_unquotehtml (public)

 ad_unquotehtml arg

reverses ns_quotehtml

Parameters:
arg (required)
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_log_deprecated ad_log_deprecated (public) ad_string_truncate ad_string_truncate (public) string_truncate string_truncate string_truncate->ad_log_deprecated 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_log_deprecated ad_log_deprecated (public) ad_string_truncate_middle ad_string_truncate_middle (public) string_truncate_middle string_truncate_middle string_truncate_middle->ad_log_deprecated 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 (required)
break_soft (optional, 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 (optional, 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 acs::icanuse acs::icanuse (public) util_close_html_tags->acs::icanuse ad_log ad_log (public) util_close_html_tags->ad_log dom dom util_close_html_tags->dom util_close_html_tags_ns_parsehtml util_close_html_tags_ns_parsehtml (private) util_close_html_tags->util_close_html_tags_ns_parsehtml 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_close_html_tags_ns_parsehtml (private)

 util_close_html_tags_ns_parsehtml html_fragment

Faster version of util_close_html_tags based on ns_parse, but closer to the original semantics and faster than the tdom variant

Parameters:
html_fragment (required)
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 ad_text_to_html ad_text_to_html (public) util_close_html_tags_ns_parsehtml util_close_html_tags_ns_parsehtml ad_text_to_html->util_close_html_tags_ns_parsehtml util_close_html_tags util_close_html_tags (public) util_close_html_tags->util_close_html_tags_ns_parsehtml

Testcases:
No testcase defined.

util_convert_line_breaks_to_html (public)

 util_convert_line_breaks_to_html [ -includes_html ] [ -contains_pre ] \
    text

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

Switches:
-includes_html (optional, boolean)
-contains_pre (optional, boolean)
Parameters:
text (required)

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_text_to_html ad_text_to_html (test acs-tcl) util_convert_line_breaks_to_html util_convert_line_breaks_to_html test_ad_text_to_html->util_convert_line_breaks_to_html test_util_convert_line_breaks_to_html util_convert_line_breaks_to_html (test acs-tcl) test_util_convert_line_breaks_to_html->util_convert_line_breaks_to_html acs::icanuse acs::icanuse (public) util_convert_line_breaks_to_html->acs::icanuse 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, ad_text_to_html

util_expand_entities (public, deprecated)

 util_expand_entities html
Deprecated. Invoking this procedure generates a warning.

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 (required)
See Also:
  • ns_unquotehtml

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

Testcases:
No testcase defined.

util_expand_entities_ie_style (public, deprecated)

 util_expand_entities_ie_style html
Deprecated. Invoking this procedure generates a warning.

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 (required)
Author:
Lars Pind <lars@pinds.com>
Created:
October 17, 2000
See Also:
  • ns_unquotehtml

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

Testcases:
No testcase defined.

util_remove_html_tags (public)

 util_remove_html_tags html

Removes everything between < and > from the string.

Parameters:
html (required)

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 (required)
width (optional, 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_log_deprecated ad_log_deprecated (public) wrap_string->ad_log_deprecated

Testcases:
No testcase defined.
[ show source ]