@@ -9,7 +9,7 @@ const styles = 'italic|oblique'
9
9
const variants = 'small-caps'
10
10
const stretches = 'ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded'
11
11
const units = 'px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q'
12
- const string = '\'([^\']+)\ '|"([^"]+)"|[\\w\\ s-]+'
12
+ const string = / ' ( ( \\ ' | [ ^ ' ] ) + ) ' | " ( ( \\ " | [ ^ " ] ) + ) " | [ \w \ s- ] + / . source
13
13
14
14
// [ [ <‘font-style’> || <font-variant-css21> || <‘font-weight’> || <‘font-stretch’> ]?
15
15
// <‘font-size’> [ / <‘line-height’> ]? <‘font-family’> ]
@@ -18,6 +18,9 @@ const weightRe = new RegExp(`(${weights}) +`, 'i')
18
18
const styleRe = new RegExp ( `(${ styles } ) +` , 'i' )
19
19
const variantRe = new RegExp ( `(${ variants } ) +` , 'i' )
20
20
const stretchRe = new RegExp ( `(${ stretches } ) +` , 'i' )
21
+ const familyRe = new RegExp ( string , 'g' )
22
+ const unquoteRe = / ^ [ ' " ] ( .* ) [ ' " ] $ /
23
+ const unescapeRe = / \\ ( [ ' " ] ) / g
21
24
const sizeFamilyRe = new RegExp (
22
25
`([\\d\\.]+)(${ units } ) *((?:${ string } )( *, *(?:${ string } ))*)` )
23
26
@@ -46,6 +49,12 @@ module.exports = str => {
46
49
const sizeFamily = sizeFamilyRe . exec ( str )
47
50
if ( ! sizeFamily ) return // invalid
48
51
52
+ const names = sizeFamily [ 3 ]
53
+ . match ( familyRe )
54
+ // remove actual bounding quotes, if any, unescape any remaining quotes inside
55
+ . map ( s => s . trim ( ) . replace ( unquoteRe , '$1' ) . replace ( unescapeRe , '$1' ) )
56
+ . filter ( s => ! ! s )
57
+
49
58
// Default values and required properties
50
59
const font = {
51
60
weight : 'normal' ,
@@ -54,7 +63,7 @@ module.exports = str => {
54
63
variant : 'normal' ,
55
64
size : parseFloat ( sizeFamily [ 1 ] ) ,
56
65
unit : sizeFamily [ 2 ] ,
57
- family : sizeFamily [ 3 ] . replace ( / [ " ' ] / g , '' ) . replace ( / * , * / g , ',' )
66
+ family : names . join ( ',' )
58
67
}
59
68
60
69
// Optional, unordered properties.
0 commit comments