Skip to content

Commit

Permalink
fix(style): resolve uncorrect remove style regex (#225)
Browse files Browse the repository at this point in the history
* fix(style): resolve uncorrect remove style regex

* chore(style): fix typo
  • Loading branch information
potato4d authored Jan 10, 2021
1 parent 5c9978e commit d995b23
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,19 @@ function registerRendererHook (options) {
*/
params.HEAD = params.HEAD
.replace(/<style[^>]*>[.\S\s]*?<\/style>/g, v => v.includes('amp-custom') ? v : '')
.replace(/<\/style>[\S\s]*<style[^>]*>/g, '')
} else {
/**
* Merge inline styles
*/
const styleRegex = /<style(?: .+?)?>([\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, '') + `<style>${styleList.join('\n')}</style>`
}

/**
* Merge inline styles
*/
params.HEAD = params.HEAD.replace(/<\/style>[\S\s]*<style[^>]*>/g, '')

/**
* Mark styles as `amp-custom`
*/
Expand Down

0 comments on commit d995b23

Please sign in to comment.