Implemented experimental formatParagraphs() method that uses p tags to format paragraphs
This commit is contained in:
parent
253ca75822
commit
186f7d37d7
1 changed files with 29 additions and 1 deletions
|
@ -65,7 +65,7 @@ public class GlobalObject extends ScriptableObject {
|
|||
String[] globalFuncs = {
|
||||
"renderSkin", "renderSkinAsString", "getProperty",
|
||||
"authenticate", "createSkin", "format", "encode",
|
||||
"encodeXml", "encodeForm", "stripTags",
|
||||
"encodeXml", "encodeForm", "stripTags", "formatParagraphs",
|
||||
"getXmlDocument", "getHtmlDocument",
|
||||
"getDBConnection", "getURL", "write", "writeln"
|
||||
};
|
||||
|
@ -372,6 +372,34 @@ public class GlobalObject extends ScriptableObject {
|
|||
return HtmlEncoder.encode(toString(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param str ...
|
||||
*
|
||||
* @return ...
|
||||
*/
|
||||
public String formatParagraphs(Object obj) {
|
||||
String str = toString(obj);
|
||||
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int l = str.length();
|
||||
|
||||
if (l == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// try to make stringbuffer large enough from the start
|
||||
StringBuffer buffer = new StringBuffer(Math.round(l * 1.4f));
|
||||
|
||||
HtmlEncoder.encode(str, buffer, true, null);
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue