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

🐛 Bug Report: Techdocs SVG handling conflicts with light & dark mode #27416

Open
2 tasks done
jschwarze opened this issue Oct 31, 2024 · 1 comment
Open
2 tasks done
Labels
area:techdocs Related to the TechDocs Project Area bug Something isn't working

Comments

@jschwarze
Copy link

jschwarze commented Oct 31, 2024

📜 Description

I'm using svg images inside my techdocs. I'd like to support the light & dark mode with help of mkdocs-material.
This leads to src attributes inside my techdocs like src="some-nice-image.svg#only-dark".

No problem so far until techdocs is changing the content-type for svg into text/plain' for security reason.
But the rewrite back to svg is failing because the src attribute doesn't end with svg 😢 .

👍 Expected behavior

It would be great, if the check will respect anchors in the url, inside of addBaseUrl.ts.

Current implementation:

const isSrcToSvg = attrName === 'src' && attrVal.endsWith('.svg');

Something like this would solve the problem:

const isSrcToSvg = attrName === "src" && attrVal.replace(/#.*/, "").endsWith(".svg");

👎 Actual Behavior with Screenshots

Currently, the svg images aren't shown in the browser because the content type is wrong.

👟 Reproduction steps

  1. create a techdocs page
  2. add an image of type svg
  3. add an anchor tag '#only-light' to the image src.
  4. open the techdocs via backstage.

📃 Provide the context for the Bug.

No response

🖥️ Your Environment

I don't believe this is needed for that issue.

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Are you willing to submit PR?

Yes I am willing to submit a PR!

@jschwarze jschwarze added the bug Something isn't working label Oct 31, 2024
@github-actions github-actions bot added the area:techdocs Related to the TechDocs Project Area label Oct 31, 2024
@freben
Copy link
Member

freben commented Nov 4, 2024

Or maybe even better -

new URL(attrVal, 'https://ignored.com').pathname.endsWith('.svg')

then it'll ignore fragments, query parts etc for you, so that e.g. my-image.svg?size=small works too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:techdocs Related to the TechDocs Project Area bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants