Support linebreaks inside a and img elements

* See: https://github.com/next-theme/hexo-theme-next/issues/497
This commit is contained in:
Mimi 2022-03-30 18:38:14 +08:00
parent 968ac54906
commit edf3675f32

View File

@ -10,13 +10,13 @@ hexo.extend.filter.register('after_post_render', data => {
const theme = hexo.theme.config;
if (!theme.exturl && !theme.lazyload) return;
if (theme.lazyload) {
data.content = data.content.replace(/(<img[^>]*) src=/img, '$1 data-src=');
data.content = data.content.replace(/(<img[^>]*)src=/ig, '$1data-src=');
}
if (theme.exturl) {
const siteHost = parse(config.url).hostname || config.url;
// External URL icon
const exturlIcon = theme.exturl_icon ? '<i class="fa fa-external-link-alt"></i>' : '';
data.content = data.content.replace(/<a[^>]* href="([^"]+)"[^>]*>([^<]+)<\/a>/img, (match, href, html) => {
data.content = data.content.replace(/<a[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/ig, (match, href, html) => {
// Exit if the href attribute doesn't exists.
if (!href) return match;