From d995b23e5d061c1783d342d81855aec6aa202d2e Mon Sep 17 00:00:00 2001 From: Takuma HANATANI Date: Sun, 10 Jan 2021 19:38:30 +0900 Subject: [PATCH] fix(style): resolve uncorrect remove style regex (#225) * fix(style): resolve uncorrect remove style regex * chore(style): fix typo --- lib/module.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/module.js b/lib/module.js index a7582d6f..6b14d7ae 100644 --- a/lib/module.js +++ b/lib/module.js @@ -167,13 +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, '') + `` } - /** - * Merge inline styles - */ - params.HEAD = params.HEAD.replace(/<\/style>[\S\s]*]*>/g, '') - /** * Mark styles as `amp-custom` */