NaviServer - programmable web server
4.99  5.0

[ Main Table Of Contents | Table Of Contents | Keyword Index ]

textutil-cmds(n) 4.99.30 naviserver "NaviServer Built-in Commands"

Name

textutil-cmds - Utility commands for processing text

Table Of Contents

Synopsis

Description

These commands support common tasks of processin text chunks in webserver applications.

COMMANDS

ns_quotehtml html

Returns the contents of HTML with certain characters that are special in HTML replaced with an escape code. The resulting text can be literally displayed in a webpage with an HTML renderer. Specifically:

& becomes &

< becomes &lt;

> becomes &gt;

' becomes &#39;

" becomes &#34;

All other characters are unmodified in the output.

ns_unquotehtml html

This is essentially the inverse operation of ns_quotehtml and replaces the named and numeric entities in decimal or hexadecimal notation contained in the provided string by their native characters. ASCII control characters are omitted.

ns_striphtml html

Returns the contents of html with all HTML tags removed. This function replaces as well all known HTML4 named entities and numeric entities in decimal or hexadecimal notation by its UTF-8 representations and removes HTML comments. ASCII control characters are omitted.

ns_reflow_text ?-width width? ?-offset offset? ?-prefix prefix? text

Reflow a text to the specified length. The arguments width (default 80) and offset (default 0) are integers referring to number of characters. The prefix can be used to prefix every resulting line with a constant string.

ns_trim ?-subst? ?-delimiter delimiter? ?-prefix prefix? text

Multi-line trim with optional delimiter or prefix. The command is useful, when not the full indentation from the source code file (with a indentation depending on the nesting level) should be preserved on the output (such as SQL statements, HTML markup, etc.).

When neither -delimiter or -prefix is specified all leading whitespace is stripped from the result. When -delimiter is specified, the delimiter is stripped as well. The specified delimiter has to be a single character.

When -prefix is used the specified string will be stripped from lines starting exactly with this prefix (example: use -prefix >> to strip the prefix >> from every line starting with it. This option is mutual exclusive with the option -delimiter.

Optionally, substitution can be used, which is applied before trimming (not really needed but sometimes convenient).

EXAMPLES

 % ns_quotehtml "Hello World!"
 Hello World!
 
 % ns_quotehtml "The <STRONG> tag is used to indicate strongly emphasized text."
 The &lt;STRONG&gt; tag is used to indicate strongly emphasized text.
 
 % ns_quotehtml {<span class="foo">}
 &lt;span class=&#34;foo&#34;&gt;
 % ns_reflow_text -width 15 -prefix "> " "one two three four five six seven eight nine ten"
 > one two three
 > four five six
 > seven eight
 > nine ten
 % ns_striphtml "<MARQUEE direction='right'><BLINK>Hello World!</BLINK></MARQUEE>"
 Hello World!
 % ns_trim {
    SELECT object_id, object_name
    FROM   acs_objects
    WHERE  object_id > 10000
 }
 SELECT object_id, object_name
 FROM   acs_objects
 WHERE  object_id > 10000
 
 % ns_trim -delimiter | {
    | <ul>
    |   <li> one
    |   <li> two
    |   <li> three
    | </ul>
 }
  <ul>
    <li> one
    <li> two
    <li> three
  </ul>
 ns_trim -prefix "> " {
 > line 1
 > line 2 
 }
  
 line 1
 line 2 

See Also

ns_hrefs

Keywords

HTML, encoding, entity, quote, server built-in, text