{"id":25715,"library":"h2x-core","title":"h2x-core","description":"h2x-core is the core compiler for h2x, an HTML-to-JSX transformer. It converts HTML strings into a JavaScript AST (JSX) via JSDOM, using a plugin system for extensibility. Version 1.1.1 is current, with releases every few months. Key differentiators: leverages JSDOM for robust parsing, supports state, and has a plugin architecture. It handles special SVG attributes and style attributes. Alternatives are typically SVGR or manual transformation.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/smooth-code/h2x/tree/master/packages/h2x-core","tags":["javascript"],"install":[{"cmd":"npm install h2x-core","lang":"bash","label":"npm"},{"cmd":"yarn add h2x-core","lang":"bash","label":"yarn"},{"cmd":"pnpm add h2x-core","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"provides node type definitions","package":"h2x-types","optional":false},{"reason":"used to parse HTML into a DOM tree for AST generation","package":"jsdom","optional":false}],"imports":[{"note":"Use ESM import. CommonJS require also works but is less common.","wrong":"const { compile } = require('h2x-core')","symbol":"compile","correct":"import { compile } from 'h2x-core'"},{"note":"The correct function name is 'transform', not 'transpile'.","wrong":"import { transpile } from 'h2x-core'","symbol":"transform","correct":"import { transform } from 'h2x-core'"},{"note":"Direct 'parse' export. No submodule import.","wrong":"import { parseHtml } from 'h2x-core'","symbol":"parse","correct":"import { parse } from 'h2x-core'"}],"quickstart":{"code":"import { compile } from 'h2x-core';\nimport pluginJsx from 'h2x-plugin-jsx';\n\nconst html = `<div class=\"foo\">Hello</div>`;\nconst jsx = compile(html, {\n  plugins: [pluginJsx],\n  output: 'string'\n});\nconsole.log(jsx); // <div className=\"foo\">Hello</div>","lang":"typescript","description":"Demonstrates how to compile HTML to JSX using a plugin."},"warnings":[{"fix":"Update code to use new API: node.originalNode, fromHtmlAttribute, fromHtmlElement.","message":"v1.0.0: AST generation changed from a custom tree to JSDOM-based tree. You must use fromHtmlAttribute and fromHtmlElement for node replacement. originalNode property available.","severity":"breaking","affected_versions":">=1.0.0 <1.2.0"},{"fix":"Install and pass plugins: e.g., `compile(html, { plugins: [require('h2x-plugin-jsx')] })`.","message":"The package does not include any default plugin; you must provide plugins (e.g., h2x-plugin-jsx) for meaningful output.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure jsdom >=12 is installed.","message":"JSDOM v12+ required; older JSDOM versions may cause parse errors.","severity":"gotcha","affected_versions":">=1.1.0"},{"fix":"Update to v1.x API (compile, transform, parse).","message":"In v0.x, the API exported a different set of functions. Direct migration may break.","severity":"deprecated","affected_versions":"<1.0.0"}],"env_vars":null,"search_vec":"'1.1.1':37 'altern':67 'architectur':58 'ast':26 'attribut':63,66 'compil':10 'convert':20 'core':3,6,9 'current':39 'differenti':46 'everi':42 'extens':35 'h2x':2,5,12 'h2x-core':1,4 'handl':60 'html':15,21 'html-to-jsx':14 'javascript':25,74 'jsdom':29,48 'jsx':17,27 'key':45 'leverag':47 'manual':72 'month':44 'pars':51 'plugin':32,57 'releas':41 'robust':50 'special':61 'state':53 'string':22 'style':65 'support':52 'svg':62 'svgr':70 'system':33 'transform':18,73 'typic':69 'use':30 'version':36 'via':28","created_at":"2026-05-01T13:46:11.871510+00:00","updated_at":"2026-05-01T13:46:11.871510+00:00","problems":[{"fix":"Run `npm install h2x-core` and ensure import path is correct: `import { compile } from 'h2x-core'`.","cause":"h2x-core not installed or not imported correctly.","error":"Error: Cannot find module 'h2x-core'"},{"fix":"Use named import: `import { compile } from 'h2x-core'`.","cause":"Mis-imported default export vs named export.","error":"TypeError: compile is not a function"},{"fix":"Run `npm install jsdom@12`.","cause":"jsdom peer dependency not installed.","error":"Error: JSDOM is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/smooth-code/h2x","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/h2x-core","openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-05-01","next_check":"2026-07-30","install_tag":null}}