Skip to content

Commit

Permalink
fix: deconstruct class and id from style attributes on marks
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Oct 28, 2024
1 parent ab7f47a commit ee65a01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions playground/vanilla/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ h1 {
color: #888;
}

.custom-penguin {
color: teal;
font-weight: 700;
}

button {
border-radius: 8px;
border: 1px solid transparent;
Expand Down
11 changes: 9 additions & 2 deletions src/richtext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,18 @@ export function richTextResolver<T>(options: StoryblokRichTextOptions<T> = {}) {

// Mark resolver for text formatting
const markResolver = (tag: string, styled = false): StoryblokRichTextNodeResolver<T> => ({ text, attrs }): T => {
const attributes = styled ? { style: attrsToStyle(attrs) } : attrs || {};
const { class: className, id: idName, ...styleAttrs } = attrs || {};
const attributes = styled
? {
class: className,
id: idName,
style: attrsToStyle(styleAttrs) || undefined,
}
: attrs || {};
if (keyedResolvers) {
attributes.key = `${tag}-${currentKey}`;
}
return renderFn(tag, attributes, text as any) as T;
return renderFn(tag, cleanObject(attributes), text as any) as T;
};

const renderToT = (node: any): T => {
Expand Down

0 comments on commit ee65a01

Please sign in to comment.