-
-
Notifications
You must be signed in to change notification settings - Fork 621
Fix: video parsing and Markdown export issues #1955
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
539dfa6
fix: video element parsing error
Hector-Zhuang 6c2c972
Merge branch 'main' into fix/video-parse
nperez0111 9a9f0fa
chore: update pnpm-lock
nperez0111 37b2d9e
test: add test cases
nperez0111 d647bac
Merge branch 'main' into fix/video-parse
matthewlipski 606c2c4
Updated snapshots and test setup
matthewlipski 664aedc
Minor type fix
matthewlipski 4a2bc9c
Fixed build
matthewlipski 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
19 changes: 19 additions & 0 deletions
19
packages/core/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.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,19 @@ | ||
import { Parent as HASTParent } from "hast"; | ||
import { visit } from "unist-util-visit"; | ||
|
||
// Originally, rehypeParse parses videos as links, which is incorrect. | ||
export function convertVideoToMarkdown() { | ||
return (tree: HASTParent) => { | ||
visit(tree, "element", (node, index, parent) => { | ||
if (parent && node.tagName === "video") { | ||
const src = node.properties?.src || node.properties?.["data-url"] || ""; | ||
const name = | ||
node.properties?.title || node.properties?.["data-name"] || ""; | ||
parent.children[index!] = { | ||
type: "text", | ||
value: ``, | ||
}; | ||
} | ||
}); | ||
}; | ||
} |
File renamed without changes.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
tests/src/unit/core/formatConversion/export/__snapshots__/blocknoteHTML/image.html
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,23 @@ | ||
<div class="bn-block-group" data-node-type="blockGroup"> | ||
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1"> | ||
<div class="bn-block" data-node-type="blockContainer" data-id="1"> | ||
<div | ||
class="bn-block-content" | ||
data-content-type="image" | ||
data-url="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" | ||
data-file-block="" | ||
> | ||
<div class="bn-file-block-content-wrapper" style="position: relative;"> | ||
<div class="bn-visual-media-wrapper"> | ||
<img | ||
class="bn-visual-media" | ||
src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" | ||
alt="BlockNote image" | ||
draggable="false" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
24 changes: 24 additions & 0 deletions
24
tests/src/unit/core/formatConversion/export/__snapshots__/blocknoteHTML/video.html
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,24 @@ | ||
<div class="bn-block-group" data-node-type="blockGroup"> | ||
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1"> | ||
<div class="bn-block" data-node-type="blockContainer" data-id="1"> | ||
<div | ||
class="bn-block-content" | ||
data-content-type="video" | ||
data-url="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm" | ||
data-file-block="" | ||
> | ||
<div class="bn-file-block-content-wrapper" style="position: relative;"> | ||
<div class="bn-visual-media-wrapper"> | ||
<video | ||
class="bn-visual-media" | ||
src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm" | ||
controls="" | ||
draggable="false" | ||
width="0" | ||
></video> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
5 changes: 5 additions & 0 deletions
5
tests/src/unit/core/formatConversion/export/__snapshots__/html/image.html
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,5 @@ | ||
<img | ||
src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" | ||
alt="BlockNote image" | ||
data-url="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" | ||
/> |
4 changes: 4 additions & 0 deletions
4
tests/src/unit/core/formatConversion/export/__snapshots__/html/video.html
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,4 @@ | ||
<video | ||
src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm" | ||
data-url="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm" | ||
></video> |
1 change: 1 addition & 0 deletions
1
tests/src/unit/core/formatConversion/export/__snapshots__/markdown/image.md
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 @@ | ||
 |
1 change: 1 addition & 0 deletions
1
tests/src/unit/core/formatConversion/export/__snapshots__/markdown/video.md
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 @@ | ||
 |
22 changes: 22 additions & 0 deletions
22
tests/src/unit/core/formatConversion/export/__snapshots__/nodes/image.json
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,22 @@ | ||
[ | ||
{ | ||
"attrs": { | ||
"id": "1", | ||
}, | ||
"content": [ | ||
{ | ||
"attrs": { | ||
"backgroundColor": "default", | ||
"caption": "", | ||
"name": "", | ||
"previewWidth": undefined, | ||
"showPreview": true, | ||
"textAlignment": "left", | ||
"url": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", | ||
}, | ||
"type": "image", | ||
}, | ||
], | ||
"type": "blockContainer", | ||
}, | ||
] |
22 changes: 22 additions & 0 deletions
22
tests/src/unit/core/formatConversion/export/__snapshots__/nodes/video.json
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,22 @@ | ||
[ | ||
{ | ||
"attrs": { | ||
"id": "1", | ||
}, | ||
"content": [ | ||
{ | ||
"attrs": { | ||
"backgroundColor": "default", | ||
"caption": "", | ||
"name": "", | ||
"previewWidth": undefined, | ||
"showPreview": true, | ||
"textAlignment": "left", | ||
"url": "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm", | ||
}, | ||
"type": "video", | ||
}, | ||
], | ||
"type": "blockContainer", | ||
}, | ||
] |
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
16 changes: 16 additions & 0 deletions
16
tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/image.json
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,16 @@ | ||
[ | ||
{ | ||
"children": [], | ||
"content": undefined, | ||
"id": "1", | ||
"props": { | ||
"backgroundColor": "default", | ||
"caption": "", | ||
"name": "Image", | ||
"showPreview": true, | ||
"textAlignment": "left", | ||
"url": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", | ||
}, | ||
"type": "image", | ||
}, | ||
] |
16 changes: 16 additions & 0 deletions
16
tests/src/unit/core/formatConversion/parse/__snapshots__/markdown/video.json
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,16 @@ | ||
[ | ||
{ | ||
"children": [], | ||
"content": undefined, | ||
"id": "1", | ||
"props": { | ||
"backgroundColor": "default", | ||
"caption": "", | ||
"name": "", | ||
"showPreview": true, | ||
"textAlignment": "left", | ||
"url": "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm", | ||
}, | ||
"type": "video", | ||
}, | ||
] |
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.
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.
@nperez0111 how do you feel about checking if a file is a video based on a hard coded list of file endings? The alternative would be to get it from the
meta.fileBlockAccept
field in the video block's implementation. It would be nice to use this instead of a hard coded list, but I'm wary of what happens if someone replaces the default video block with their own. Wdyt?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 think hard-coding is fine for now, this is what the markdown parser would've done anyway.