From f8a614a00ac5117e4815c9ed5104e98dad688763 Mon Sep 17 00:00:00 2001 From: Andi Rosca Date: Tue, 19 Mar 2024 20:01:55 +0100 Subject: [PATCH] Fix: Style properties should not be camel case --- package.json | 4 ++-- src/utils.ts | 35 ++++++++--------------------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 1b83e37..2514f17 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solid-markdown", - "version": "2.0.0", + "version": "2.0.1", "description": "Markdown renderer for solid-js", "license": "MIT", "keywords": [ @@ -120,4 +120,4 @@ "node": ">=18", "pnpm": ">=8.6.0" } -} \ No newline at end of file +} diff --git a/src/utils.ts b/src/utils.ts index 373d7d1..17b357c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,7 +2,6 @@ import { stringify as commas } from "comma-separated-tokens"; import type { Root, Element } from "hast"; import { find } from "property-information"; import { stringify as spaces } from "space-separated-tokens"; -import style from "style-to-object"; import { Position } from "unist"; import { Context } from "./types"; @@ -42,6 +41,11 @@ export function addProperty( const info = find(ctx.schema, prop); let result = value; + + if (info.property === "className") { + info.property = 'class' + } + // Ignore nullish and `NaN` values. // eslint-disable-next-line no-self-compare // biome-ignore lint/suspicious/noSelfCompare: @@ -55,42 +59,19 @@ export function addProperty( result = info.commaSeparated ? commas(result) : spaces(result); } - if (info.property === "style" && typeof result === "string") { - result = parseStyle(result); - } - if (info.space && info.property) { props[info.property] = result; } else if (info.attribute) { props[info.attribute] = result; } } -function parseStyle(value: string): Record { - const result: Record = {}; - - try { - style(value, iterator); - } catch { - // Silent. - } - - return result; - - function iterator(name: string, v: string) { - const k = name.slice(0, 4) === "-ms-" ? `ms-${name.slice(4)}` : name; - result[k.replace(/-([a-z])/g, styleReplacer)] = v; - } -} -function styleReplacer(_: unknown, $1: string) { - return $1.toUpperCase(); -} export function flattenPosition( pos: | Position | { - start: { line: null; column: null; offset: null }; - end: { line: null; column: null; offset: null }; - }, + start: { line: null; column: null; offset: null }; + end: { line: null; column: null; offset: null }; + }, ): string { return [ pos.start.line,