DanXi-Dev / DanXi-swift

A Swift Reimplementation of DanXi
GNU Affero General Public License v3.0
13 stars 3 forks source link

Links in markdown are not parsed correctly #221

Open fsy2001 opened 3 months ago

fsy2001 commented 3 months ago

image

fsy2001 commented 3 months ago

Here's a possible fix:

func addSpaceAfterLinks(_ content: String) -> String {
    let pattern = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)(?![\n\s])/

    let modifiedContent = content.replacing(pattern, maxReplacements: 10) { match in
        content[match.range] + " "
    }

    return modifiedContent
}

But the regex still needs fix. It cannot handle contents like

http://www.whxinan.net/dongman/mingzhentankenanwanshengjiedexinniang/2-1.html 这个网站有人在电影院拍的,勉强能看吧

or

https://www.wjx.cn/vm/hxjo6de.aspx# 
关于疫情下志愿服务开展状况的问卷,有50%概率获得红包,roll5个带r的uu请奶茶,请大家帮忙填填😭😭😭