Skip to content

Commit 5a6aeec

Browse files
committed
Add redacted text formatting action
Adds a new inline formatting option that applies a red background and strikethrough to selected text, represented as <del class="redacted"> in HTML. Includes a toolbar button, full HTML round-trip support, and a parser test.
1 parent 6cc4b6c commit 5a6aeec

File tree

14 files changed

+144
-2
lines changed

14 files changed

+144
-2
lines changed

app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ open class MainActivity : AppCompatActivity(),
475475
ToolbarAction.LINK,
476476
ToolbarAction.UNDERLINE,
477477
ToolbarAction.STRIKETHROUGH,
478+
ToolbarAction.REDACTED,
478479
ToolbarAction.ALIGN_LEFT,
479480
ToolbarAction.ALIGN_CENTER,
480481
ToolbarAction.ALIGN_RIGHT,

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import org.wordpress.aztec.spans.AztecListItemSpan
3737
import org.wordpress.aztec.spans.AztecListItemSpan.Companion.CHECKED
3838
import org.wordpress.aztec.spans.AztecMediaClickableSpan
3939
import org.wordpress.aztec.spans.AztecMediaSpan
40+
import org.wordpress.aztec.spans.AztecRedactedSpan
4041
import org.wordpress.aztec.spans.AztecStrikethroughSpan
4142
import org.wordpress.aztec.spans.AztecTaskListSpan
4243
import org.wordpress.aztec.spans.AztecVideoSpan
@@ -87,7 +88,16 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
8788
return true
8889
}
8990
STRIKETHROUGH_S, STRIKETHROUGH_STRIKE, STRIKETHROUGH_DEL -> {
90-
handleElement(output, opening, AztecStrikethroughSpan(tag, AztecAttributes(attributes)))
91+
val span = if (opening && tag == STRIKETHROUGH_DEL &&
92+
AztecAttributes(attributes).getValue("class") == "redacted"
93+
) {
94+
AztecRedactedSpan(AztecAttributes(attributes))
95+
} else if (!opening && tagStack.isNotEmpty() && tagStack.last() is AztecRedactedSpan) {
96+
AztecRedactedSpan()
97+
} else {
98+
AztecStrikethroughSpan(tag, AztecAttributes(attributes))
99+
}
100+
handleElement(output, opening, span)
91101
return true
92102
}
93103
SPAN -> {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
14411441
AztecTextFormat.FORMAT_CITE,
14421442
AztecTextFormat.FORMAT_UNDERLINE,
14431443
AztecTextFormat.FORMAT_STRIKETHROUGH,
1444+
AztecTextFormat.FORMAT_REDACTED,
14441445
AztecTextFormat.FORMAT_BACKGROUND,
14451446
AztecTextFormat.FORMAT_HIGHLIGHT,
14461447
AztecTextFormat.FORMAT_CODE -> inlineFormatter.toggle(textFormat)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ enum class AztecTextFormat : ITextFormat {
3838
FORMAT_CODE,
3939
FORMAT_BACKGROUND,
4040
FORMAT_MARK,
41-
FORMAT_HIGHLIGHT
41+
FORMAT_HIGHLIGHT,
42+
FORMAT_REDACTED
4243
}

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.ITextFormat
1616
import org.wordpress.aztec.R
1717
import org.wordpress.aztec.spans.AztecBackgroundColorSpan
1818
import org.wordpress.aztec.spans.AztecCodeSpan
19+
import org.wordpress.aztec.spans.AztecRedactedSpan
1920
import org.wordpress.aztec.spans.AztecStrikethroughSpan
2021
import org.wordpress.aztec.spans.AztecStyleBoldSpan
2122
import org.wordpress.aztec.spans.AztecStyleCiteSpan
@@ -99,6 +100,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
99100
AztecTextFormat.FORMAT_EMPHASIS,
100101
AztecTextFormat.FORMAT_CITE,
101102
AztecTextFormat.FORMAT_STRIKETHROUGH,
103+
AztecTextFormat.FORMAT_REDACTED,
102104
AztecTextFormat.FORMAT_BACKGROUND,
103105
AztecTextFormat.FORMAT_UNDERLINE,
104106
AztecTextFormat.FORMAT_CODE -> {
@@ -325,6 +327,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
325327
AztecCodeSpan::class.java -> AztecTextFormat.FORMAT_CODE
326328
AztecBackgroundColorSpan::class.java -> return AztecTextFormat.FORMAT_BACKGROUND
327329
MarkSpan::class.java -> AztecTextFormat.FORMAT_MARK
330+
AztecRedactedSpan::class.java -> AztecTextFormat.FORMAT_REDACTED
328331
HighlightSpan::class.java -> AztecTextFormat.FORMAT_HIGHLIGHT
329332
else -> null
330333
}
@@ -478,6 +481,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
478481
AztecTextFormat.FORMAT_UNDERLINE -> AztecUnderlineSpan()
479482
AztecTextFormat.FORMAT_CODE -> AztecCodeSpan(codeStyle)
480483
AztecTextFormat.FORMAT_BACKGROUND -> AztecBackgroundColorSpan(backgroundSpanColor ?: R.color.background)
484+
AztecTextFormat.FORMAT_REDACTED -> AztecRedactedSpan()
481485
AztecTextFormat.FORMAT_HIGHLIGHT -> {
482486
HighlightSpan.create(context = editor.context, defaultStyle = highlightStyle)
483487
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.wordpress.aztec.spans
2+
3+
import android.graphics.Color
4+
import android.graphics.Paint
5+
import android.text.TextPaint
6+
import android.text.style.CharacterStyle
7+
import org.wordpress.aztec.AztecAttributes
8+
9+
class AztecRedactedSpan(
10+
override var attributes: AztecAttributes = AztecAttributes()
11+
) : CharacterStyle(), IAztecInlineSpan {
12+
13+
override val TAG = "del"
14+
15+
init {
16+
if (attributes.getValue("class").isNullOrEmpty()) {
17+
attributes.setValue("class", "redacted")
18+
}
19+
}
20+
21+
override fun updateDrawState(tp: TextPaint) {
22+
tp.bgColor = Color.RED
23+
tp.flags = tp.flags or Paint.STRIKE_THRU_TEXT_FLAG
24+
}
25+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ enum class ToolbarAction constructor(
9797
ToolbarActionType.INLINE_STYLE,
9898
setOf(AztecTextFormat.FORMAT_STRIKETHROUGH),
9999
R.layout.format_bar_button_strikethrough),
100+
REDACTED(
101+
R.id.format_bar_button_redacted,
102+
R.drawable.format_bar_button_redacted_selector,
103+
ToolbarActionType.INLINE_STYLE,
104+
setOf(AztecTextFormat.FORMAT_REDACTED),
105+
R.layout.format_bar_button_redacted),
100106
ALIGN_LEFT(R.id.format_bar_button_align_left,
101107
R.drawable.format_bar_button_align_left_selector,
102108
ToolbarActionType.BLOCK_STYLE,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:height="48dp"
6+
android:width="48dp"
7+
android:viewportHeight="48"
8+
android:viewportWidth="48" >
9+
10+
<!-- Filled rectangle representing redacted block -->
11+
<path
12+
android:fillColor="?attr/toolbarIconNormalColor"
13+
android:pathData="M12,18h24v12H12z" />
14+
15+
<!-- Diagonal strikethrough line -->
16+
<path
17+
android:fillColor="?attr/toolbarIconNormalColor"
18+
android:pathData="M10,30.5L35.5,17l1,1.7L11,32.2z" />
19+
20+
</vector>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:height="48dp"
6+
android:width="48dp"
7+
android:viewportHeight="48"
8+
android:viewportWidth="48" >
9+
10+
<!-- Filled rectangle representing redacted block -->
11+
<path
12+
android:fillColor="?attr/toolbarIconDisabledColor"
13+
android:pathData="M12,18h24v12H12z" />
14+
15+
<!-- Diagonal strikethrough line -->
16+
<path
17+
android:fillColor="?attr/toolbarIconDisabledColor"
18+
android:pathData="M10,30.5L35.5,17l1,1.7L11,32.2z" />
19+
20+
</vector>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:height="48dp"
6+
android:width="48dp"
7+
android:viewportHeight="48"
8+
android:viewportWidth="48" >
9+
10+
<!-- Filled rectangle representing redacted block -->
11+
<path
12+
android:fillColor="?attr/toolbarIconHighlightColor"
13+
android:pathData="M12,18h24v12H12z" />
14+
15+
<!-- Diagonal strikethrough line -->
16+
<path
17+
android:fillColor="?attr/toolbarIconHighlightColor"
18+
android:pathData="M10,30.5L35.5,17l1,1.7L11,32.2z" />
19+
20+
</vector>

0 commit comments

Comments
 (0)