Skip to content

Commit

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

export type BreakNode = {
type: "break";
Expand Down Expand Up @@ -70,3 +71,9 @@ export type ImageNode = {
title: string | null;
alt: string | null;
};

export type ImageReferenceNode = {
type: "image-reference";
alt: string | null;
reference: "full" | "shortcut" | "collapsed";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ImageReference } from "mdast";
import type { ImageReferenceNode } from "../ast";

export const mapImageReference: (node: ImageReference) => ImageReferenceNode = (
node,
) => ({
type: "image-reference",
reference: node.referenceType,
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 { mapImageReference } from "./image-reference/image-reference";
import { mapImage } from "./image/image";
import { mapParagraph } from "./paragraph/paragraph";
import { mapStrong } from "./strong/strong";
Expand Down Expand Up @@ -43,6 +44,9 @@ export const mapNode: (node: RootContent) => Node = (node) => {
case "image": {
return mapImage(node);
}
case "imageReference": {
return mapImageReference(node);
}
default: {
console.log(node);
throw new Error("TODO: Implement");
Expand Down

0 comments on commit df76eb7

Please sign in to comment.