实现播放音乐
用网易云音乐播放markdown格式信息给出的歌曲。
实现
import Foundation
import Ink
import Sweep
var musicPlayer = Modifier(target: .codeBlocks) { html, markdown in
guard let content = markdown.substrings(between: "```musicPlayer\n", and: "\n```").first else {
return html
}
var musicID: String = ""
var auto: String = ""
content.scan(using: [
Matcher(identifier: "musicID: ", terminator: "\n", allowMultipleMatches: false) { match, _ in
musicID = String(match)
},
Matcher(identifier: "auto: ", terminator: "\n", allowMultipleMatches: false) { match, _ in
auto = String(match)
},
])
return
"""
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=100% height=86 src="http://music.163.com/outchain/player?type=2&id=\(musicID)&auto=\(auto)&height=66"></iframe>
"""
}
调用
try ChengzhenyuBlog().publish(
using: [
// ...
.addModifier(modifier: musicPlayer,modifierName:"music player"),
// ...
]