-
Couldn't load subscription status.
- Fork 1
feat: add altText as a data attribute to rendered span #52
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
Open
drizco
wants to merge
2
commits into
master
Choose a base branch
from
ryan/remark/feat/pass-alt-text-as-span-data-attribute
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+58
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| const test = require("tape") | ||
| const { markdownToHtml } = require("./utils") | ||
| const expandableImages = require("../src/expandableImages") | ||
|
|
||
| test("plain images are not converted to span with data attributes", (t) => { | ||
| t.plan(1) | ||
| const markdown = "" | ||
| const expected = '<p><img src="https://example.com/image.png" alt="plain image"></p>' | ||
|
|
||
| const rendered = markdownToHtml(markdown, expandableImages) | ||
| t.equal(rendered, expected) | ||
| }) | ||
|
|
||
| test("expandable images are converted to span with data attributes", (t) => { | ||
| t.plan(1) | ||
| const markdown = "Check out this cool  dog!" | ||
| const expected = | ||
| '<p>Check out this cool <span data-url="https://example.com/image.png" data-alt="" class="expandable-image"></span> dog!</p>' | ||
|
|
||
| const rendered = markdownToHtml(markdown, expandableImages) | ||
| t.equal(rendered, expected) | ||
| }) | ||
|
|
||
| test("expandable image with alt text are converted to span with data attributes", (t) => { | ||
| t.plan(1) | ||
| const markdown = | ||
| "Check out this cool  dog!" | ||
| const expected = | ||
| '<p>Check out this cool <span data-url="https://example.com/image.png" data-alt="image of a dog" class="expandable-image">image of a dog</span> dog!</p>' | ||
|
|
||
| const rendered = markdownToHtml(markdown, expandableImages) | ||
| t.equal(rendered, expected) | ||
| }) | ||
|
|
||
| test("'expandable' anywhere but the end of the alt text does not make it expandable", (t) => { | ||
| t.plan(1) | ||
| const markdown = "" | ||
| const expected = | ||
| '<p><img src="https://example.com/image.png" alt="expandable image"></p>' | ||
|
|
||
| const rendered = markdownToHtml(markdown, expandableImages) | ||
| t.equal(rendered, expected) | ||
| }) | ||
|
|
||
| test("'expandable' flag at the end of the alt text handles 'expandable' elsewhere in the alt text", (t) => { | ||
| t.plan(1) | ||
| const markdown = | ||
| "Check out this cool  dog!" | ||
| const expected = | ||
| '<p>Check out this cool <span data-url="https://example.com/image.png" data-alt="expandable image of a dog" class="expandable-image">expandable image of a dog</span> dog!</p>' | ||
|
|
||
| const rendered = markdownToHtml(markdown, expandableImages) | ||
| t.equal(rendered, expected) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ schema.attributes.img.push('height', 'width'); | |
|
|
||
| // Add support for expandableImages | ||
| schema.tagNames.push('span'); | ||
| schema.attributes.span = ['dataUrl', 'className']; | ||
| schema.attributes.span = ['dataUrl', 'dataAlt', 'className']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you'll also want to apply this change here over in the main repo PR |
||
|
|
||
| // Add support for inline styles (gross) | ||
| // TODO replace all inline styles in our curriculum content with | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
FWIW, although this implementation is definitely easier to read than what we had before, the original implementation is approximately 50 times faster than this one (according to a quick https://jsbench.me/ test).
Because this is a low-level utility which is distributed without transpilation of any kind, little optimizations like this can end up mattering a lot more than they would in our primary codebase; I think we want to preserve the original. Might also be worth adding a comment explicitly calling out why we're prioritizing performance over readability here!