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:
		@@ -52,6 +52,10 @@ public abstract class SafeHtml
 | 
				
			|||||||
              return "wikiPreFormat";
 | 
					              return "wikiPreFormat";
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            public String wikiQuote() {
 | 
				
			||||||
 | 
					              return "wikiQuote";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            public boolean ensureInjected() {
 | 
					            public boolean ensureInjected() {
 | 
				
			||||||
              return false;
 | 
					              return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -139,7 +143,10 @@ public abstract class SafeHtml
 | 
				
			|||||||
  public SafeHtml wikify() {
 | 
					  public SafeHtml wikify() {
 | 
				
			||||||
    final SafeHtmlBuilder r = new SafeHtmlBuilder();
 | 
					    final SafeHtmlBuilder r = new SafeHtmlBuilder();
 | 
				
			||||||
    for (final String p : linkify().asString().split("\n\n")) {
 | 
					    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");
 | 
					        r.openElement("p");
 | 
				
			||||||
        for (final String line : p.split("\n")) {
 | 
					        for (final String line : p.split("\n")) {
 | 
				
			||||||
          r.openSpan();
 | 
					          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) {
 | 
					  private static boolean isPreFormat(final String p) {
 | 
				
			||||||
    return p.contains("\n ") || p.contains("\n\t") || p.startsWith(" ")
 | 
					    return p.contains("\n ") || p.contains("\n\t") || p.startsWith(" ")
 | 
				
			||||||
        || p.startsWith("\t");
 | 
					        || p.startsWith("\t");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ package com.google.gwtexpui.safehtml.client;
 | 
				
			|||||||
import com.google.gwt.resources.client.CssResource;
 | 
					import com.google.gwt.resources.client.CssResource;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public interface SafeHtmlCss extends CssResource {
 | 
					public interface SafeHtmlCss extends CssResource {
 | 
				
			||||||
  String wikiPreFormat();
 | 
					 | 
				
			||||||
  String wikiList();
 | 
					  String wikiList();
 | 
				
			||||||
 | 
					  String wikiPreFormat();
 | 
				
			||||||
 | 
					  String wikiQuote();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,11 +13,17 @@
 | 
				
			|||||||
 * limitations under the License.
 | 
					 * limitations under the License.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.wikiList {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.wikiPreFormat {
 | 
					.wikiPreFormat {
 | 
				
			||||||
  white-space: pre;
 | 
					  white-space: pre;
 | 
				
			||||||
  font-family: 'Lucida Console', 'Lucida Sans Typewriter', Monaco, monospace;
 | 
					  font-family: 'Lucida Console', 'Lucida Sans Typewriter', Monaco, monospace;
 | 
				
			||||||
  font-size: small;
 | 
					  font-size: small;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.wikiList {
 | 
					.wikiQuote {
 | 
				
			||||||
 | 
					  margin-left: 0;
 | 
				
			||||||
 | 
					  border-left: 1px solid #888;
 | 
				
			||||||
 | 
					  padding-left: 5px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,8 @@ limitations under the License.
 | 
				
			|||||||
      position: relative;
 | 
					      position: relative;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    .contents p {
 | 
					    .contents p,
 | 
				
			||||||
 | 
					    .contents blockquote {
 | 
				
			||||||
      -webkit-margin-before: 0;
 | 
					      -webkit-margin-before: 0;
 | 
				
			||||||
      -webkit-margin-after: 0.3em;
 | 
					      -webkit-margin-after: 0.3em;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,7 +54,8 @@
 | 
				
			|||||||
  position: relative;
 | 
					  position: relative;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.contents p,
 | 
					.contents p,
 | 
				
			||||||
.contents ul {
 | 
					.contents ul,
 | 
				
			||||||
 | 
					.contents blockquote {
 | 
				
			||||||
  -webkit-margin-before: 0;
 | 
					  -webkit-margin-before: 0;
 | 
				
			||||||
  -webkit-margin-after: 0.3em;
 | 
					  -webkit-margin-after: 0.3em;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user