@@ -19,14 +19,14 @@ import getMinNotPresentContinuousCount from "../utils/get-min-not-present-contin
1919import getPreferredQuote from "../utils/get-preferred-quote.js" ;
2020import UnexpectedNodeError from "../utils/unexpected-node-error.js" ;
2121import clean from "./clean.js" ;
22- import { PUNCTUATION_REGEXP } from "./constants.evaluate.js" ;
2322import embed from "./embed.js" ;
2423import getVisitorKeys from "./get-visitor-keys.js" ;
2524import { locEnd , locStart } from "./loc.js" ;
2625import { insertPragma } from "./pragma.js" ;
2726import { printChildren } from "./print/children.js" ;
2827import { printList } from "./print/list.js" ;
2928import { printTable } from "./print/table.js" ;
29+ import { printWord } from "./print/word.js" ;
3030import { printParagraph } from "./print-paragraph.js" ;
3131import preprocess from "./print-preprocess.js" ;
3232import { printSentence } from "./print-sentence.js" ;
@@ -99,47 +99,8 @@ function genericPrint(path, options, print) {
9999 return printParagraph ( path , options , print ) ;
100100 case "sentence" :
101101 return printSentence ( path , print ) ;
102- case "word" : {
103- let escapedValue = node . value
104- . replaceAll ( "*" , String . raw `\*` ) // escape all `*`
105- . replaceAll (
106- new RegExp (
107- [
108- `(^|${ PUNCTUATION_REGEXP . source } )(_+)` ,
109- `(_+)(${ PUNCTUATION_REGEXP . source } |$)` ,
110- ] . join ( "|" ) ,
111- "gu" ,
112- ) ,
113- ( _ , text1 , underscore1 , underscore2 , text2 ) =>
114- ( underscore1
115- ? `${ text1 } ${ underscore1 } `
116- : `${ underscore2 } ${ text2 } `
117- ) . replaceAll ( "_" , String . raw `\_` ) ,
118- ) ; // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
119-
120- const isFirstSentence = ( node , name , index ) =>
121- node . type === "sentence" && index === 0 ;
122- const isLastChildAutolink = ( node , name , index ) =>
123- isAutolink ( node . children [ index - 1 ] ) ;
124-
125- if (
126- escapedValue !== node . value &&
127- ( path . match ( undefined , isFirstSentence , isLastChildAutolink ) ||
128- path . match (
129- undefined ,
130- isFirstSentence ,
131- ( node , name , index ) => node . type === "emphasis" && index === 0 ,
132- isLastChildAutolink ,
133- ) )
134- ) {
135- // backslash is parsed as part of autolinks, so we need to remove it
136- escapedValue = escapedValue . replace ( / ^ ( \\ ? [ * _ ] ) + / u, ( prefix ) =>
137- prefix . replaceAll ( "\\" , "" ) ,
138- ) ;
139- }
140-
141- return escapedValue ;
142- }
102+ case "word" :
103+ return printWord ( path ) ;
143104 case "whitespace" : {
144105 const { next } = path ;
145106
0 commit comments