From 2b241f54caf7cf29cb5cdd62010410cabb3360f0 Mon Sep 17 00:00:00 2001 From: Takuma HANATANI Date: Sat, 2 Jan 2021 17:12:58 +0900 Subject: [PATCH 1/2] fix(style): resolve uncorrect remove style regex --- lib/module.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/module.js b/lib/module.js index a7582d6f..f49052bd 100644 --- a/lib/module.js +++ b/lib/module.js @@ -169,10 +169,12 @@ function registerRendererHook (options) { .replace(/]*>[.\S\s]*?<\/style>/g, v => v.includes('amp-custom') ? v : '') } - /** - * Merge inline styles - */ - params.HEAD = params.HEAD.replace(/<\/style>[\S\s]*]*>/g, '') + const styleRegex = /([\s\S]*?)<\/style>/g + const styleList = params.HEAD.match(styleRegex).map((css) => { + const rawStyle = css.replace(styleRegex, '$1\n') + return rawStyle + }) + params.HEAD = params.HEAD.replace(styleRegex, '') + `` /** * Mark styles as `amp-custom` From 3cf5d8db5c9ca901ed9bff9f2eb09460204caf72 Mon Sep 17 00:00:00 2001 From: Takuma HANATANI Date: Sat, 2 Jan 2021 17:33:26 +0900 Subject: [PATCH 2/2] chore(style): fix typo --- lib/module.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/module.js b/lib/module.js index f49052bd..6b14d7ae 100644 --- a/lib/module.js +++ b/lib/module.js @@ -167,15 +167,19 @@ function registerRendererHook (options) { */ params.HEAD = params.HEAD .replace(/]*>[.\S\s]*?<\/style>/g, v => v.includes('amp-custom') ? v : '') + .replace(/<\/style>[\S\s]*]*>/g, '') + } else { + /** + * Merge inline styles + */ + const styleRegex = /([\s\S]*?)<\/style>/g + const styleList = params.HEAD.match(styleRegex).map((css) => { + const rawStyle = css.replace(styleRegex, '$1\n') + return rawStyle + }) + params.HEAD = params.HEAD.replace(styleRegex, '') + `` } - const styleRegex = /([\s\S]*?)<\/style>/g - const styleList = params.HEAD.match(styleRegex).map((css) => { - const rawStyle = css.replace(styleRegex, '$1\n') - return rawStyle - }) - params.HEAD = params.HEAD.replace(styleRegex, '') + `` - /** * Mark styles as `amp-custom` */