Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linearGradient siblings are moved inside linearGradient #23

Closed
4 tasks done
remcohaszing opened this issue May 5, 2024 · 4 comments
Closed
4 tasks done

linearGradient siblings are moved inside linearGradient #23

remcohaszing opened this issue May 5, 2024 · 4 comments
Labels
💪 phase/solved Post is done 🐛 type/bug This is a problem

Comments

@remcohaszing
Copy link
Member

Initial checklist

Affected packages and versions

hast-util-raw@9.0.2

Link to runnable example

No response

Steps to reproduce

Fun the following script:

import { raw } from 'hast-util-raw'

const reformatted = raw({
  type: 'root',
  children: [
    {
      type: 'element',
      tagName: 'svg',
      properties: {},
      children: [
        {
          type: 'element',
          tagName: 'circle',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'rect',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'linearGradient',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'path',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'g',
          properties: {},
          children: []
        }
      ]
    }
  ]
})

console.dir(reformatted, { depth: Number.POSITIVE_INFINITY })

This causes remcohaszing/rehype-mermaid#17

Expected behavior

It logs:

{
  type: 'root',
  children: [
    {
      type: 'element',
      tagName: 'svg',
      properties: {},
      children: [
        {
          type: 'element',
          tagName: 'circle',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'rect',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'linearGradient',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'path',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'g',
          properties: {},
          children: []
        }
      ]
    }
  ],
  data: { quirksMode: false }
}

Actual behavior

It moves all siblings after linearGradient inside its children.

{
  type: 'root',
  children: [
    {
      type: 'element',
      tagName: 'svg',
      properties: {},
      children: [
        {
          type: 'element',
          tagName: 'circle',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'rect',
          properties: {},
          children: []
        },
        {
          type: 'element',
          tagName: 'linearGradient',
          properties: {},
          children: [
            {
              type: 'element',
              tagName: 'path',
              properties: {},
              children: []
            },
            {
              type: 'element',
              tagName: 'g',
              properties: {},
              children: []
            }
          ]
        }
      ]
    }
  ],
  data: { quirksMode: false }
}

Affected runtime and version

node@22.1.0

Affected package manager and version

npm@10.7.0

Affected OS and version

Pop!_OS 22.04

Build and bundle tools

No response

@remcohaszing remcohaszing added 🐛 type/bug This is a problem 🤞 phase/open Post is being triaged manually labels May 5, 2024
@wooorm
Copy link
Member

wooorm commented May 6, 2024

Weird. It seems to be the camelcase.
If I pass any other lowercase string (even lineargradient) through, it nests adjacently fine.
And the weird thing with lineargradient: if I pass that in, I get linearGradient out!

@wooorm
Copy link
Member

wooorm commented May 6, 2024

My guess for what’s going on is that the HTML parser is case-insensitive for tag names.
So, parse5 lowercases things.
When we here pass a cased string in, most things go fine, but when doing the closing tag, it doesn’t match up to the current open tag, and is thus discarded.

@wooorm wooorm closed this as completed in 57c9910 May 6, 2024

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label May 6, 2024
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label May 6, 2024
@wooorm
Copy link
Member

wooorm commented May 6, 2024

released in 9.0.3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done 🐛 type/bug This is a problem
Development

No branches or pull requests

2 participants