From ee72137e524cc6c1b5c5230560d757aab0367b51 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Sun, 24 Nov 2013 18:16:24 -0800 Subject: [PATCH] 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 --- .../gwtexpui/safehtml/client/SafeHtml.java | 34 ++++++++++++++++++- .../gwtexpui/safehtml/client/SafeHtmlCss.java | 3 +- .../gwtexpui/safehtml/client/safehtml.css | 8 ++++- .../gerrit/client/change/Message.ui.xml | 3 +- .../gerrit/client/diff/CommentBoxUi.css | 3 +- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java index 7bd6d118f4..944e8a499a 100644 --- a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java +++ b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java @@ -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"); diff --git a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtmlCss.java b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtmlCss.java index f6836a088d..651ebafa52 100644 --- a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtmlCss.java +++ b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtmlCss.java @@ -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(); } diff --git a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/safehtml.css b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/safehtml.css index fcad92c47a..163c548b9a 100644 --- a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/safehtml.css +++ b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/safehtml.css @@ -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; } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/Message.ui.xml b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/Message.ui.xml index d014ce5a3f..401e5abd82 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/Message.ui.xml +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/Message.ui.xml @@ -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; } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/CommentBoxUi.css b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/CommentBoxUi.css index 36f57b9422..351442b5c7 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/CommentBoxUi.css +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/CommentBoxUi.css @@ -54,7 +54,8 @@ position: relative; } .contents p, -.contents ul { +.contents ul, +.contents blockquote { -webkit-margin-before: 0; -webkit-margin-after: 0.3em; }