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

feat: customization of allowedClasses #85

Merged
merged 5 commits into from
Jan 16, 2024

Conversation

deer
Copy link
Contributor

@deer deer commented Jan 12, 2024

I was trying to use this with fresh's tailwind plugin, but ran into issues because tailwind expects lists to be like <ul class="list-disc"> which is not what we do here.

Fortunately #80 allows me to define a custom renderer like:

class CustomRenderer extends Renderer {
  list(body: string, ordered: boolean): string {
    const type = ordered ? "list-decimal" : "list-disc";
    const tag = ordered ? "ol" : "ul";
    return `<${tag} class="${type}">${body}</${tag}>`;
  }
}

Cool, but then the classes get purged during sanitization. So this feature allows users to invoke the render function like this:

const html = render(markdown, {
  renderer: new CustomRenderer({}),
  allowedClasses: { ul: ["list-disc"], ol: ["list-decimal"] },
});

@deer
Copy link
Contributor Author

deer commented Jan 15, 2024

@marvinhagemeister, what do you think of this approach and this PR? I see you're doing something different on the fresh www site. There you have the css hardcoded in a markdown.css file.

Copy link
Contributor

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@marvinhagemeister marvinhagemeister merged commit 055a05d into denoland:main Jan 16, 2024
1 check passed
@deer deer deleted the custom_allowed_class branch January 16, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants