andi23rosca / solid-markdown

Render Markdown as Solid components
MIT License
106 stars 10 forks source link

Incorrect inline style for katex #29

Closed ailectra closed 5 months ago

ailectra commented 5 months ago

Hi,

When using remark-math and rehype-katex, there is a display issue. It shows the image on the right instead of the one on the left:

Sans titre3

The one on the left is displayed using katex.renderToString() directly, the one on the right uses SolidMarkdown.

The issue seems to be because the style properties are camelCase instead of kebab-case:

{
  className: 'mord mathnormal',
  style: { marginRight: '0.07153em' },
  key: 'span---0'
}
andi23rosca commented 5 months ago

yep, you're right, solid uses kebab case style properties PRs are welcome, otherwise I'll try to get to fixing it in the weekend

ailectra commented 5 months ago

Adding the following code to childProps from MarkdownNode in renderer.tsx seems to fix it:

if (properties.style) {
    properties.style = Object.entries(properties.style).reduce((acc, [key, value]) => {
        const kebabKey = key.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`)
        acc[kebabKey] = value
        return acc
    }, {} as Record<string, string>)
}

Also, maybe also changing className to class can prevent future problems:

if (properties.className) {
    properties.class = properties.className;
    delete properties.className;
}
ailectra commented 5 months ago

Ok I checked your code. The issue seems to stem from the parseStyle function in utils.ts. The style is already in kebab-case but gets turned into camelCase by this function. Removing this function entirely fixes the problem.

As for the className property, it should be changed in the addProperty function like this:

if (info.property === "className") {
    info.property = 'class'
}
andi23rosca commented 5 months ago

@ailectra just published v2.0.1 let me know if it fixed all your issues

ailectra commented 5 months ago

Yes it works perfectly now! Thank you