Skip to content

Commit

Permalink
Implement the image node mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek committed May 10, 2024
1 parent 2b50157 commit a520201
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/modules/markdown-parser/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export type Node =
| DeleteNode
| StrongNode
| FootnoteReferenceNode
| HtmlNode;
| HtmlNode
| ImageNode;

export type BreakNode = {
type: "break";
Expand Down Expand Up @@ -62,3 +63,10 @@ export type HtmlNode = {
type: "html";
html: string;
};

export type ImageNode = {
type: "image";
url: string;
title: string | null;
alt: string | null;
};
9 changes: 9 additions & 0 deletions packages/modules/markdown-parser/src/image/image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Image } from "mdast";
import type { ImageNode } from "../ast";

export const mapImage: (node: Image) => ImageNode = (node) => ({
type: "image",
url: node.url,
title: node.title ?? null,
alt: node.alt ?? null,
});
4 changes: 4 additions & 0 deletions packages/modules/markdown-parser/src/mapNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { mapDelete } from "./delete/delete";
import { mapEmphasis } from "./emphasis/empasis";
import { mapFootnoteReference } from "./footnote-reference/footnote-reference";
import { mapHtml } from "./html/html";
import { mapImage } from "./image/image";
import { mapParagraph } from "./paragraph/paragraph";
import { mapStrong } from "./strong/strong";
import { mapText } from "./text/text";
Expand Down Expand Up @@ -39,6 +40,9 @@ export const mapNode: (node: RootContent) => Node = (node) => {
case "html": {
return mapHtml(node);
}
case "image": {
return mapImage(node);
}
default: {
console.log(node);
throw new Error("TODO: Implement");
Expand Down

0 comments on commit a520201

Please sign in to comment.