kit icon indicating copy to clipboard operation
kit copied to clipboard

Text styling not applying to md() inside div()

Open nbbaier opened this issue 1 year ago • 3 comments

Text styles added in the second argument of div() do not apply to strings inside md(). For example, the following behaves as expected:

await div("Hello world!", "bg-blue-300 text-red-500 text-2xl p-5");

As seen in this screenshot: Screenshot 2023-04-22 at 9 27 03 PM

But this next snippet only comes out with the background color and padding, but the text is default:

await div(md(`Hello world!`), `bg-blue-300 text-red-500 text-2xl p-5`);

Screenshot:

Screenshot 2023-04-22 at 9 27 43 PM

It would be nice if we could style the text content of md() with Tailwind classes.

Also, a broader question: Are there limits on what tailwind classes can be used in the second argument of div()?

nbbaier avatar Apr 23 '23 02:04 nbbaier

Ran into this myself. I moved the tailwind classes in to the md call and it worked:

const markdown = `.......`;

await div(highlight(md(markdown, 'text-md m-6')));

While div and highlight receive container classes, they didn't apply until I set them inside the md call. I'm guessing this has to do with style isolation or simply with the style hierarchy.

It would definitely be nice if they can be applied at the top level.

shyagamzo avatar Apr 29 '23 14:04 shyagamzo

Nice catch! I just tried that and it worked great.

nbbaier avatar Apr 29 '23 16:04 nbbaier

md() applies its own set of classes. The second argument of md overrides those classes (like you already figured out).

I'm not sure it makes sense to have the div container classes override the md classes.

You can roll your own prompts/components like this:


let myMd = async markdownString => {
  return div(`
<div class="override">
<style>
@keyframes pulsing-glow {
    0% {
        text-shadow: 0 0 5px white;
    }
    50% {
        text-shadow: 0 0 20px white, 0 0 10px white;
    }
    100% {
        text-shadow: 0 0 5px white;
    }
}
.override h2 {
    color: red;
    font-size: 7rem;
    animation: pulsing-glow 2s infinite;
}

</style>
${md(markdownString)}
<div>
`)
}

await myMd(`
## Anything is Possible!
`)

CleanShot 2023-04-29 at 10 28 49

johnlindquist avatar Apr 29 '23 16:04 johnlindquist