Skip to content

Commit

Permalink
fix: meta should not be removed by rehypeFernCode inside CodeBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Mar 26, 2024
1 parent 4bad116 commit 1299723
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/ui/app/src/mdx/plugins/rehypeFernCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export function rehypeFernCode(): (tree: Root) => void {
}

if (isBlockCode(node) && node.data?.visited !== true) {
node.data = { visited: true };
if (node.data == null) {
node.data = {};
}
node.data.visited = true;
const head = node.children.filter(isElement).find((child) => child.tagName === "code");
if (head != null) {
const code = getCode(head);
Expand Down Expand Up @@ -131,7 +134,10 @@ function visitCodeBlockNodes(nodeToVisit: MdxJsxFlowElementHast) {
const title = jsxAttributes.find((attr) => attr.name === "title");
visit(node, "element", (child) => {
if (child.tagName === "code" && child.data?.visited !== true) {
child.data = { visited: true };
if (child.data == null) {
child.data = {};
}
child.data.visited = true;
const code = getCode(child);
const meta = parseBlockMetaString(child, "plaintext");
if (code != null) {
Expand All @@ -157,7 +163,10 @@ function visitCodeBlockNodes(nodeToVisit: MdxJsxFlowElementHast) {

visit(nodeToVisit, "element", (child) => {
if (child.tagName === "code" && child.data?.visited !== true) {
child.data = { visited: true };
if (child.data == null) {
child.data = {};
}
child.data.visited = true;
const code = getCode(child);
const meta = parseBlockMetaString(child, "plaintext");
if (code != null) {
Expand Down Expand Up @@ -212,6 +221,7 @@ function maybeParseInt(str: string | null | undefined): number | undefined {

export function parseBlockMetaString(element: Element, defaultFallback: string): FernCodeMeta {
let meta: string = unknownToString(element.data?.meta ?? element.properties?.metastring ?? "");
console.log(meta);

Check failure on line 224 in packages/ui/app/src/mdx/plugins/rehypeFernCode.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

const titleMatch = meta.match(/title="([^"]*)"/);
const title = titleMatch?.[1];
Expand Down

0 comments on commit 1299723

Please sign in to comment.