美文网首页
HTML实体转码

HTML实体转码

作者: stanf1l | 来源:发表于2019-01-12 15:31 被阅读0次

    以下代码用来将包含HTML实体的lrc文档字符串进行转码

    const main = (lrc) => {
      let str = lrc.replace(/&#\d+?;/g,(a)=> {
        let ret = a.slice(2,a.length-1)
        ret = String.fromCharCode(ret)
        return ret
      })
      console.log(str)
    }
    

    转码前:

    [ti:Don’t Wanna Write This Song]
[ar:Brett Young]
[al:Ticket To L.A.]
[by:]
[offset:0]
[00:00.23]Don’t Wanna Write This Song - Brett Young
[00:01.92]Lyrics by:Brett Young/Zach Crowell/Sean McConnell
[00:03.51]Composed by:Brett Young/Zach Crowell/Sean McConnell
[00:19.93]There's a dress in the closet that I just can't throw away
[00:26.16]I know it might sound crazy but I haven't changed your pillowcase
[00:31.07]A heart half full or half empty
[00:35.16]Is half gone either way with you gone
[00:44.32]What went wrong
[00:52.17]Maybe the hardest part
[00:55.31]Is we didn't break this heart
[00:58.49]Nobody cheated or lied
[01:01.55]I still have to live with goodbye
[01:04.63]But how can I just move on
[01:07.81]I've loved you for way too long
[01:10.76]I don't want to admit that you're gone
[01:14.18]I don't wanna write this song
[01:22.03]Don't wanna write this song
[01:30.16]Another glass of whiskey by your picture in a frame
[01:36.44]I'm playin' all the black keys and cryin' out your name
[01:41.71]I'm holdin' on or lettin' go
[01:44.93]It's gonna kill me either way
[01:48.31]With you gone
[01:54.35]Oh
[01:56.09]Maybe the hardest part
[01:59.14]Is we didn't break this heart
[02:02.48]Nobody cheated or lied
[02:05.62]I still have to live with goodbye
[02:08.79]But how can I just move on
[02:11.73]I've loved you for way too long
[02:15.03]I don't want to admit that you're gone
[02:18.29]I don't wanna write this song
[02:26.15]Don't wanna write this song
[02:34.36]Bobby pins on the dresser
[02:36.78]Wilted flowers in a vase
[02:40.28]I left a rose on your headstone
[02:42.95]I never quite know what to say
[02:47.28]Oh
[02:48.95]Maybe the hardest part
[02:51.97]Is we didn't break this heart
[02:54.85]Nobody cheated or lied
[02:58.35]I still have to live with goodbye
[03:01.67]But how can I just move on
[03:04.71]I've loved you for way too long
[03:08.34]I don't want to admit that you're gone
[03:11.28]I don't wanna write this song
[03:18.28]No don't wanna write this song
[03:24.68]Haa
[03:25.00]I don't wanna write this song
[03:31.15]Mmm don't wanna write this song mmm whoa
    }
    

    转码后:

    [ti:Don’t Wanna Write This Song]
    [ar:Brett Young]
    [al:Ticket To L.A.]
    [by:]
    [offset:0]
    [00:00.23]Don’t Wanna Write This Song - Brett Young
    [00:01.92]Lyrics by:Brett Young/Zach Crowell/Sean McConnell
    [00:03.51]Composed by:Brett Young/Zach Crowell/Sean McConnell
    [00:19.93]There's a dress in the closet that I just can't throw away
    [00:26.16]I know it might sound crazy but I haven't changed your pillowcase
    [00:31.07]A heart half full or half empty
    [00:35.16]Is half gone either way with you gone
    [00:44.32]What went wrong
    [00:52.17]Maybe the hardest part
    [00:55.31]Is we didn't break this heart
    [00:58.49]Nobody cheated or lied
    [01:01.55]I still have to live with goodbye
    [01:04.63]But how can I just move on
    [01:07.81]I've loved you for way too long
    [01:10.76]I don't want to admit that you're gone
    [01:14.18]I don't wanna write this song
    [01:22.03]Don't wanna write this song
    [01:30.16]Another glass of whiskey by your picture in a frame
    [01:36.44]I'm playin' all the black keys and cryin' out your name
    [01:41.71]I'm holdin' on or lettin' go
    [01:44.93]It's gonna kill me either way
    [01:48.31]With you gone
    [01:54.35]Oh
    [01:56.09]Maybe the hardest part
    [01:59.14]Is we didn't break this heart
    [02:02.48]Nobody cheated or lied
    [02:05.62]I still have to live with goodbye
    [02:08.79]But how can I just move on
    [02:11.73]I've loved you for way too long
    [02:15.03]I don't want to admit that you're gone
    [02:18.29]I don't wanna write this song
    [02:26.15]Don't wanna write this song
    [02:34.36]Bobby pins on the dresser
    [02:36.78]Wilted flowers in a vase
    [02:40.28]I left a rose on your headstone
    [02:42.95]I never quite know what to say
    [02:47.28]Oh
    [02:48.95]Maybe the hardest part
    [02:51.97]Is we didn't break this heart
    [02:54.85]Nobody cheated or lied
    [02:58.35]I still have to live with goodbye
    [03:01.67]But how can I just move on
    [03:04.71]I've loved you for way too long
    [03:08.34]I don't want to admit that you're gone
    [03:11.28]I don't wanna write this song
    [03:18.28]No don't wanna write this song
    [03:24.68]Haa
    [03:25.00]I don't wanna write this song
    [03:31.15]Mmm don't wanna write this song mmm whoa
    

    相关文章

      网友评论

          本文标题:HTML实体转码

          本文链接:https://www.haomeiwen.com/subject/qhlcdqtx.html