mirror of https://github.com/halo-dev/halo
✨ #83 编辑器支持哔哩哔哩([bilibili:id,宽,高])和YouTube([youtube:id,宽,高])的短代码
parent
f7d40db7b1
commit
8ec7cef1e5
|
@ -54,4 +54,34 @@ public class HaloConst {
|
|||
* 网易云音乐短代码正则表达式
|
||||
*/
|
||||
public static final String NETEASE_MUSIC_REG_PATTERN = "\\[music:(\\d+)\\]";
|
||||
|
||||
/**
|
||||
* 哔哩哔哩视频短代码前缀
|
||||
*/
|
||||
public static final String BILIBILI_VIDEO_PREFIX = "[bilibili:";
|
||||
|
||||
/**
|
||||
* 哔哩哔哩视频 iframe 代码
|
||||
*/
|
||||
public static final String BILIBILI_VIDEO_IFRAME = "<iframe height=$3 width=$2 src=\"//player.bilibili.com/player.html?aid=$1\" scrolling=\"no\" border=\"0\" frameborder=\"no\" framespacing=\"0\" allowfullscreen=\"true\"> </iframe>";
|
||||
|
||||
/**
|
||||
* 哔哩哔哩视频正则表达式
|
||||
*/
|
||||
public static final String BILIBILI_VIDEO_REG_PATTERN = "\\[bilibili:(\\d+)\\,(\\d+)\\,(\\d+)\\]";
|
||||
|
||||
/**
|
||||
* YouTube 视频短代码前缀
|
||||
*/
|
||||
public static final String YOUTUBE_VIDEO_PREFIX = "[youtube:";
|
||||
|
||||
/**
|
||||
* YouTube 视频 iframe 代码
|
||||
*/
|
||||
public static final String YOUTUBE_VIDEO_IFRAME = "<iframe width=$2 height=$3 src=\"https://www.youtube.com/embed/$1\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>";
|
||||
|
||||
/**
|
||||
* YouTube 视频正则表达式
|
||||
*/
|
||||
public static final String YOUTUBE_VIDEO_REG_PATTERN = "\\[youtube:(\\w+)\\,(\\d+)\\,(\\d+)\\]";
|
||||
}
|
||||
|
|
|
@ -54,6 +54,14 @@ public class MarkdownUtils {
|
|||
if (content.contains(HaloConst.NETEASE_MUSIC_PREFIX)) {
|
||||
renderContent = content.replaceAll(HaloConst.NETEASE_MUSIC_REG_PATTERN, HaloConst.NETEASE_MUSIC_IFRAME);
|
||||
}
|
||||
// render bilibili video short url
|
||||
if (content.contains(HaloConst.BILIBILI_VIDEO_PREFIX)) {
|
||||
renderContent = content.replaceAll(HaloConst.BILIBILI_VIDEO_REG_PATTERN, HaloConst.BILIBILI_VIDEO_IFRAME);
|
||||
}
|
||||
// render youtube video short url
|
||||
if (content.contains(HaloConst.YOUTUBE_VIDEO_PREFIX)) {
|
||||
renderContent = content.replaceAll(HaloConst.YOUTUBE_VIDEO_REG_PATTERN, HaloConst.YOUTUBE_VIDEO_IFRAME);
|
||||
}
|
||||
return renderContent;
|
||||
}
|
||||
|
||||
|
@ -69,4 +77,8 @@ public class MarkdownUtils {
|
|||
document.accept(visitor);
|
||||
return visitor.getData();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("[bilibili:44971847]".replaceAll(HaloConst.BILIBILI_VIDEO_REG_PATTERN, HaloConst.BILIBILI_VIDEO_IFRAME));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue