Skip to content

Commit 2878796

Browse files
author
Gerardo Pacheco
authored
Merge pull request #943 from wordpress-mobile/feature/mark-formatting
Add Mark inline formatting
2 parents b664b51 + 3823851 commit 2878796

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.wordpress.aztec.spans.IAztecParagraphStyle;
6060
import org.wordpress.aztec.spans.UnknownClickableSpan;
6161
import org.wordpress.aztec.spans.UnknownHtmlSpan;
62+
import org.wordpress.aztec.spans.MarkSpan;
6263
import org.wordpress.aztec.util.CleaningUtils;
6364
import org.xml.sax.Attributes;
6465
import org.xml.sax.InputSource;
@@ -355,6 +356,8 @@ private void handleStartTag(String tag, Attributes attributes, int nestingLevel)
355356
} else if (tag.equalsIgnoreCase("code")) {
356357
insideCodeTag = true;
357358
start(spannableStringBuilder, AztecTextFormat.FORMAT_CODE, attributes);
359+
} else if (tag.equalsIgnoreCase("mark")) {
360+
start(spannableStringBuilder, AztecTextFormat.FORMAT_MARK, attributes);
358361
} else if (!UnknownHtmlSpan.Companion.getKNOWN_TAGS().contains(tag.toLowerCase())) {
359362
// Initialize a new "Unknown" node
360363
if (contentHandlerLevel == 0) {
@@ -448,6 +451,8 @@ private void handleEndTag(String tag, int nestingLevel) {
448451
} else if (tag.equalsIgnoreCase("code")) {
449452
insideCodeTag = false;
450453
end(spannableStringBuilder, AztecTextFormat.FORMAT_CODE);
454+
} else if (tag.equalsIgnoreCase("mark")) {
455+
end(spannableStringBuilder, AztecTextFormat.FORMAT_MARK);
451456
}
452457
}
453458

@@ -543,6 +548,9 @@ private static void start(SpannableStringBuilder text, AztecTextFormat textForma
543548
case FORMAT_CODE:
544549
newSpan = new AztecCodeSpan(attributes);
545550
break;
551+
case FORMAT_MARK:
552+
newSpan = new MarkSpan(attributes);
553+
break;
546554
default:
547555
throw new IllegalArgumentException("Style not supported");
548556
}
@@ -597,6 +605,9 @@ private static void end(SpannableStringBuilder text, AztecTextFormat textFormat)
597605
case FORMAT_CODE:
598606
span = (AztecCodeSpan) getLast(text, AztecCodeSpan.class);
599607
break;
608+
case FORMAT_MARK:
609+
span = (MarkSpan) getLast(text, MarkSpan.class);
610+
break;
600611
default:
601612
throw new IllegalArgumentException("Style not supported");
602613
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
144144
handleElement(output, opening, preformatSpan)
145145
return true
146146
}
147-
MARK -> {
148-
val span = createHiddenHtmlSpan(tag, AztecAttributes(attributes), nestingLevel, alignmentRendering)
149-
handleElement(output, opening, span)
150-
return true
151-
}
152147
else -> {
153148
if (tag.length == 2 && Character.toLowerCase(tag[0]) == 'h' && tag[1] >= '1' && tag[1] <= '6') {
154149
handleElement(output, opening, createHeadingSpan(nestingLevel, tag, AztecAttributes(attributes), alignmentRendering))

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11781178
AztecTextFormat.FORMAT_CITE,
11791179
AztecTextFormat.FORMAT_UNDERLINE,
11801180
AztecTextFormat.FORMAT_STRIKETHROUGH,
1181+
AztecTextFormat.FORMAT_MARK,
11811182
AztecTextFormat.FORMAT_CODE -> return inlineFormatter.containsInlineStyle(format, selStart, selEnd)
11821183
AztecTextFormat.FORMAT_UNORDERED_LIST,
11831184
AztecTextFormat.FORMAT_ORDERED_LIST -> return blockFormatter.containsList(format, selStart, selEnd)
@@ -1619,6 +1620,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
16191620
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_STRIKETHROUGH, start, end)
16201621
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_UNDERLINE, start, end)
16211622
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_CODE, start, end)
1623+
inlineFormatter.removeInlineStyle(AztecTextFormat.FORMAT_MARK, start, end)
16221624
}
16231625

16241626
fun removeBlockStylesFromRange(start: Int, end: Int, ignoreLineBounds: Boolean = false) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ enum class AztecTextFormat : ITextFormat {
3535
FORMAT_FONT,
3636
FORMAT_MONOSPACE,
3737
FORMAT_CODE,
38+
FORMAT_MARK,
3839
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.wordpress.aztec.spans.AztecStyleStrongSpan
2121
import org.wordpress.aztec.spans.AztecStyleSpan
2222
import org.wordpress.aztec.spans.AztecUnderlineSpan
2323
import org.wordpress.aztec.spans.IAztecInlineSpan
24+
import org.wordpress.aztec.spans.MarkSpan
2425
import org.wordpress.aztec.watchers.TextChangedEvent
2526
import java.util.ArrayList
2627

@@ -73,6 +74,14 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
7374
AztecTextFormat.FORMAT_CODE -> {
7475
applyInlineStyle(item, textChangedEvent.inputStart, textChangedEvent.inputEnd)
7576
}
77+
AztecTextFormat.FORMAT_MARK -> {
78+
// For cases of an empty mark tag, either at the beginning of the text or in between
79+
if (textChangedEvent.inputStart == 0 && textChangedEvent.inputEnd == 1) {
80+
applyMarkInlineStyle(textChangedEvent.inputStart, textChangedEvent.inputEnd)
81+
} else {
82+
applyInlineStyle(item, textChangedEvent.inputStart, textChangedEvent.inputEnd)
83+
}
84+
}
7685
else -> {
7786
// do nothing
7887
}
@@ -176,6 +185,13 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
176185
joinStyleSpans(start, end)
177186
}
178187

188+
private fun applyMarkInlineStyle(start: Int = selectionStart, end: Int = selectionEnd, attrs: AztecAttributes = AztecAttributes()) {
189+
val previousSpans = editableText.getSpans(start, end, MarkSpan::class.java)
190+
previousSpans.forEach {
191+
it.applyInlineStyleAttributes(editableText, start, end)
192+
}
193+
}
194+
179195
private fun applySpan(span: IAztecInlineSpan, start: Int, end: Int, type: Int) {
180196
if (start > end || start < 0 || end > editableText.length) {
181197
// If an external logger is available log the error there.
@@ -205,6 +221,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
205221
AztecStrikethroughSpan::class.java -> return AztecTextFormat.FORMAT_STRIKETHROUGH
206222
AztecUnderlineSpan::class.java -> return AztecTextFormat.FORMAT_UNDERLINE
207223
AztecCodeSpan::class.java -> return AztecTextFormat.FORMAT_CODE
224+
MarkSpan::class.java -> return AztecTextFormat.FORMAT_MARK
208225
else -> return null
209226
}
210227
}
@@ -349,6 +366,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
349366
AztecTextFormat.FORMAT_STRIKETHROUGH -> return AztecStrikethroughSpan()
350367
AztecTextFormat.FORMAT_UNDERLINE -> return AztecUnderlineSpan()
351368
AztecTextFormat.FORMAT_CODE -> return AztecCodeSpan(codeStyle)
369+
AztecTextFormat.FORMAT_MARK -> return MarkSpan()
352370
else -> return AztecStyleSpan(Typeface.NORMAL)
353371
}
354372
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.wordpress.aztec.spans
2+
3+
import android.text.TextPaint
4+
import android.text.style.CharacterStyle
5+
import org.wordpress.aztec.AztecAttributes
6+
7+
class MarkSpan(override var attributes: AztecAttributes = AztecAttributes()) : CharacterStyle(), IAztecInlineSpan {
8+
override var TAG = "mark"
9+
10+
override fun updateDrawState(tp: TextPaint?) {
11+
}
12+
}

0 commit comments

Comments
 (0)