Skip to content

Commit 21fdf02

Browse files
authored
Merge pull request #687 from wordpress-mobile/issue/681-citation-italic
Issue/681 citation italic
2 parents 051354a + d41a0ed commit 21fdf02

File tree

6 files changed

+46
-2
lines changed

6 files changed

+46
-2
lines changed

app/src/androidTest/kotlin/org/wordpress/aztec/demo/tests/GutenbergCompatTests.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ class GutenbergCompatTests : BaseTest() {
277277
.verifyHTML("")
278278
}
279279

280+
@Test
281+
fun testRetainCitationInQuote() {
282+
val htmlOriginal = "<!-- wp:quote --><blockquote class=\"wp-block-quote\"><p>quote</p><cite>this is a citation</cite></blockquote><!-- /wp:quote -->"
283+
284+
EditorPage()
285+
.toggleHtml()
286+
.insertHTML(htmlOriginal)
287+
.toggleHtml()
288+
.toggleHtml()
289+
.verifyHTML(htmlOriginal)
290+
}
291+
280292
@Test
281293
fun testDeleteAllItemsFromFirstList() {
282294
val itemOnListTwo = "item 1 on list 2"

aztec/src/main/java/org/wordpress/aztec/Html.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.wordpress.aztec.spans.AztecRelativeSizeBigSpan;
4545
import org.wordpress.aztec.spans.AztecRelativeSizeSmallSpan;
4646
import org.wordpress.aztec.spans.AztecStyleBoldSpan;
47+
import org.wordpress.aztec.spans.AztecStyleCiteSpan;
4748
import org.wordpress.aztec.spans.AztecStyleItalicSpan;
4849
import org.wordpress.aztec.spans.AztecSubscriptSpan;
4950
import org.wordpress.aztec.spans.AztecSuperscriptSpan;
@@ -315,7 +316,7 @@ private void handleStartTag(String tag, Attributes attributes, int nestingLevel)
315316
} else if (tag.equalsIgnoreCase("em")) {
316317
start(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC, attributes);
317318
} else if (tag.equalsIgnoreCase("cite")) {
318-
start(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC, attributes);
319+
start(spannableStringBuilder, AztecTextFormat.FORMAT_CITE, attributes);
319320
} else if (tag.equalsIgnoreCase("dfn")) {
320321
start(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC, attributes);
321322
} else if (tag.equalsIgnoreCase("i")) {
@@ -408,7 +409,7 @@ private void handleEndTag(String tag, int nestingLevel) {
408409
} else if (tag.equalsIgnoreCase("em")) {
409410
end(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC);
410411
} else if (tag.equalsIgnoreCase("cite")) {
411-
end(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC);
412+
end(spannableStringBuilder, AztecTextFormat.FORMAT_CITE);
412413
} else if (tag.equalsIgnoreCase("dfn")) {
413414
end(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC);
414415
} else if (tag.equalsIgnoreCase("i")) {
@@ -490,6 +491,9 @@ private static void start(SpannableStringBuilder text, AztecTextFormat textForma
490491
case FORMAT_ITALIC:
491492
newSpan = new AztecStyleItalicSpan(attributes);
492493
break;
494+
case FORMAT_CITE:
495+
newSpan = new AztecStyleCiteSpan(attributes);
496+
break;
493497
case FORMAT_UNDERLINE:
494498
newSpan = new AztecUnderlineSpan(false, attributes);
495499
break;
@@ -536,6 +540,9 @@ private static void end(SpannableStringBuilder text, AztecTextFormat textFormat)
536540
case FORMAT_ITALIC:
537541
span = (AztecStyleItalicSpan) getLast(text, AztecStyleItalicSpan.class);
538542
break;
543+
case FORMAT_CITE:
544+
span = (AztecStyleCiteSpan) getLast(text, AztecStyleCiteSpan.class);
545+
break;
539546
case FORMAT_UNDERLINE:
540547
span = (AztecUnderlineSpan) getLast(text, AztecUnderlineSpan.class);
541548
break;

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
831831
AztecTextFormat.FORMAT_PREFORMAT -> blockFormatter.toggleHeading(textFormat)
832832
AztecTextFormat.FORMAT_BOLD,
833833
AztecTextFormat.FORMAT_ITALIC,
834+
AztecTextFormat.FORMAT_CITE,
834835
AztecTextFormat.FORMAT_UNDERLINE,
835836
AztecTextFormat.FORMAT_STRIKETHROUGH,
836837
AztecTextFormat.FORMAT_CODE -> inlineFormatter.toggle(textFormat)
@@ -859,6 +860,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
859860
AztecTextFormat.FORMAT_HEADING_6 -> return lineBlockFormatter.containsHeading(format, selStart, selEnd)
860861
AztecTextFormat.FORMAT_BOLD,
861862
AztecTextFormat.FORMAT_ITALIC,
863+
AztecTextFormat.FORMAT_CITE,
862864
AztecTextFormat.FORMAT_UNDERLINE,
863865
AztecTextFormat.FORMAT_STRIKETHROUGH,
864866
AztecTextFormat.FORMAT_CODE -> return inlineFormatter.containsInlineStyle(format, selStart, selEnd)
@@ -1265,6 +1267,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
12651267
fun removeInlineStylesFromRange(start: Int, end: Int) {
12661268
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_BOLD, start, end)
12671269
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_ITALIC, start, end)
1270+
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_CITE, start, end)
12681271
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_STRIKETHROUGH, start, end)
12691272
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_UNDERLINE, start, end)
12701273
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_CODE, start, end)

aztec/src/main/kotlin/org/wordpress/aztec/AztecTextFormat.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ enum class AztecTextFormat : ITextFormat {
1515
FORMAT_ORDERED_LIST,
1616
FORMAT_BOLD,
1717
FORMAT_ITALIC,
18+
FORMAT_CITE,
1819
FORMAT_UNDERLINE,
1920
FORMAT_STRIKETHROUGH,
2021
FORMAT_ALIGN_LEFT,

aztec/src/main/kotlin/org/wordpress/aztec/formatting/InlineFormatter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.wordpress.aztec.ITextFormat
1414
import org.wordpress.aztec.spans.AztecCodeSpan
1515
import org.wordpress.aztec.spans.AztecStrikethroughSpan
1616
import org.wordpress.aztec.spans.AztecStyleBoldSpan
17+
import org.wordpress.aztec.spans.AztecStyleCiteSpan
1718
import org.wordpress.aztec.spans.AztecStyleItalicSpan
1819
import org.wordpress.aztec.spans.AztecStyleSpan
1920
import org.wordpress.aztec.spans.AztecUnderlineSpan
@@ -51,6 +52,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
5152
when (item) {
5253
AztecTextFormat.FORMAT_BOLD,
5354
AztecTextFormat.FORMAT_ITALIC,
55+
AztecTextFormat.FORMAT_CITE,
5456
AztecTextFormat.FORMAT_STRIKETHROUGH,
5557
AztecTextFormat.FORMAT_UNDERLINE,
5658
AztecTextFormat.FORMAT_CODE -> {
@@ -183,6 +185,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
183185
when (span::class.java) {
184186
AztecStyleBoldSpan::class.java -> return AztecTextFormat.FORMAT_BOLD
185187
AztecStyleItalicSpan::class.java -> return AztecTextFormat.FORMAT_ITALIC
188+
AztecStyleCiteSpan::class.java -> return AztecTextFormat.FORMAT_CITE
186189
AztecStrikethroughSpan::class.java -> return AztecTextFormat.FORMAT_STRIKETHROUGH
187190
AztecUnderlineSpan::class.java -> return AztecTextFormat.FORMAT_UNDERLINE
188191
AztecCodeSpan::class.java -> return AztecTextFormat.FORMAT_CODE
@@ -328,6 +331,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
328331
when (textFormat) {
329332
AztecTextFormat.FORMAT_BOLD -> return AztecStyleBoldSpan()
330333
AztecTextFormat.FORMAT_ITALIC -> return AztecStyleItalicSpan()
334+
AztecTextFormat.FORMAT_CITE -> return AztecStyleCiteSpan()
331335
AztecTextFormat.FORMAT_STRIKETHROUGH -> return AztecStrikethroughSpan()
332336
AztecTextFormat.FORMAT_UNDERLINE -> return AztecUnderlineSpan()
333337
AztecTextFormat.FORMAT_CODE -> return AztecCodeSpan(codeStyle)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.wordpress.aztec.spans
2+
3+
import android.graphics.Typeface
4+
import org.wordpress.aztec.AztecAttributes
5+
6+
class AztecStyleCiteSpan(attributes: AztecAttributes = AztecAttributes())
7+
: AztecStyleSpan(Typeface.ITALIC, attributes) {
8+
9+
override val TAG by lazy {
10+
when (style) {
11+
Typeface.ITALIC -> {
12+
return@lazy "cite"
13+
}
14+
}
15+
throw IllegalArgumentException()
16+
}
17+
}

0 commit comments

Comments
 (0)