Style quoted text with a bar on the left

Update wikify() to understand the quoted text format now used on
ChangeScreen2 when replying to a comment. Hide the " > " prefix
markers and instead display a horizontal bar down the left margin.
This style of presentation is commonly used in modern email clients
for quoted text.

Change-Id: Ib7cb309a17dedfb00af7fb82c776b07055f8d47d
This commit is contained in:
Shawn Pearce
2013-11-24 18:16:24 -08:00
parent 86c862b4dd
commit ee72137e52
5 changed files with 46 additions and 5 deletions

View File

@@ -52,6 +52,10 @@ public abstract class SafeHtml
return "wikiPreFormat";
}
public String wikiQuote() {
return "wikiQuote";
}
public boolean ensureInjected() {
return false;
}
@@ -139,7 +143,10 @@ public abstract class SafeHtml
public SafeHtml wikify() {
final SafeHtmlBuilder r = new SafeHtmlBuilder();
for (final String p : linkify().asString().split("\n\n")) {
if (isPreFormat(p)) {
if (isQuote(p)) {
wikifyQuote(r, p);
} else if (isPreFormat(p)) {
r.openElement("p");
for (final String line : p.split("\n")) {
r.openSpan();
@@ -202,6 +209,31 @@ public abstract class SafeHtml
}
}
private void wikifyQuote(SafeHtmlBuilder r, String p) {
r.openElement("blockquote");
r.setStyleName(RESOURCES.css().wikiQuote());
if (p.startsWith("> ")) {
p = p.substring(5);
} else if (p.startsWith(" > ")) {
p = p.substring(6);
}
p = p.replaceAll("\\n ?> ", "\n");
for (String e : p.split("\n\n")) {
if (isQuote(e)) {
SafeHtmlBuilder b = new SafeHtmlBuilder();
wikifyQuote(b, e);
r.append(b);
} else {
r.append(asis(e));
}
}
r.closeElement("blockquote");
}
private static boolean isQuote(String p) {
return p.startsWith("> ") || p.startsWith(" > ");
}
private static boolean isPreFormat(final String p) {
return p.contains("\n ") || p.contains("\n\t") || p.startsWith(" ")
|| p.startsWith("\t");

View File

@@ -17,6 +17,7 @@ package com.google.gwtexpui.safehtml.client;
import com.google.gwt.resources.client.CssResource;
public interface SafeHtmlCss extends CssResource {
String wikiPreFormat();
String wikiList();
String wikiPreFormat();
String wikiQuote();
}

View File

@@ -13,11 +13,17 @@
* limitations under the License.
*/
.wikiList {
}
.wikiPreFormat {
white-space: pre;
font-family: 'Lucida Console', 'Lucida Sans Typewriter', Monaco, monospace;
font-size: small;
}
.wikiList {
.wikiQuote {
margin-left: 0;
border-left: 1px solid #888;
padding-left: 5px;
}

View File

@@ -48,7 +48,8 @@ limitations under the License.
position: relative;
}
.contents p {
.contents p,
.contents blockquote {
-webkit-margin-before: 0;
-webkit-margin-after: 0.3em;
}

View File

@@ -54,7 +54,8 @@
position: relative;
}
.contents p,
.contents ul {
.contents ul,
.contents blockquote {
-webkit-margin-before: 0;
-webkit-margin-after: 0.3em;
}