Skip to content

{.x} after an element replaces its class instead of adding to it #568

Closed

Description

@onmax

Environment

Node v24.21.0, Linux, no framework

Comark Version

main (439c6f0)

Reproduction

Core syntax doesn't create an element that already has a class, so the playground can't show this. A plugin that turns ++esc++ into <kbd class="key"> does:

const kbd = {
  name: 'kbd',
  markdownItPlugins: [(md) => md.inline.ruler.before('emphasis', 'kbd', (state, silent) => {
    if (!state.src.startsWith('++', state.pos)) return false
    const end = state.src.indexOf('++', state.pos + 2)
    if (end < 0) return false
    if (!silent) {
      state.push('mdc_inline_span_open', 'kbd', 1).attrs = [['class', 'key']]
      state.push('text', '', 0).content = state.src.slice(state.pos + 2, end)
      state.push('mdc_inline_span_close', 'kbd', -1)
    }
    state.pos = end + 2
    return true
  })],
}

await parseMarkdown('++esc++{.big}', { plugins: [kbd] })
// ['kbd', { class: 'big' }, 'esc'], expected class 'key big'

Description

{.big} after an element replaces the class it already has. processPossibleAttributesSyntax merges with Object.assign. Happy to open a PR that appends the class.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions