Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Fix userStyle CSS parsing problem
Browse files Browse the repository at this point in the history
The problem was: failed to parse when
  - newline exists before `/*<viewer>*/`
  - font-family value has space character
  • Loading branch information
MurakamiShinyu committed Mar 10, 2019
1 parent 758f8a1 commit 1c469a8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/js/models/page-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class PageStyle {
this.pageStyleRegExp = new RegExp(

// 1. beforeOtherStyle,
"^(.*?)\\/\\*<viewer>\\*\\/\\s*(?:@page\\s*\\{\\s*" +
"^((?:\\n|.)*?)\\/\\*<viewer>\\*\\/\\s*(?:@page\\s*\\{\\s*" +

// 2. sizeW, sizeH, sizeImportant,
"(?:size:\\s*([^\\s!;{}]+)(?:\\s+([^\\s!;{}]+))?\\s*(!important)?(?:;|(?=[\\s{}]))\\s*)?" +
Expand All @@ -161,7 +161,7 @@ class PageStyle {
"((?:html|:root),\\s*body\\s*\\{\\s*margin:\\s*0(?:\\w+|%)?\\s*!important(?:;|(?=[\\s{}]))\\s*\\}\\s*)?" +

// 12. baseFontSize, baseFontSizeImportant, baseLineHeight, baseLineHeightImportant, baseFontFamily, baseFontFamilyImportant, rootOtherStyle,
"(?:(?:html|:root)\\s*\\{\\s*(?:font-size:\\s*(calc\\([^()]+\\)|[^\\s!;{}]+)\\s*(!important)?(?:;|(?=[\\s{}]))\\s*)?(?:line-height:\\s*([^\\s!;{}]+)\\s*(!important)?(?:;|(?=[\\s{}]))\\s*)?(?:font-family:\\s*([^\\s!;{}]+)\\s*(!important)?(?:;|(?=[\\s{}]))\\s*)?([^{}]*)\\}\\s*)?" +
"(?:(?:html|:root)\\s*\\{\\s*(?:font-size:\\s*(calc\\([^()]+\\)|[^\\s!;{}]+)\\s*(!important)?(?:;|(?=[\\s{}]))\\s*)?(?:line-height:\\s*([^\\s!;{}]+)\\s*(!important)?(?:;|(?=[\\s{}]))\\s*)?(?:font-family:\\s*([^!;{}]+)\\s*(!important)?(?:;|(?=[\\s{}]))\\s*)?([^{}]*)\\}\\s*)?" +

// body {font-size: inherit !important;} etc.
"(?:body\\s*\\{\\s*(?:[-\\w]+:\\s*inherit\\s*!important(?:;|(?=[\\s{}]))\\s*)+\\}\\s*)?" +
Expand All @@ -173,7 +173,7 @@ class PageStyle {
"(?:img,\\s*svg\\s*\\{\\s*(max-inline-size:\\s*100%\\s*(!important)?(?:;|(?=[\\s{}]))\\s*max-block-size:\\s*100vb\\s*\\22(?:;|(?=[\\s{}]))\\s*)?(object-fit:\\s*contain\\s*(!important)?(?:;|(?=[\\s{}]))\\s*)?\\}\\s*)?" +

// 25. afterOtherStyle
"((?:\n|.)*)$"
"((?:\\n|.)*)$"
);

if (pageStyle) {
Expand Down Expand Up @@ -329,6 +329,7 @@ class PageStyle {
this.baseLineHeightSpecified(false);
}
if (baseFontFamily != null) {
baseFontFamily = baseFontFamily.trim();
this.baseFontFamilySpecified(true);
this.baseFontFamily(baseFontFamily);
this.baseFontFamilyImportant(!!baseFontFamilyImportant);
Expand Down

0 comments on commit 1c469a8

Please sign in to comment.