mozITXTToHTMLConv

The mozITXTToHTMLConv interface is used to convert text into HTML format. Its primary use is in converting user-entered text into properly-formatted HTML.

Please add a summary to this article.
  Last changed in Gecko 1.8.1 (Firefox 2 / Thunderbird 2 / SeaMonkey 1.1)

Inherits from nsIStreamConverter

Implemented by @mozilla.org/txttohtmlconv;1 as a service:

var ios = Components.classes["@mozilla.org/txttohtmlconv;1"]
                    .getService(Components.interfaces.mozITXTToHTMLConv);

Method overview
Edit section

unsigned long citeLevelTXT(in wstring line, out unsigned long logLineStart)
void findURLInPlaintext(in wstring text, in long aLength, in long aPos, out long aStartPos, out long aEndPos)
wstring scanHTML(in wstring text, in unsigned long whattodo)
wstring scanTXT(in wstring text, in unsigned long whattodo)

Constants

Conversion control attributes

These bits allow you to control the conversion of text into HTML.

Constant Type Description
kEntities unsigned long Enables conversion of basic special characters to HTML entities. This applies to "<", "&", and ">" (which are converted to &lt;, &amp;, and &gt;, respectively).
kGlyphSubstitution unsigned long Enables conversion of smilies and non-ASCII special characters.
kStructPhrase unsigned long Enables conversion of text attributes, such as converting "*some text*" to boldfaced "some text" by wrapping in the HTML <strong> element.
kURLs unsigned long Enables automatic addition of hyperlinks for URLs in the text.

Methods

scanTXT()

Scans the specified text, applying the requested conversions and outputting HTML.

wstring scanTXT(
  in wstring text,
  in unsigned long whattodo
);
Parameters
text
The original, plain text to scan and convert into HTML.
whattodo
A bit field comprised of the Conversion control attributes indicating what conversions to apply.
Return value

The HTML version of the specified string.

scanHTML()

Scans the specified user-edited HTML, adding additional formatting that the user may not have known to do. This should correct HTML that isn't entirely standards-compliant.

Warning: Don't use the kGlyphSubstitution conversion type with this method, as doing so generates HTML that is non-standard.
wstring scanHTML(
  in wstring text,
  in unsigned long whattodo
);
Parameters
text
The original, user-edited HTML.
whattodo
A bit field comprised of the Conversion control attributes indicating what conversions to apply.
Return value

A normalized version of the original HTML string.

citeLevelTXT()

Returns the "cite level" of the specified text; that is, it indicates how many levels of email reply quotes are used, when the text uses "quote" characters (such as ">") at the beginning of the line to indicate cite levels.

unsigned long citeLevelTXT(
  in wstring line,
  out unsigned long logLineStart
);
Parameters
line
The original line of text, which may begin with one or more cite characters such as ">".
logLineStart
On output, this parameter is set to indicate the offset into the string of the first non-cite character. You must set this value to zero before calling this method.
Return value

The cite level of the quote; that is, the number of text quote characters found at the beginning of the string.

findURLInPlaintext()

Returns the start and end offsets of the first URL found in a substring.

void findURLInPlaintext(
  in wstring text,
  in long aLength,
  in long aPos,
  out long aStartPos,
  out long aEndPos
);
Parameters
text
The string to scan for the presence of a URL.
aLength
The length of the buffer to scan.
aPos
The character offset into the string at which to begin the scan.
aStartPos
On return, indicates the offset to the first character of the first found URL, or -1 if no URL was found.
aEndPos
On return, indicates the offset to the last character of the first found URL, or -1 if no URL was found.
Remarks

You can call this method repeatedly, passing in updated values for aPos, to locate all the URLs in a string.

Document Tags and Contributors

Tags: 
 Contributors to this page: teoli, Sheppy, Hashem
 Last updated by: Sheppy,