This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test/stripDataDiscoverSerializer.js | |
const isReactElement = (val) => | |
typeof val === 'object' && val !== null && 'props' in val; | |
const stripDataDiscover = (props = {}) => | |
Object.fromEntries( | |
Object.entries(props).filter(([key]) => key !== 'data-discover') | |
); | |
module.exports = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case 'table': { | |
const headers: string[] = []; | |
const rows: string[][] = []; | |
// Extract headers from <thead> or first <tr> | |
const thead = el.querySelector('thead'); | |
const headerRow = thead?.querySelector('tr') || el.querySelector('tr'); | |
if (headerRow) { | |
headerRow.querySelectorAll('th, td').forEach(cell => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case 'li': { | |
const parentTag = el.parentElement?.tagName.toLowerCase(); | |
const isOrdered = parentTag === 'ol'; | |
const isUnordered = parentTag === 'ul'; | |
// Use placeholder marker — we'll replace it in `ol` later | |
const marker = isUnordered ? '-' : '1.'; | |
// Render children with proper formatting | |
const content = convertNodeToPlainText(el).trim(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatDefinitionList(dl: HTMLElement): string { | |
const pairs: [string, HTMLElement][] = []; | |
const getDtDdPairs = (parent: Element): void => { | |
const elements = Array.from(parent.querySelectorAll('dt, dd')); | |
for (let i = 0; i < elements.length; i++) { | |
if (elements[i].tagName === 'DT' && elements[i + 1]?.tagName === 'DD') { | |
const dtText = elements[i].textContent?.trim() ?? ''; | |
const ddEl = elements[i + 1] as HTMLElement; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { useFormattedClipboard } from './useFormattedClipboard'; | |
const CopyButton: React.FC = () => { | |
const { copy, copied } = useFormattedClipboard(); | |
return ( | |
<button onClick={() => copy('#mainContent')}> | |
{copied ? 'Copied!' : 'Copy to Clipboard'} | |
</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useState } from 'react'; | |
export function useFormattedClipboard() { | |
const [copied, setCopied] = useState(false); | |
const copy = useCallback((selector: string) => { | |
const node = document.querySelector(selector); | |
if (!node) return; | |
const clonedNode = node.cloneNode(true) as HTMLElement; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require("http"); | |
const fs = require("fs"); | |
const path = require("path"); | |
const url = require("url"); | |
const port = 3000; | |
// Utility function to read files asynchronously | |
function readFile(filePath, callback) { | |
fs.readFile(filePath, "utf-8", (err, data) => { |