Repository navigation
fix: export a file block with a caption as a figure #3401
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
Draft
YousefED
wants to merge
3
commits into
fix/file-block-html-export
from
fix/file-block-caption-figure
+336
−141
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3466e1d
fix(core): a file block with a caption stays one block in external HTML
YousefED 68b92b1
fix(react): a React file block with a caption stays one block in exte…
YousefED b2ab47f
fix(core): a figure caption with a line feed stays one figure in mark…
YousefED 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
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
37 changes: 37 additions & 0 deletions
37
packages/core/src/blocks/File/helpers/parse/parseLinkFigure.ts
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,37 @@ | ||
| import { parseFigureElement } from "./parseFigureElement.js"; | ||
|
|
||
| /** | ||
| * Reads the figure that `createLinkWithCaption` writes: a link to the file, | ||
| * then a caption, each with only text in it, and no other content. Each other | ||
| * figure gives `undefined`. A figure without a caption is one of these: the | ||
| * export without a caption is a link in a paragraph, which is not a file | ||
| * block. | ||
| */ | ||
| export function parseLinkFigure(figure: HTMLElement) { | ||
| const parsedFigure = parseFigureElement(figure, "a"); | ||
| const url = parsedFigure?.targetElement.getAttribute("href"); | ||
| if ( | ||
| !parsedFigure?.caption || | ||
| !url || | ||
| figure.children.length !== 2 || | ||
| figure.lastElementChild?.tagName !== "FIGCAPTION" || | ||
| // An element in the link or in the caption. | ||
| figure.querySelector(":scope > * > *") || | ||
| // Text next to them. White space and comments do not count. | ||
| Array.from(figure.childNodes).some( | ||
| (node) => | ||
| node.nodeType === 3 /* Node.TEXT_NODE */ && node.textContent?.trim(), | ||
| ) | ||
| ) { | ||
| return undefined; | ||
| } | ||
|
|
||
| // The export writes the URL as the link text of a block without a name. | ||
| const name = parsedFigure.targetElement.textContent.trim(); | ||
|
|
||
| return { | ||
| url, | ||
| name: name === url ? "" : name, | ||
| caption: parsedFigure.caption, | ||
| }; | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.