Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deconstruct class and id from style attributes on marks #132

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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