@@ -153,12 +153,13 @@ export const calculateChunkPositions = (
153153 ) {
154154 const elementName = charToElementName [ character ] ;
155155 if ( elementName ) {
156- const nextCharacter = content [ i + 1 ] ;
156+ const nextCharacter_1 = content [ i + 1 ] ;
157+ const nextCharacter_2 = content [ i + 2 ] ;
157158 // heading
158159 if (
159160 character === '#' &&
160161 state . x === 0 &&
161- ( nextCharacter === ' ' || nextCharacter === '#' )
162+ ( nextCharacter_1 === ' ' || nextCharacter_1 === '#' )
162163 ) {
163164 state . elementMeta = {
164165 elementName,
@@ -168,7 +169,7 @@ export const calculateChunkPositions = (
168169 // tag
169170 else if (
170171 character === '#' &&
171- ! illegalObsidianTagCharacters . has ( nextCharacter ) &&
172+ ! illegalObsidianTagCharacters . has ( nextCharacter_1 ) &&
172173 ( ! state . elementMeta ||
173174 state . elementMeta . canBeParent ||
174175 state . elementMeta . elementName === elementName )
@@ -185,7 +186,7 @@ export const calculateChunkPositions = (
185186 // bullet point
186187 else if ( character === '-' && state . x === 0 ) {
187188 const isTask =
188- nextCharacter === ' ' &&
189+ nextCharacter_1 === ' ' &&
189190 content [ i + 2 ] === '[' &&
190191 content [ i + 4 ] === ']' ;
191192 if ( isTask ) {
@@ -252,12 +253,12 @@ export const calculateChunkPositions = (
252253 ) {
253254 const isHighlight = character === '=' ;
254255 const isDoubleCharacterTag =
255- ( isHighlight && nextCharacter === '=' ) ||
256- ( character === '~' && nextCharacter === '~' ) ||
257- ( character === '[' && nextCharacter === '[' ) ||
258- ( character === ']' && nextCharacter === ']' ) ||
256+ ( isHighlight && nextCharacter_1 === '=' ) ||
257+ ( character === '~' && nextCharacter_1 === '~' ) ||
258+ ( character === '[' && nextCharacter_1 === '[' ) ||
259+ ( character === ']' && nextCharacter_1 === ']' ) ||
259260 // **text**
260- ( character === '*' && nextCharacter === '*' ) ;
261+ ( character === '*' && nextCharacter_1 === '*' ) ;
261262 const isDoubleTagElement =
262263 isDoubleCharacterTag ||
263264 // *text*
@@ -267,11 +268,16 @@ export const calculateChunkPositions = (
267268 if ( isDoubleTagElement ) {
268269 const isClosingTag =
269270 state . elementMeta ?. elementName === elementName ;
271+ const hasSpaceAfterStart = isClosingTag
272+ ? false
273+ : isDoubleCharacterTag
274+ ? nextCharacter_2 === ' '
275+ : nextCharacter_1 === ' ' ;
270276 if ( isClosingTag ) {
271277 state . closingTagLength = isDoubleCharacterTag
272278 ? 2
273279 : 1 ;
274- } else {
280+ } else if ( ! hasSpaceAfterStart ) {
275281 const scope = isHighlight
276282 ? ElementScope . multi_line
277283 : ElementScope . block ;
0 commit comments