@@ -77,18 +77,28 @@ export const normalizeSlugify = (str: string) => {
77
77
return slugify ( removeHTMLEntities ( removeMarkdown ( str ) ) ) . replace ( / ( < ( [ ^ > ] + ) > ) / gi, '' ) ;
78
78
} ;
79
79
80
- export function smart_quotes ( str : string ) {
80
+ export function smart_quotes ( str : string , html : boolean = false ) {
81
81
// replace dumb quotes with smart quotes. This isn't a perfect algorithm — it
82
82
// wouldn't correctly handle `That '70s show` or `My country 'tis of thee`
83
83
// but a) it's very unlikely they'll occur in our docs, and
84
84
// b) they can be dealt with manually
85
- return str . replace ( / ( .| ^ ) ( & # 3 9 ; | & q u o t ; ) ( .| $ ) / g, ( m , before , quote , after ) => {
86
- const left = ! before . trim ( ) ;
87
- const double = quote === '"' ;
88
- const entity = `&${ left ? 'l' : 'r' } ${ double ? 'd' : 's' } quo;` ;
89
-
90
- return ( before ?? '' ) + entity + ( after ?? '' ) ;
91
- } ) ;
85
+ return str . replace (
86
+ html ? / ( .| ^ ) ( & # 3 9 ; | & q u o t ; ) ( .| $ ) / g : / ( .| ^ ) ( ' | " ) ( .| $ ) / g,
87
+ ( m , before , quote , after ) => {
88
+ const left = ! before . trim ( ) ;
89
+ let replacement = '' ;
90
+
91
+ if ( html ) {
92
+ const double = quote === '"' ;
93
+ replacement = `&${ left ? 'l' : 'r' } ${ double ? 'd' : 's' } quo;` ;
94
+ } else {
95
+ const double = quote === '"' ;
96
+ replacement = double ? ( left ? '“' : '”' ) : left ? '‘' : '’' ;
97
+ }
98
+
99
+ return ( before ?? '' ) + replacement + ( after ?? '' ) ;
100
+ }
101
+ ) ;
92
102
}
93
103
94
104
const tokenizer : TokenizerObject = {
0 commit comments