-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add support for alt attribute on structured content images #359
Conversation
✔️ No visual differences introduced by this PR. View Playwright Report (note: open the "playwright-report" artifact) |
I just noticed that the Maybe this |
It was already in the codebase for some reason, just never in the schema, so I left it in and added it to the schema. 4da4827#diff-ce730242c96c30356b0f3b286e9d160ab920e11d878726a31b3d28a531232c98R480-R508 Since the codebase has types now, you can follow references to see how it's used: yomitan/types/ext/structured-content.d.ts Line 139 in 1ae752b
Which takes you to here: |
If I'm understanding the code correctly, it looks like the purpose of the I added a new It seems the automated tests are failing because I made changes to the test dictionary. I'm not sure how to go about fixing that. |
This relates to comment 2. in #342 (comment). I can try to resurrect this functionality so you don't have to try and manually update those files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should comment that the changes here look good, I'm just working towards getting the functionality to rebuild the test data with my recent PRs so we can fix the tests.
Now that #415 is merged, you can rebase this and run |
I'm not quite sure what this command did. I ran it and it didn't seem to change or fix anything. I looked a bit harder at the test script and noticed that the expected media file counts in |
Oh, I might have made a wrong assumption that this was affecting some of the tests that use the JSON files as input/output. If all you needed to fix CI was to fix those numbers in the test file, then that should be sufficient. |
Dictionaries imported by yomitan may contain image files. The markup attributes for the images (width, height, alignment, etc.) are defined by the term bank schema. Currently the schema supports the
title
attribute, which allows users to view textual descriptions when hovering over images. However, the similaralt
attribute is not currently supported. It would be useful if we could enable it.For example, a dictionary might want to display the kanji 𬵪 (あおさば). This kanji is not supported by many fonts, so the text form (unicode character) likely will not display correctly for most users. We can replace it with an image of the kanji to ensure that users will be able to see it. It would also be nice if the users could highlight and copy the image and get the correct unicode character on their clipboard. This is possible by setting the
alt
attribute of the image equal to𬵪
.It looks like this feature was intended to be added at some point, but the implementation was not finished. There is a
description
property defined for images within the term bank schema, but it is not used within the actual program (as far as I can see).yomitan/ext/data/schemas/dictionary-term-bank-v3-schema.json
Lines 423 to 430 in 1ae752b
The "alt" attribute is currently set for images, but it is always set to an empty string.
yomitan/ext/js/display/sandbox/structured-content-generator.js
Lines 80 to 84 in 55897b2
I updated the program to set the
alt
attribute equal to the value of thisdescription
property instead of an empty string. After doing so, I noticed that it worked as expected withauto
type (color) images, but it did not work withmonochrome
images. I found that for monochrome images, thedisplay
style on theimg
element was being set tohidden
. It appears it was designed this way to allow monochrome images to change correctly when users switch between dark and light themes (monochrome text should be dark in light mode and light in dark mode). However, images cannot be selected whendisplay
is set tohidden
, so thealt
text would not copy to the clipboard. In order to work around this problem, I replaced thedisplay: hidden
style withopacity: 0
to achieve the same effect.Everything seems to be working correctly now. I also created and tested some anki cards, and the
alt
text and monochrome functionality both carried over as expected. I'm not at all familiar with this code base so it's possible I may have overlooked something, so please take a careful look.