8
8
* @typedef {import('./complex-types').MDXTextExpression } MDXTextExpression
9
9
*/
10
10
11
- import stripIndent from 'strip-indent'
12
-
13
- const eol = / \r ? \n | \r / g
14
-
15
11
/** @type {FromMarkdownExtension } */
16
12
export const mdxExpressionFromMarkdown = {
17
13
enter : {
@@ -59,7 +55,7 @@ function exitMdxExpression(token) {
59
55
const node = /** @type {MDXFlowExpression|MDXTextExpression } */ (
60
56
this . exit ( token )
61
57
)
62
- node . value = token . type === 'mdxFlowExpression' ? dedent ( value ) : value
58
+ node . value = value
63
59
64
60
if ( estree ) {
65
61
node . data = { estree}
@@ -78,54 +74,5 @@ function exitMdxExpressionData(token) {
78
74
*/
79
75
function handleMdxExpression ( node ) {
80
76
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 + '}'
131
78
}
0 commit comments