Skip to content

Commit e02ec13

Browse files
authored
Merge pull request #777 from wordpress-mobile/update/italic-tag-em
Make `em` the default tag for italic
2 parents 7d7a7e2 + bf2668c commit e02ec13

File tree

12 files changed

+69
-32
lines changed

12 files changed

+69
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## [v1.3.20](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.3.20)
3+
### Changed
4+
- Support for `<em>` for italic and using it as default via the formatting toolbar #777
5+
26
## [v1.3.19](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.3.19)
37
### Fixed
48
- Option to avoid autofocus when getting visible #783

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class FormattingHistoryTests : BaseHistoryTest() {
187187
@Test
188188
fun testAddItalicAndUnderlineUndoRedo() {
189189
val text = "There's no crying in baseball!"
190-
val htmlRegex = Regex("<i><u>$text</u></i>|<u><i>$text</i></u>")
190+
val htmlRegex = Regex("<em><u>$text</u></em>|<u><em>$text</em></u>")
191191
val editorPage = EditorPage()
192192

193193
// Insert text snippet

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MixedTextFormattingTests : BaseTest() {
2222
val text1 = "so"
2323
val text2 = "me "
2424
val text3 = "text "
25-
val regex = Regex("<strong>$text1</strong><i>$text2</i><(strong|i)><(strong|i)>$text3</(strong|i)></(strong|i)>")
25+
val regex = Regex("<strong>$text1</strong><em>$text2</em><(strong|em)><(strong|em)>$text3</(strong|em)></(strong|em)>")
2626

2727
EditorPage()
2828
.toggleBold()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SimpleTextFormattingTests : BaseTest() {
3232
fun testSimpleItalicFormatting() {
3333
val text1 = "some"
3434
val text2 = "text"
35-
val html = "$text1<i>$text2</i>"
35+
val html = "$text1<em>$text2</em>"
3636

3737
EditorPage()
3838
.insertText(text1)
@@ -335,7 +335,7 @@ class SimpleTextFormattingTests : BaseTest() {
335335
@Test
336336
fun testInlineStyleAndDelete() {
337337
val text1 = "some"
338-
val html = "<i>som</i>"
338+
val html = "<em>som</em>"
339339

340340
EditorPage()
341341
.toggleItalics()

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.wordpress.aztec.spans.AztecStyleBoldSpan;
4747
import org.wordpress.aztec.spans.AztecStyleCiteSpan;
4848
import org.wordpress.aztec.spans.AztecStyleItalicSpan;
49+
import org.wordpress.aztec.spans.AztecStyleEmphasisSpan;
4950
import org.wordpress.aztec.spans.AztecStyleStrongSpan;
5051
import org.wordpress.aztec.spans.AztecSubscriptSpan;
5152
import org.wordpress.aztec.spans.AztecSuperscriptSpan;
@@ -318,7 +319,7 @@ private void handleStartTag(String tag, Attributes attributes, int nestingLevel)
318319
} else if (tag.equalsIgnoreCase("b")) {
319320
start(spannableStringBuilder, AztecTextFormat.FORMAT_BOLD, attributes);
320321
} else if (tag.equalsIgnoreCase("em")) {
321-
start(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC, attributes);
322+
start(spannableStringBuilder, AztecTextFormat.FORMAT_EMPHASIS, attributes);
322323
} else if (tag.equalsIgnoreCase("cite")) {
323324
start(spannableStringBuilder, AztecTextFormat.FORMAT_CITE, attributes);
324325
} else if (tag.equalsIgnoreCase("dfn")) {
@@ -411,7 +412,7 @@ private void handleEndTag(String tag, int nestingLevel) {
411412
} else if (tag.equalsIgnoreCase("b")) {
412413
end(spannableStringBuilder, AztecTextFormat.FORMAT_BOLD);
413414
} else if (tag.equalsIgnoreCase("em")) {
414-
end(spannableStringBuilder, AztecTextFormat.FORMAT_ITALIC);
415+
end(spannableStringBuilder, AztecTextFormat.FORMAT_EMPHASIS);
415416
} else if (tag.equalsIgnoreCase("cite")) {
416417
end(spannableStringBuilder, AztecTextFormat.FORMAT_CITE);
417418
} else if (tag.equalsIgnoreCase("dfn")) {
@@ -498,6 +499,9 @@ private static void start(SpannableStringBuilder text, AztecTextFormat textForma
498499
case FORMAT_ITALIC:
499500
newSpan = new AztecStyleItalicSpan(attributes);
500501
break;
502+
case FORMAT_EMPHASIS:
503+
newSpan = new AztecStyleEmphasisSpan(attributes);
504+
break;
501505
case FORMAT_CITE:
502506
newSpan = new AztecStyleCiteSpan(attributes);
503507
break;
@@ -550,6 +554,9 @@ private static void end(SpannableStringBuilder text, AztecTextFormat textFormat)
550554
case FORMAT_ITALIC:
551555
span = (AztecStyleItalicSpan) getLast(text, AztecStyleItalicSpan.class);
552556
break;
557+
case FORMAT_EMPHASIS:
558+
span = (AztecStyleEmphasisSpan) getLast(text, AztecStyleEmphasisSpan.class);
559+
break;
553560
case FORMAT_CITE:
554561
span = (AztecStyleCiteSpan) getLast(text, AztecStyleCiteSpan.class);
555562
break;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
925925
AztecTextFormat.FORMAT_HEADING_6,
926926
AztecTextFormat.FORMAT_PREFORMAT -> blockFormatter.toggleHeading(textFormat)
927927
AztecTextFormat.FORMAT_ITALIC,
928+
AztecTextFormat.FORMAT_EMPHASIS,
928929
AztecTextFormat.FORMAT_CITE,
929930
AztecTextFormat.FORMAT_UNDERLINE,
930931
AztecTextFormat.FORMAT_STRIKETHROUGH,
@@ -957,6 +958,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
957958
AztecTextFormat.FORMAT_BOLD,
958959
AztecTextFormat.FORMAT_STRONG,
959960
AztecTextFormat.FORMAT_ITALIC,
961+
AztecTextFormat.FORMAT_EMPHASIS,
960962
AztecTextFormat.FORMAT_CITE,
961963
AztecTextFormat.FORMAT_UNDERLINE,
962964
AztecTextFormat.FORMAT_STRIKETHROUGH,
@@ -1361,6 +1363,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
13611363
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_BOLD, start, end)
13621364
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_STRONG, start, end)
13631365
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_ITALIC, start, end)
1366+
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_EMPHASIS, start, end)
13641367
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_CITE, start, end)
13651368
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_STRIKETHROUGH, start, end)
13661369
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_UNDERLINE, 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
@@ -16,6 +16,7 @@ enum class AztecTextFormat : ITextFormat {
1616
FORMAT_BOLD,
1717
FORMAT_STRONG,
1818
FORMAT_ITALIC,
19+
FORMAT_EMPHASIS,
1920
FORMAT_CITE,
2021
FORMAT_UNDERLINE,
2122
FORMAT_STRIKETHROUGH,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.wordpress.aztec.spans.AztecStrikethroughSpan
1616
import org.wordpress.aztec.spans.AztecStyleBoldSpan
1717
import org.wordpress.aztec.spans.AztecStyleCiteSpan
1818
import org.wordpress.aztec.spans.AztecStyleItalicSpan
19+
import org.wordpress.aztec.spans.AztecStyleEmphasisSpan
1920
import org.wordpress.aztec.spans.AztecStyleStrongSpan
2021
import org.wordpress.aztec.spans.AztecStyleSpan
2122
import org.wordpress.aztec.spans.AztecUnderlineSpan
@@ -65,6 +66,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
6566
AztecTextFormat.FORMAT_BOLD,
6667
AztecTextFormat.FORMAT_STRONG,
6768
AztecTextFormat.FORMAT_ITALIC,
69+
AztecTextFormat.FORMAT_EMPHASIS,
6870
AztecTextFormat.FORMAT_CITE,
6971
AztecTextFormat.FORMAT_STRIKETHROUGH,
7072
AztecTextFormat.FORMAT_UNDERLINE,
@@ -198,6 +200,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
198200
AztecStyleBoldSpan::class.java -> return AztecTextFormat.FORMAT_BOLD
199201
AztecStyleStrongSpan::class.java -> return AztecTextFormat.FORMAT_STRONG
200202
AztecStyleItalicSpan::class.java -> return AztecTextFormat.FORMAT_ITALIC
203+
AztecStyleEmphasisSpan::class.java -> return AztecTextFormat.FORMAT_EMPHASIS
201204
AztecStyleCiteSpan::class.java -> return AztecTextFormat.FORMAT_CITE
202205
AztecStrikethroughSpan::class.java -> return AztecTextFormat.FORMAT_STRIKETHROUGH
203206
AztecUnderlineSpan::class.java -> return AztecTextFormat.FORMAT_UNDERLINE
@@ -341,6 +344,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
341344
AztecTextFormat.FORMAT_BOLD -> return AztecStyleBoldSpan()
342345
AztecTextFormat.FORMAT_STRONG -> return AztecStyleStrongSpan()
343346
AztecTextFormat.FORMAT_ITALIC -> return AztecStyleItalicSpan()
347+
AztecTextFormat.FORMAT_EMPHASIS -> return AztecStyleEmphasisSpan()
344348
AztecTextFormat.FORMAT_CITE -> return AztecStyleCiteSpan()
345349
AztecTextFormat.FORMAT_STRIKETHROUGH -> return AztecStrikethroughSpan()
346350
AztecTextFormat.FORMAT_UNDERLINE -> return AztecUnderlineSpan()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.wordpress.aztec.spans
2+
3+
import android.graphics.Typeface
4+
import org.wordpress.aztec.AztecAttributes
5+
6+
class AztecStyleEmphasisSpan(attributes: AztecAttributes = AztecAttributes())
7+
: AztecStyleSpan(Typeface.ITALIC, attributes) {
8+
9+
override val TAG by lazy {
10+
when (style) {
11+
Typeface.ITALIC -> {
12+
return@lazy "em"
13+
}
14+
}
15+
throw IllegalArgumentException()
16+
}
17+
}
18+

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
182182
}
183183
KeyEvent.KEYCODE_I -> {
184184
if (event.isCtrlPressed) { // Italic = Ctrl + I
185-
aztecToolbarListener?.onToolbarFormatButtonClicked(AztecTextFormat.FORMAT_ITALIC, true)
185+
aztecToolbarListener?.onToolbarFormatButtonClicked(AztecTextFormat.FORMAT_EMPHASIS, true)
186186
findViewById<ToggleButton>(ToolbarAction.ITALIC.buttonId).performClick()
187187
return true
188188
}

0 commit comments

Comments
 (0)