Skip to content

Instantly share code, notes, and snippets.

// 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 = {
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 => {
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();
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;
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>
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;
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) => {