88 * @typedef {import('./complex-types').MDXTextExpression } MDXTextExpression
99 */
1010
11- import stripIndent from 'strip-indent'
12-
13- const eol = / \r ? \n | \r / g
14-
1511/** @type {FromMarkdownExtension } */
1612export const mdxExpressionFromMarkdown = {
1713 enter : {
@@ -59,7 +55,7 @@ function exitMdxExpression(token) {
5955 const node = /** @type {MDXFlowExpression|MDXTextExpression } */ (
6056 this . exit ( token )
6157 )
62- node . value = token . type === 'mdxFlowExpression' ? dedent ( value ) : value
58+ node . value = value
6359
6460 if ( estree ) {
6561 node . data = { estree}
@@ -78,54 +74,5 @@ function exitMdxExpressionData(token) {
7874 */
7975function handleMdxExpression ( node ) {
8076 const value = node . value || ''
81- return '{' + ( node . type === 'mdxFlowExpression' ? indent ( value ) : value ) + '}'
82- }
83-
84- /**
85- * @param {string } value
86- * @returns {string }
87- */
88- function dedent ( value ) {
89- const firstLineEnding = / \r ? \n | \r / . exec ( value )
90- const position = firstLineEnding
91- ? firstLineEnding . index + firstLineEnding [ 0 ] . length
92- : - 1
93-
94- if ( position > - 1 ) {
95- return value . slice ( 0 , position ) + stripIndent ( value . slice ( position ) )
96- }
97-
98- return value
99- }
100-
101- /**
102- * @param {string } value
103- * @returns {string }
104- */
105- function indent ( value ) {
106- /** @type {Array.<string> } */
107- const result = [ ]
108- let start = 0
109- let line = 0
110- /** @type {RegExpExecArray|null } */
111- let match
112-
113- while ( ( match = eol . exec ( value ) ) ) {
114- one ( value . slice ( start , match . index ) )
115- result . push ( match [ 0 ] )
116- start = match . index + match [ 0 ] . length
117- line ++
118- }
119-
120- one ( value . slice ( start ) )
121-
122- return result . join ( '' )
123-
124- /**
125- * @param {string } slice
126- * @returns {void }
127- */
128- function one ( slice ) {
129- result . push ( ( line && slice ? ' ' : '' ) + slice )
130- }
77+ return '{' + value + '}'
13178}
0 commit comments