Skip to content

feat: support foreign elements#8

Merged
fcrozatier merged 4 commits into
mainfrom
foreign-elements
Jul 4, 2025
Merged

feat: support foreign elements#8
fcrozatier merged 4 commits into
mainfrom
foreign-elements

Conversation

@fcrozatier

Copy link
Copy Markdown
Owner

svg and math elements have different parsing rules: self-closing elements, case-sensitive tage names etc

const markup =
    `<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<!-- A self-closing tag -->
<circle cx="50" cy="50" r="40" stroke="green" fill="yellow"/>

<!-- Another self-closing tag but without the slash (valid in HTML, not in XML) -->
<rect x="10" y="10" width="30" height="30">

  <!-- Embedded foreign content  -->
  <script type="application/ecmascript">
      console.log("Inside SVG &lt;script&gt;");
  </script>

  <!-- Nested elements with same tag name -->
  <g>
    <g>
      <text x="10" y="90">Nested <tspan font-weight="bold">text</tspan> inside</text>
    </g>
  </g>

  <!-- Namespaced element -->
  <animateTransform attributeName="transform" type="rotate" from="0 50 50" to="360 50 50" dur="10s" repeatCount="indefinite"/>
</rect>
</svg>`;

const svg = element.parseOrThrow(markup);

assertEquals(serializeNode(svg), markup.replaceAll("/>", ">"));

@fcrozatier
fcrozatier merged commit c17386d into main Jul 4, 2025
3 checks passed
@fcrozatier
fcrozatier deleted the foreign-elements branch July 4, 2025 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant