Skip to content

Commit

Permalink
Use AlignmentApproach with HiddenHtmlSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
mchowning committed Apr 23, 2020
1 parent 279cfeb commit 2a4406d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 3 additions & 1 deletion aztec/src/main/kotlin/org/wordpress/aztec/AztecTagHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.wordpress.aztec.spans.IAztecNestable
import org.wordpress.aztec.spans.createAztecQuoteSpan
import org.wordpress.aztec.spans.createHeadingSpan
import org.wordpress.aztec.spans.createHiddenHtmlBlockSpan
import org.wordpress.aztec.spans.createHiddenHtmlSpan
import org.wordpress.aztec.spans.createListItemSpan
import org.wordpress.aztec.spans.createOrderedListSpan
import org.wordpress.aztec.spans.createParagraphSpan
Expand Down Expand Up @@ -82,7 +83,8 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
return true
}
SPAN -> {
handleElement(output, opening, HiddenHtmlSpan(tag, AztecAttributes(attributes), nestingLevel))
val span = createHiddenHtmlSpan(tag, AztecAttributes(attributes), nestingLevel, alignmentApproach)
handleElement(output, opening, span)
return true
}
DIV, FIGURE, FIGCAPTION, SECTION -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.wordpress.aztec.plugins
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import org.wordpress.aztec.AlignmentApproach
import org.wordpress.aztec.AztecText
import org.wordpress.aztec.plugins.html2visual.ISpanPostprocessor
import org.wordpress.aztec.plugins.visual2html.ISpanPreprocessor
import org.wordpress.aztec.source.CssStyleFormatter
Expand All @@ -11,7 +13,9 @@ import org.wordpress.aztec.spans.HiddenHtmlSpan
import org.wordpress.aztec.spans.IAztecNestable
import org.wordpress.aztec.util.SpanWrapper

class CssUnderlinePlugin : ISpanPostprocessor, ISpanPreprocessor {
class CssUnderlinePlugin(
val alignmentApproach: AlignmentApproach = AztecText.DEFAULT_ALIGNMENT_APPROACH
): ISpanPostprocessor, ISpanPreprocessor {

private val SPAN_TAG = "span"
private val UNDERLINE_STYLE_VALUE = "underline"
Expand Down
21 changes: 18 additions & 3 deletions aztec/src/main/kotlin/org/wordpress/aztec/spans/HiddenHtmlSpan.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package org.wordpress.aztec.spans

import android.text.Layout
import org.wordpress.aztec.AlignmentApproach
import org.wordpress.aztec.AztecAttributes

class HiddenHtmlSpan(tag: String,
override var attributes: AztecAttributes = AztecAttributes(),
override var nestingLevel: Int) : IAztecAlignmentSpan, IAztecParagraphStyle {
fun createHiddenHtmlSpan(tag: String,
attributes: AztecAttributes = AztecAttributes(),
nestingLevel: Int,
alignmentApproach: AlignmentApproach
) = when (alignmentApproach) {
AlignmentApproach.SPAN_LEVEL -> HiddenHtmlSpanAligned(tag, attributes, nestingLevel)
AlignmentApproach.VIEW_LEVEL -> HiddenHtmlSpan(tag, attributes, nestingLevel)
}

class HiddenHtmlSpanAligned(tag: String,
attributes: AztecAttributes,
nestingLevel: Int
) : HiddenHtmlSpan(tag, attributes, nestingLevel), IAztecAlignmentSpan {
override var align: Layout.Alignment? = null
}

open class HiddenHtmlSpan(tag: String,
override var attributes: AztecAttributes,
override var nestingLevel: Int) : IAztecParagraphStyle {
override val TAG: String = tag
}

0 comments on commit 2a4406d

Please sign in to comment.