Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions packages/core/src/api/exporters/markdown/htmlToMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function serializeNode(node: Node, ctx: SerializeContext): string {
return serializeVideo(el, ctx);
case "audio":
return serializeAudio(el, ctx);
case "embed":
return serializeEmbed(el, ctx);
case "figure":
return serializeFigure(el, ctx);
case "a":
Expand Down Expand Up @@ -501,29 +503,33 @@ function formatSeparatorRow(colWidths: number[], colCount: number): string {
function serializeImage(el: HTMLElement, ctx: SerializeContext): string {
const src = el.getAttribute("src") || "";
const alt = el.getAttribute("alt") || "";
if (!src) {
return ctx.indent + "Add image\n\n";
}
// Empty placeholder — preserve the block-level break, matching how
// serializeParagraph/serializeHeading emit `\n\n` for empty content.
if (!src) {return "\n\n";}
return ctx.indent + `![${alt}](${src})\n\n`;
}

function serializeVideo(el: HTMLElement, ctx: SerializeContext): string {
const src =
el.getAttribute("src") || el.getAttribute("data-url") || "";
const name = el.getAttribute("data-name") || el.getAttribute("title") || "";
if (!src) {
return ctx.indent + "Add video\n\n";
}
if (!src) {return "\n\n";}
return ctx.indent + `![${name}](${src})\n\n`;
}

function serializeAudio(el: HTMLElement, ctx: SerializeContext): string {
const src = el.getAttribute("src") || "";
if (!src) {return "";}
if (!src) {return "\n\n";}
// Audio has no visible representation in markdown; output as link with empty text
return ctx.indent + `[](${src})\n\n`;
}

function serializeEmbed(el: HTMLElement, ctx: SerializeContext): string {
const src = el.getAttribute("src") || "";
if (!src) {return "\n\n";}
return ctx.indent + `[](${src})\n\n`;
}

function serializeFigure(el: HTMLElement, ctx: SerializeContext): string {
let result = "";

Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/blocks/Audio/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ export const audioToExternalHTML =
>,
) => {
if (!block.props.url) {
const div = document.createElement("p");
div.textContent = "Add audio";

return {
dom: div,
dom: document.createElement("audio"),
};
}

Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/blocks/File/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ export const createFileBlockSpec = createBlockSpec(createFileBlockConfig, {
},
toExternalHTML(block) {
if (!block.props.url) {
const div = document.createElement("p");
div.textContent = "Add file";

return {
dom: div,
dom: document.createElement("embed"),
};
}

Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/blocks/Image/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,8 @@ export const imageToExternalHTML =
>,
) => {
if (!block.props.url) {
const div = document.createElement("p");
div.textContent = "Add image";

return {
dom: div,
dom: document.createElement("img"),
};
}

Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/blocks/Video/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@ export const createVideoBlockSpec = createBlockSpec(
},
toExternalHTML(block) {
if (!block.props.url) {
const div = document.createElement("p");
div.textContent = "Add video";

return {
dom: div,
dom: document.createElement("video"),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ <h1>Heading 1</h1>
</td>
</tr>
</table>
<p>Add image</p>
<img />
<hr />
<p>Paragraph 2</p>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>Add audio</p>
<audio></audio>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>Add file</p>
<embed />
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>Add image</p>
<img />
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add audio

Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add file

Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add image

Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>Add file</p>
<embed />
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>Add image</p>
<img />
Loading