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: remove preprocessor-specific attributes #653

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dummdidumm
Copy link
Member

  • global for style tags
  • src for script/style tags

fixes #652

@dominikg does this fix the v-p-s issue?

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR relates to an outstanding issue, so please reference it in your PR, or create an explanatory one for discussion. In many cases features are absent for a reason.
  • This message body should clearly illustrate what problems it solves. If there are related issues, remember to reference them.
  • Ideally, include a test that fails without this PR but passes with it. PRs will only be merged once they pass CI. (Remember to run pnpm lint!)

Tests

  • Run the tests with npm test or pnpm test

- global for style tags
- src for script/style tags

fixes #652
@@ -123,8 +123,9 @@ export default {
/** Add a custom language preprocessor */
potatoLanguage({ content, filename, attributes }) {
const { code, map } = require('potato-language').render(content);
const { src, ...cleanedAttributes } = attributes;
Copy link
Member

Choose a reason for hiding this comment

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

this example does not make sense as i assume potato-language uses the lang attribute value.

If you want to show it here, the preprocessor would have to use a custom potato attribute that then gets filtered

@@ -67,3 +67,9 @@ export const getTagInfo = async ({
markup,
};
};

export const removeSrcAttribute = (attributes: Record<string, any>) => {
Copy link
Member

@dominikg dominikg Aug 28, 2024

Choose a reason for hiding this comment

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

should this be a generic util?

export const filterAttributes(attributes: Record<string,any>, filterFn: (a:string) => boolean) {
  return Object.fromEntries(Object.entries(attributes).filter(([a])=>filterFn(a)))
}

usage:

const cleanAttributes = filterAttributes(attributes, a => a !=='src');
// or
const attributesToRemove = ['foo','bar'];
const cleanMultipleAttributes = filterAttributes(attributes, a => !attributesToRemove.includes(a))

that can be reused for global and potentially others?

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.

svelte5 - custom attributes like src must be removed from tag when preprocessing them
2 participants