Skip to content

Commit 72041ac

Browse files
committed
(fix) nested text formatting
1 parent 6d8a013 commit 72041ac

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/utils/format-string.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,31 +157,29 @@ function compileToHTML(json) {
157157

158158
function parseContent(item) {
159159
const result = []
160+
iterateContent(item, result, [])
161+
return result
162+
}
160163

164+
function iterateContent(item, result, types) {
161165
item.content.forEach(it => {
162166
if (typeof it === 'string') {
163167
result.push({
164-
types: [item.type],
168+
types: removeDuplicates(types.concat([item.type])),
165169
value: it
166170
})
167171
} else {
168-
it.content.forEach(i => {
169-
if (typeof i === 'string') {
170-
result.push({
171-
types: [it.type].concat([item.type]),
172-
value: i
173-
})
174-
} else {
175-
result.push({
176-
types: [i.type].concat([it.type]).concat([item.type]),
177-
value: parseContent(i)
178-
})
179-
}
180-
})
172+
iterateContent(
173+
it,
174+
result,
175+
removeDuplicates([it.type].concat([item.type]).concat(types))
176+
)
181177
}
182178
})
179+
}
183180

184-
return result
181+
function removeDuplicates(items) {
182+
return [...new Set(items)]
185183
}
186184

187185
function linkifyResult(array) {

0 commit comments

Comments
 (0)