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
5 changes: 4 additions & 1 deletion src/components/Layout/MarkdownStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ export const MarkdownStyles = createGlobalStyle`
word-break: break-word;
word-wrap: break-word;
}
ul {
list-style: none;
}
li > details {
display: block;
}
summary {
cursor: pointer;
margin-left: -2rem;
user-select: none;
list-style: none;
display: block;
&::marker,
&::-webkit-details-marker {
Expand Down
83 changes: 83 additions & 0 deletions src/helpers/rehypeWrapTimecodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { visit } from "unist-util-visit";
import type { Root, Element, Text, ElementContent } from "hast";

/**
* Rehype plugin that wraps timecode patterns in <code> tags.
* Looks for list items that start with `[<timecode link>]` pattern
* and wraps them in <code> tags for styling.
*
* Input: <li>[<a href="#intro">00:00</a>] Intro</li>
* Output: <li><code>[<a href="#intro">00:00</a>]</code> Intro</li>
*/
export default function rehypeWrapTimecodes() {
return (tree: Root) => {
visit(tree, "element", (node) => {
// Only process <li> elements
if (node.tagName !== "li") {
return;
}

// Check if first child is a text node starting with "["
if (node.children.length < 3) {
return;
}

const firstChild = node.children[0];
if (firstChild.type !== "text" || !firstChild.value.startsWith("[")) {
return;
}

// Check if second child is a link with a timecode pattern
const secondChild = node.children[1];
if (secondChild.type !== "element" || secondChild.tagName !== "a") {
return;
}

// Check if the link text matches timecode pattern (HH:MM:SS or MM:SS)
const linkText =
secondChild.children[0]?.type === "text"
? secondChild.children[0].value
: "";
const timecodePattern = /^\d{1,2}:\d{2}(:\d{2})?$/;
if (!timecodePattern.test(linkText)) {
return;
}

// Check if third child is a text node starting with "]"
const thirdChild = node.children[2];
if (thirdChild.type !== "text" || !thirdChild.value.startsWith("]")) {
return;
}

// Extract and modify the bracket text nodes
const openingBracket: Text = {
type: "text",
value: "[",
};

const closingBracket: Text = {
type: "text",
value: "]",
};

// Update the original text nodes to remove the brackets
const firstTextNode = firstChild as Text;
firstTextNode.value = firstTextNode.value.slice(1); // Remove leading "["

const thirdTextNode = thirdChild as Text;
thirdTextNode.value = thirdTextNode.value.slice(1); // Remove leading "]"

// Create the <code> wrapper with the timecode content
const codeElement: Element = {
type: "element",
tagName: "code",
properties: {},
children: [openingBracket, secondChild, closingBracket],
};

// Rebuild the children array
const remainingContent = node.children.slice(2);
node.children = [codeElement, ...remainingContent];
});
};
}
2 changes: 2 additions & 0 deletions src/helpers/retrieveMdPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import rehypeSlug from "rehype-slug";
import remarkHeadings, { hasHeadingsData } from "@vcarl/remark-headings";
import { toString } from "mdast-util-to-string";
import rehypeWrapFirstList from "./rehypeWrapFirstList";
import rehypeWrapTimecodes from "./rehypeWrapTimecodes";

const loadMd = async (path: string) => {
const fullPath = join(process.cwd(), `${path}.md`);
Expand Down Expand Up @@ -55,6 +56,7 @@ export const processMd = (mdSource: string, options?: ProcessMdOptions) => {
.use(remarkHeadings as ReturnType<ReturnType<typeof unified>["use"]>)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeSlug)
.use(rehypeWrapTimecodes)
.use(rehypeWrapFirstList)
.use(rehypeStringify, { allowDangerousHtml: true });
}
Expand Down
7 changes: 5 additions & 2 deletions src/pages/transcripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export default function Transcripts({
<p>
<em>Transcript from {date}</em>
</p>
<div dangerouslySetInnerHTML={{ __html: latest.html }} />
<div
className="markdown"
dangerouslySetInnerHTML={{ __html: latest.html }}
/>
</div>
</>
)}
Expand Down Expand Up @@ -68,7 +71,7 @@ export async function getStaticProps() {
title: latest.title,
description: latest.description,
date: latest.date,
html: processMd(latest.content).html,
html: processMd(latest.content, { wrapFirstList: true }).html,
},
},
};
Expand Down
374 changes: 187 additions & 187 deletions src/transcripts/ankita-kulkarni.md

Large diffs are not rendered by default.

Loading