-
Notifications
You must be signed in to change notification settings - Fork 121
Improve Mark formatting #1073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Improve Mark formatting #1073
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
13c580a
Improve Mark formating by implementing custom Mark plugin and support…
4f79f24
Fix lint issues
c48c233
Fix getTextColor in MarkSpan
9639a10
Update updating existing MarkSpan logic
9b97880
Fix lint issue
bdfb20f
MarkSpan - Set color from HTML attributes if they exist
ffdddf3
InlineFormatter - Prevent picking previous Mark styles if the format …
bdc719c
Improve setting and resetting Mark formatting styles
d83e764
Remove unnecessary semicolon
99b5c9f
Remove markStyleColor check
299b8ea
Merge branch 'trunk' into fix/mark-style-issues
17946f2
InlineFormatter - Move markStyleColor declaration
2f73564
MarkSpan - Rename textColor variable to textColorValue, it also appli…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
aztec/src/main/kotlin/org/wordpress/aztec/plugins/MarkPlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package org.wordpress.aztec.plugins | ||
|
|
||
| import android.text.SpannableStringBuilder | ||
| import org.wordpress.aztec.plugins.visual2html.ISpanPreprocessor | ||
| import org.wordpress.aztec.source.CssStyleFormatter | ||
| import org.wordpress.aztec.spans.MarkSpan | ||
|
|
||
| class MarkPlugin : ISpanPreprocessor { | ||
|
|
||
| override fun beforeSpansProcessed(spannable: SpannableStringBuilder) { | ||
| spannable.getSpans(0, spannable.length, MarkSpan::class.java).forEach { | ||
| if (!CssStyleFormatter.containsStyleAttribute(it.attributes, CssStyleFormatter.CSS_BACKGROUND_COLOR_ATTRIBUTE)) { | ||
| CssStyleFormatter.addStyleAttribute(it.attributes, CssStyleFormatter.CSS_BACKGROUND_COLOR_ATTRIBUTE, "rgba(0, 0, 0, 0)") | ||
| } | ||
|
|
||
| if (!CssStyleFormatter.containsStyleAttribute(it.attributes, CssStyleFormatter.CSS_COLOR_ATTRIBUTE)) { | ||
| CssStyleFormatter.addStyleAttribute(it.attributes, CssStyleFormatter.CSS_COLOR_ATTRIBUTE, it.getTextColor()) | ||
| } | ||
|
|
||
| if (!it.attributes.hasAttribute("class")) { | ||
| it.attributes.setValue("class", "has-inline-color") | ||
| } | ||
| } | ||
| } | ||
| } |
37 changes: 35 additions & 2 deletions
37
aztec/src/main/kotlin/org/wordpress/aztec/spans/MarkSpan.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,45 @@ | ||
| package org.wordpress.aztec.spans | ||
|
|
||
| import android.graphics.Color | ||
| import android.text.TextPaint | ||
| import android.text.style.CharacterStyle | ||
| import org.wordpress.aztec.AztecAttributes | ||
| import org.wordpress.aztec.source.CssStyleFormatter | ||
|
|
||
| class MarkSpan(override var attributes: AztecAttributes = AztecAttributes()) : CharacterStyle(), IAztecInlineSpan { | ||
| class MarkSpan : CharacterStyle, IAztecInlineSpan { | ||
| override var TAG = "mark" | ||
|
|
||
| override fun updateDrawState(tp: TextPaint?) { | ||
| override var attributes: AztecAttributes = AztecAttributes() | ||
| private val textColorValue: Int? | ||
|
|
||
| constructor(attributes: AztecAttributes = AztecAttributes()) : super() { | ||
| this.attributes = attributes | ||
|
|
||
| val color = CssStyleFormatter.getStyleAttribute(attributes, | ||
| CssStyleFormatter.CSS_COLOR_ATTRIBUTE) | ||
| textColorValue = if (color.isNotEmpty()) { | ||
| Color.parseColor(color) | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| constructor(attributes: AztecAttributes = AztecAttributes(), colorString: String?) : super() { | ||
| this.attributes = attributes | ||
|
|
||
| textColorValue = if (colorString != null) { | ||
| Color.parseColor(colorString) | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| override fun updateDrawState(tp: TextPaint) { | ||
| textColorValue?.let { tp.color = it } | ||
| } | ||
|
|
||
| fun getTextColor(): String { | ||
| val currentColor = textColorValue ?: 0 | ||
| return String.format("#%06X", 0xFFFFFF and currentColor) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.