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.

netwerk/streamconv/public/mozITXTToHTMLConv.idlScriptable 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.

ConstantTypeDescription
kEntitiesunsigned longEnables conversion of basic special characters to HTML entities. This applies to "<", "&", and ">" (which are converted to &lt;, &amp;, and &gt;, respectively).
kGlyphSubstitutionunsigned longEnables conversion of smilies and non-ASCII special characters.
kStructPhraseunsigned longEnables conversion of text attributes, such as converting "*some text*" to boldfaced "some text" by wrapping in the HTML <strong> element.
kURLsunsigned longEnables 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 composed 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 composed 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:52 次

字数:7669

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文