From d50d4b8c69e53287f085b591914cf88cdf846efc Mon Sep 17 00:00:00 2001
From: mdb
Date: Sun, 25 Jun 2006 16:15:03 +0000
Subject: [PATCH] Restored the URL processing.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1863 6335cc39-0255-0410-8fd6-9bcaacd3b74c
---
.../com/samskivert/servlet/util/HTMLUtil.java | 43 +++++++++++++------
1 file changed, 29 insertions(+), 14 deletions(-)
diff --git a/src/java/com/samskivert/servlet/util/HTMLUtil.java b/src/java/com/samskivert/servlet/util/HTMLUtil.java
index d30706b7..a018cb0f 100644
--- a/src/java/com/samskivert/servlet/util/HTMLUtil.java
+++ b/src/java/com/samskivert/servlet/util/HTMLUtil.java
@@ -90,20 +90,37 @@ public class HTMLUtil
*/
public static String simpleFormat (String text)
{
- String[] lines = StringUtil.split(text, "\n");
- StringBuilder tbuf = new StringBuilder();
+ // first replace the image and other URLs
+ Matcher m = _url.matcher(text);
+ StringBuffer tbuf = new StringBuffer();
+ while (m.find()) {
+ String match = m.group();
+ String lmatch = match.toLowerCase();
+ if (lmatch.endsWith(".png") ||
+ lmatch.endsWith(".jpg") ||
+ lmatch.endsWith(".gif")) {
+ match = "
";
+ } else {
+ match = "" + match + "";
+ }
+ m.appendReplacement(tbuf, match);
+ }
+ m.appendTail(tbuf);
+
+ // then do our paragraph and list processing
+ String[] lines = StringUtil.split(tbuf.toString(), "\n");
+ StringBuilder lbuf = new StringBuilder();
boolean inpara = false, inlist = false;
-
for (int ii = 0; ii < lines.length; ii++) {
String line = lines[ii];
if (StringUtil.isBlank(lines[ii])) {
if (inlist) {
- tbuf.append("");
+ lbuf.append("");
inlist = false;
}
if (inpara) {
- tbuf.append("
\n");
+ lbuf.append("\n");
inpara = false;
}
continue;
@@ -111,34 +128,32 @@ public class HTMLUtil
if (!inpara) {
inpara = true;
- tbuf.append(" ");
+ lbuf.append("
");
}
if (line.startsWith("*")) {
if (inlist) {
- tbuf.append("
");
+ lbuf.append("");
} else {
- tbuf.append("- ");
+ lbuf.append("
- ");
inlist = true;
}
line = line.substring(1);
}
- tbuf.append(line).append("\n");
+ lbuf.append(line).append("\n");
}
if (inlist) {
- tbuf.append("
");
+ lbuf.append("
");
}
if (inpara) {
- tbuf.append("\n");
+ lbuf.append("\n");
}
- return tbuf.toString().trim();
+ return lbuf.toString().trim();
}
protected static Pattern _url =
Pattern.compile("http://\\S+", Pattern.MULTILINE);
- protected static Pattern _star = Pattern.compile("^\\*", Pattern.MULTILINE);
- protected static Pattern _blank = Pattern.compile("^$", Pattern.MULTILINE);
}