File tree Expand file tree Collapse file tree 1 file changed +23
-8
lines changed
packages/site-kit/src/lib/markdown Expand file tree Collapse file tree 1 file changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -60,30 +60,45 @@ export function smart_quotes(
6060 html ?: boolean ;
6161 } = { }
6262) {
63- let open_quote = false ;
63+ const stack : Array < "'" | '"' > = [ ] ;
6464 let res = '' ;
6565 const len = str . length ;
6666 for ( let index = 0 ; index < len ; index ++ ) {
67- let char = str . charAt ( index ) ;
67+ const char = str . charAt ( index ) ;
6868 if ( html && char === '&' ) {
6969 if ( str . slice ( index , index + 5 ) === ''' ) {
70- let left : boolean = ( first && ! open_quote ) || ( index > 1 && str . charAt ( index - 1 ) === '=' ) ;
71- open_quote = left ;
70+ const left : boolean =
71+ ( first && stack . at ( - 1 ) !== "'" ) || ( index > 1 && str . charAt ( index - 1 ) === '=' ) ;
7272 res += `&${ left ? 'l' : 'r' } squo;` ;
7373 index += 4 ;
74+ if ( ! left ) {
75+ stack . pop ( ) ;
76+ } else {
77+ stack . push ( "'" ) ;
78+ }
7479 } else if ( str . slice ( index , index + 6 ) === '"' ) {
75- let left : boolean = ( first && ! open_quote ) || ( index > 1 && str . charAt ( index - 1 ) === '=' ) ;
76- open_quote = left ;
80+ const left : boolean =
81+ ( first && stack . at ( - 1 ) !== '"' ) || ( index > 1 && str . charAt ( index - 1 ) === '=' ) ;
7782 res += `&${ left ? 'l' : 'r' } dquo` ;
7883 index += 5 ;
84+ if ( ! left ) {
85+ stack . pop ( ) ;
86+ } else {
87+ stack . push ( '"' ) ;
88+ }
7989 } else {
8090 res += '&' ;
8191 }
8292 } else if ( ! html && ( char === '"' || char === "'" ) ) {
83- let left : boolean = ( first && ! open_quote ) || ( index > 1 && str . charAt ( index - 1 ) === '=' ) ;
84- open_quote = left ;
93+ let left : boolean =
94+ ( first && stack . at ( - 1 ) !== char ) || ( index > 1 && str . charAt ( index - 1 ) === '=' ) ;
8595 let double = char === '"' ;
8696 res += double ? ( left ? '“' : '”' ) : left ? '‘' : '’' ;
97+ if ( ! left ) {
98+ stack . pop ( ) ;
99+ } else {
100+ stack . push ( char ) ;
101+ }
87102 } else {
88103 res += char ;
89104 }
You can’t perform that action at this time.
0 commit comments