mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-10 19:57:43 +02:00
Fix links after translation and in tg (#7788)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
@@ -255,6 +255,8 @@ function addMarks (builder: NodeBuilder, marks: MarkupMark[], next?: () => void)
|
||||
addMark(builder, mark, () => {
|
||||
addMarks(builder, others, next)
|
||||
})
|
||||
} else {
|
||||
addMark(builder, mark, next)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,11 +80,13 @@ export function platformToTelegram (message: string, limit: number): string {
|
||||
string,
|
||||
{
|
||||
count: number
|
||||
hasContent: boolean
|
||||
defaultText: string
|
||||
}
|
||||
>()
|
||||
|
||||
const parser = new Parser({
|
||||
onopentag: (tag) => {
|
||||
onopentag: (tag, attributes) => {
|
||||
if (tag === 'br' || tag === 'p') {
|
||||
return
|
||||
}
|
||||
@@ -104,18 +106,37 @@ export function platformToTelegram (message: string, limit: number): string {
|
||||
return
|
||||
}
|
||||
|
||||
let defaultText = ''
|
||||
|
||||
if (tag === 'a' && 'href' in attributes) {
|
||||
newMessage += `<a href="${attributes.href}">`
|
||||
defaultText = attributes.href
|
||||
} else {
|
||||
newMessage += `<${tag}>`
|
||||
}
|
||||
|
||||
openedTags.set(tag, {
|
||||
count: 1
|
||||
count: 1,
|
||||
hasContent: false,
|
||||
defaultText
|
||||
})
|
||||
newMessage += `<${tag}>`
|
||||
},
|
||||
ontext: (text) => {
|
||||
ontext: (rawText) => {
|
||||
if (textLength >= limit) {
|
||||
return
|
||||
}
|
||||
|
||||
textLength += unescape(text).length
|
||||
newMessage += unescape(text)
|
||||
const text = unescape(rawText)
|
||||
textLength += text.length
|
||||
newMessage += text
|
||||
|
||||
const lastOpenedTag = Array.from(openedTags.keys()).pop()
|
||||
if (lastOpenedTag != null) {
|
||||
const tagData = openedTags.get(lastOpenedTag)
|
||||
if (tagData != null && text !== '') {
|
||||
tagData.hasContent = true
|
||||
}
|
||||
}
|
||||
|
||||
if (textLength > limit) {
|
||||
const extra = textLength - limit + 1
|
||||
@@ -148,6 +169,10 @@ export function platformToTelegram (message: string, limit: number): string {
|
||||
return
|
||||
}
|
||||
|
||||
if (!existingTag.hasContent && existingTag.defaultText !== '') {
|
||||
newMessage += existingTag.defaultText
|
||||
}
|
||||
|
||||
existingTag.count -= 1
|
||||
|
||||
if (existingTag.count <= 0) {
|
||||
|
||||
Reference in New Issue
Block a user