protected <T extends Appendable & CharSequence> void appendEmptyTagReplacement( @NonNull T output, @NonNull HtmlTagImpl tag) { final String replacement = emptyTagReplacement.replace(tag); if (replacement != null) { appendQuietly(output, replacement); } } }
protected <T extends Appendable & CharSequence> void processInlineTagStart( @NonNull T output, @NonNull Token.StartTag startTag) { final String name = startTag.normalName; final HtmlTagImpl.InlineImpl inline = new HtmlTagImpl.InlineImpl(name, output.length(), extractAttributes(startTag)); ensureNewLineIfPreviousWasBlock(output); if (isVoidTag(name) || startTag.selfClosing) { final String replacement = emptyTagReplacement.replace(inline); if (replacement != null && replacement.length() > 0) { appendQuietly(output, replacement); } // the thing is: we will keep this inline tag in the list, // but in case of void-tag that has no replacement, there will be no // possibility to set a span (requires at least one char) inline.closeAt(output.length()); } inlineTags.add(inline); }
final String replacement = emptyTagReplacement.replace(block); if (replacement != null && replacement.length() > 0) {
@Test public void imageReplacementNoAlt() { final HtmlTag.Inline img = new InlineImpl("img", -1, Collections.<String, String>emptyMap()); assertEquals("\uFFFC", replacement.replace(img)); }
@Test public void imageReplacementAlt() { final HtmlTag.Inline img = new InlineImpl( "img", -1, Collections.singletonMap("alt", "alternative27") ); assertEquals("alternative27", replacement.replace(img)); }
@Test public void brAddsNewLine() { final HtmlTag.Inline br = new InlineImpl( "br", -1, Collections.<String, String>emptyMap() ); assertEquals("\n", replacement.replace(br)); } }