#83 编辑器支持哔哩哔哩([bilibili:id,宽,高])和YouTube([youtube:id,宽,高])的短代码

pull/137/head
ruibaby 2019-03-03 17:05:49 +08:00
parent f7d40db7b1
commit 8ec7cef1e5
2 changed files with 42 additions and 0 deletions

View File

@ -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+)\\]";
}

View File

@ -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));
}
}