Skip to content

Commit

Permalink
fix: rules shouldn't update state.posMax (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed May 30, 2024
1 parent 6d3a306 commit 8fe34b1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
7 changes: 0 additions & 7 deletions src/syntax/inline-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,17 @@ export const MarkdownItInlineComponent: MarkdownIt.PluginWithOptions<MdcInlineCo
if (contentEnd !== contentStart) {
const name = state.src.slice(start + 1, contentStart - 1)
const body = state.src.slice(contentStart, contentEnd)
state.posMax = contentStart
state.push('mdc_inline_component', name, 1)
state.pos = contentStart
state.posMax = contentEnd
const text = state.push('text', '', 0)
text.content = body
state.pos = contentEnd
state.posMax = contentEnd
state.push('mdc_inline_component', name, -1)
}
else {
state.posMax = index
const name = state.src.slice(start + 1, index)
state.push('mdc_inline_component', name, 0)
}

state.pos = index
state.posMax = index

return true
})
Expand Down
4 changes: 0 additions & 4 deletions src/syntax/inline-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ export const MarkdownItInlineProps: MarkdownIt.PluginWithOptions<MdcInlinePropsO
if (silent)
return true

state.pos = start
state.posMax = end

// We insert a hidden token holding the props, and later apply them to the previous token
const token = state.push('mdc_inline_props', 'span', 0)
token.attrs = props
token.hidden = true

state.pos = end
state.posMax = end

return true
})
Expand Down
7 changes: 0 additions & 7 deletions src/syntax/inline-span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,14 @@ export const MarkdownItInlineSpan: MarkdownIt.PluginWithOptions<MdcInlineSpanOpt
if (silent)
return true

state.posMax = start + 1
state.push('mdc_inline_span', 'span', 1)

state.pos = start + 1
state.posMax = index
const text = state.push('text', '', 0)
text.content = state.src.slice(start + 1, index)

state.pos = index
state.posMax = index + 1

state.push('mdc_inline_span', 'span', -1)

state.pos = index + 1
state.posMax = index + 1

return true
})
Expand Down
4 changes: 4 additions & 0 deletions test/input/7.inline-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ A simple :inline-component[John Doe]
How to say :hello{}-world in Markdown

Inline :component{key="value" key2=value2}!

Inline :component and [link](https://example.com)!

Inline :component[John Doe]{.cls} and _Italic_!
4 changes: 3 additions & 1 deletion test/output/7.inline-components.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<p>A simple <inline-component /></p>
<p>A simple <inline-component>John Doe</inline-component></p>
<p>How to say <hello />-world in Markdown</p>
<p>Inline <component key="value" key2="value2" />!</p>
<p>Inline <component key="value" key2="value2" />!</p>
<p>Inline <component /> and <a href="https://example.com">link</a>!</p>
<p>Inline <component class="cls">John Doe</component> and <em>Italic</em>!</p>

0 comments on commit 8fe34b1

Please sign in to comment.