|
1 | 1 | package com.swmansion.enriched.spans |
2 | 2 |
|
| 3 | +import com.swmansion.enriched.styles.HtmlStyle |
| 4 | + |
3 | 5 | data class BaseSpanConfig(val clazz: Class<*>) |
4 | 6 | data class ParagraphSpanConfig(val clazz: Class<*>, val isContinuous: Boolean) |
5 | 7 | data class ListSpanConfig(val clazz: Class<*>, val shortcut: String) |
@@ -62,50 +64,63 @@ object EnrichedSpans { |
62 | 64 | MENTION to BaseSpanConfig(EnrichedMentionSpan::class.java), |
63 | 65 | ) |
64 | 66 |
|
65 | | - val mergingConfig: Map<String, StylesMergingConfig> = mapOf( |
66 | | - BOLD to StylesMergingConfig( |
67 | | - blockingStyles = arrayOf(CODE_BLOCK) |
68 | | - ), |
69 | | - ITALIC to StylesMergingConfig( |
70 | | - blockingStyles = arrayOf(CODE_BLOCK) |
71 | | - ), |
72 | | - UNDERLINE to StylesMergingConfig( |
73 | | - blockingStyles = arrayOf(CODE_BLOCK) |
74 | | - ), |
75 | | - STRIKETHROUGH to StylesMergingConfig( |
76 | | - blockingStyles = arrayOf(CODE_BLOCK) |
77 | | - ), |
78 | | - INLINE_CODE to StylesMergingConfig( |
79 | | - conflictingStyles = arrayOf(MENTION, LINK), |
80 | | - blockingStyles = arrayOf(CODE_BLOCK) |
81 | | - ), |
82 | | - H1 to StylesMergingConfig( |
83 | | - conflictingStyles = arrayOf(H2, H3, ORDERED_LIST, UNORDERED_LIST, BLOCK_QUOTE, CODE_BLOCK), |
84 | | - ), |
85 | | - H2 to StylesMergingConfig( |
86 | | - conflictingStyles = arrayOf(H1, H3, ORDERED_LIST, UNORDERED_LIST, BLOCK_QUOTE, CODE_BLOCK), |
87 | | - ), |
88 | | - H3 to StylesMergingConfig( |
89 | | - conflictingStyles = arrayOf(H1, H2, ORDERED_LIST, UNORDERED_LIST, BLOCK_QUOTE, CODE_BLOCK), |
90 | | - ), |
91 | | - BLOCK_QUOTE to StylesMergingConfig( |
92 | | - conflictingStyles = arrayOf(H1, H2, H3, CODE_BLOCK, ORDERED_LIST, UNORDERED_LIST), |
93 | | - ), |
94 | | - CODE_BLOCK to StylesMergingConfig( |
95 | | - conflictingStyles = arrayOf(H1, H2, H3, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, UNORDERED_LIST, ORDERED_LIST, BLOCK_QUOTE, INLINE_CODE), |
96 | | - ), |
97 | | - UNORDERED_LIST to StylesMergingConfig( |
98 | | - conflictingStyles = arrayOf(H1, H2, H3, ORDERED_LIST, CODE_BLOCK, BLOCK_QUOTE), |
99 | | - ), |
100 | | - ORDERED_LIST to StylesMergingConfig( |
101 | | - conflictingStyles = arrayOf(H1, H2, H3, UNORDERED_LIST, CODE_BLOCK, BLOCK_QUOTE), |
102 | | - ), |
103 | | - LINK to StylesMergingConfig( |
104 | | - blockingStyles = arrayOf(INLINE_CODE, CODE_BLOCK, MENTION) |
105 | | - ), |
106 | | - IMAGE to StylesMergingConfig(), |
107 | | - MENTION to StylesMergingConfig( |
108 | | - blockingStyles = arrayOf(INLINE_CODE, CODE_BLOCK, LINK) |
109 | | - ), |
110 | | - ) |
| 67 | + fun getMergingConfigForStyle(style: String, htmlStyle: HtmlStyle): StylesMergingConfig? { |
| 68 | + return when (style) { |
| 69 | + BOLD -> { |
| 70 | + val blockingStyles = mutableListOf(CODE_BLOCK) |
| 71 | + if (htmlStyle.h1Bold) blockingStyles.add(H1) |
| 72 | + if (htmlStyle.h2Bold) blockingStyles.add(H2) |
| 73 | + if (htmlStyle.h3Bold) blockingStyles.add(H3) |
| 74 | + StylesMergingConfig(blockingStyles = blockingStyles.toTypedArray()) |
| 75 | + } |
| 76 | + ITALIC -> StylesMergingConfig( |
| 77 | + blockingStyles = arrayOf(CODE_BLOCK) |
| 78 | + ) |
| 79 | + UNDERLINE -> StylesMergingConfig( |
| 80 | + blockingStyles = arrayOf(CODE_BLOCK) |
| 81 | + ) |
| 82 | + STRIKETHROUGH -> StylesMergingConfig( |
| 83 | + blockingStyles = arrayOf(CODE_BLOCK) |
| 84 | + ) |
| 85 | + INLINE_CODE -> StylesMergingConfig( |
| 86 | + conflictingStyles = arrayOf(MENTION, LINK), |
| 87 | + blockingStyles = arrayOf(CODE_BLOCK) |
| 88 | + ) |
| 89 | + H1 -> { |
| 90 | + val conflictingStyles = mutableListOf(H2, H3, ORDERED_LIST, UNORDERED_LIST, BLOCK_QUOTE, CODE_BLOCK) |
| 91 | + if (htmlStyle.h1Bold) conflictingStyles.add(BOLD) |
| 92 | + StylesMergingConfig(conflictingStyles = conflictingStyles.toTypedArray()) |
| 93 | + } |
| 94 | + H2 -> { |
| 95 | + val conflictingStyles = mutableListOf(H1, H3, ORDERED_LIST, UNORDERED_LIST, BLOCK_QUOTE, CODE_BLOCK) |
| 96 | + if (htmlStyle.h2Bold) conflictingStyles.add(BOLD) |
| 97 | + StylesMergingConfig(conflictingStyles = conflictingStyles.toTypedArray()) |
| 98 | + } |
| 99 | + H3 -> { |
| 100 | + val conflictingStyles = mutableListOf(H1, H2, ORDERED_LIST, UNORDERED_LIST, BLOCK_QUOTE, CODE_BLOCK) |
| 101 | + if (htmlStyle.h3Bold) conflictingStyles.add(BOLD) |
| 102 | + StylesMergingConfig(conflictingStyles = conflictingStyles.toTypedArray()) |
| 103 | + } |
| 104 | + BLOCK_QUOTE -> StylesMergingConfig( |
| 105 | + conflictingStyles = arrayOf(H1, H2, H3, CODE_BLOCK, ORDERED_LIST, UNORDERED_LIST) |
| 106 | + ) |
| 107 | + CODE_BLOCK -> StylesMergingConfig( |
| 108 | + conflictingStyles = arrayOf(H1, H2, H3, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, UNORDERED_LIST, ORDERED_LIST, BLOCK_QUOTE, INLINE_CODE) |
| 109 | + ) |
| 110 | + UNORDERED_LIST -> StylesMergingConfig( |
| 111 | + conflictingStyles = arrayOf(H1, H2, H3, ORDERED_LIST, CODE_BLOCK, BLOCK_QUOTE) |
| 112 | + ) |
| 113 | + ORDERED_LIST -> StylesMergingConfig( |
| 114 | + conflictingStyles = arrayOf(H1, H2, H3, UNORDERED_LIST, CODE_BLOCK, BLOCK_QUOTE), |
| 115 | + ) |
| 116 | + LINK -> StylesMergingConfig( |
| 117 | + blockingStyles = arrayOf(INLINE_CODE, CODE_BLOCK, MENTION) |
| 118 | + ) |
| 119 | + IMAGE -> StylesMergingConfig() |
| 120 | + MENTION -> StylesMergingConfig( |
| 121 | + blockingStyles = arrayOf(INLINE_CODE, CODE_BLOCK, LINK) |
| 122 | + ) |
| 123 | + else -> null |
| 124 | + } |
| 125 | + } |
111 | 126 | } |
0 commit comments