OOKNET                             [ /  search the index  ]  
──────────────────────────────────────────────────────────────────────────────────────
══════════════════════════════════════════════════════════════════════════════════════
OOKNET   [ /  search  ]  
────────────────────────────────────────────────
════════════════════════════════════════════════
 
 
master @ 60 LINES
 
[ HISTORY ]  [ UP ]
 

import { describe, expect, it } from "vitest";
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkGfm from "remark-gfm";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import { renderMarkdown } from "./markdown";
import { rehypeAscii } from "./rehype-ascii";

const cols = Array.from({ length: 12 }, (_, i) => `c${i + 1}`);
const wideTable = [
  "# title",
  "",
  `| ${cols.join(" | ")} |`,
  `| ${cols.map(() => "---").join(" | ")} |`,
  `| ${cols.join(" | ")} |`,
].join("\n");

describe("renderMarkdown", () => {
  it("renders gfm with the ascii chrome", () => {
    const html = renderMarkdown("# hi\n\n| a | b |\n| --- | --- |\n| 1 | 2 |\n");
    expect(html).toContain("head-rule");
    expect(html).toContain("table-frame");
  });

  it("transliterates foreign glyphs before the grid checks", () => {
    expect(renderMarkdown("a - b")).toContain("a - b");
  });

  it("degrades a too-wide table per width, keeps the rest rich", () => {
    // 12 short columns fit the wide frame but not the narrow one:
    // desktop keeps the rich table, mobile transposes to k/v blocks
    const html = renderMarkdown(wideTable);
    expect(html).toContain("head-rule");
    expect(html).toMatch(/table-frame frame-wide/);
    expect(html).toMatch(/table-frame frame-narrow/);
    expect(html).not.toContain("code-block");
    expect(html).toContain("sr-only");
  });

  it("degrades an oversized diagram fence to a code frame", () => {
    const html = renderMarkdown("```diagram\n" + "x".repeat(100) + "\n```\n");
    expect(html).toContain("code-block");
    expect(html).not.toContain("diagram-art");
  });
});

describe("rehypeAscii strict", () => {
  const strict = unified()
    .use(remarkParse)
    .use(remarkGfm)
    .use(remarkRehype)
    .use(rehypeAscii)
    .use(rehypeStringify);

  it("still throws on grid-defeating tables", () => {
    expect(() => strict.processSync(wideTable)).toThrow();
  });
});

import { describe, expect, it } from "vitest
";
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkGfm from "remark-gfm";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringif
y";
import { renderMarkdown } from "./markdown";
import { rehypeAscii } from "./rehype-ascii"
;

const cols = Array.from({ length: 12 }, (_, 
i) => `c${i + 1}`);
const wideTable = [
  "# title",
  "",
  `| ${cols.join(" | ")} |`,
  `| ${cols.map(() => "---").join(" | ")} |`
,
  `| ${cols.join(" | ")} |`,
].join("\n");

describe("renderMarkdown", () => {
  it("renders gfm with the ascii chrome", ()
 => {
    const html = renderMarkdown("# hi\n\n| a
 | b |\n| --- | --- |\n| 1 | 2 |\n");
    expect(html).toContain("head-rule");
    expect(html).toContain("table-frame");
  });

  it("transliterates foreign glyphs before t
he grid checks", () => {
    expect(renderMarkdown("a - b")).toContai
n("a - b");
  });

  it("degrades a too-wide table per width, k
eeps the rest rich", () => {
    // 12 short columns fit the wide frame b
ut not the narrow one:
    // desktop keeps the rich table, mobile 
transposes to k/v blocks
    const html = renderMarkdown(wideTable);
    expect(html).toContain("head-rule");
    expect(html).toMatch(/table-frame frame-
wide/);
    expect(html).toMatch(/table-frame frame-
narrow/);
    expect(html).not.toContain("code-block")
;
    expect(html).toContain("sr-only");
  });

  it("degrades an oversized diagram fence to
 a code frame", () => {
    const html = renderMarkdown("```diagram\
n" + "x".repeat(100) + "\n```\n");
    expect(html).toContain("code-block");
    expect(html).not.toContain("diagram-art"
);
  });
});

describe("rehypeAscii strict", () => {
  const strict = unified()
    .use(remarkParse)
    .use(remarkGfm)
    .use(remarkRehype)
    .use(rehypeAscii)
    .use(rehypeStringify);

  it("still throws on grid-defeating tables"
, () => {
    expect(() => strict.processSync(wideTabl
e)).toThrow();
  });
});
 
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET