Skip to content

Commit

Permalink
Fix: Style properties should not be camel case
Browse files Browse the repository at this point in the history
  • Loading branch information
andi23rosca committed Mar 19, 2024
1 parent 9aa6a75 commit f8a614a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solid-markdown",
"version": "2.0.0",
"version": "2.0.1",
"description": "Markdown renderer for solid-js",
"license": "MIT",
"keywords": [
Expand Down Expand Up @@ -120,4 +120,4 @@
"node": ">=18",
"pnpm": ">=8.6.0"
}
}
}
35 changes: 8 additions & 27 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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: <explanation>
Expand All @@ -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<string, string> {
const result: Record<string, string> = {};

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,
Expand Down

0 comments on commit f8a614a

Please sign in to comment.