Watch
1
0
Fork
You've already forked packages
0

packages/ at markup-kit dd1e6eb5270e

A snapshot of packages/ in the Weft repository; the official packages are published from these commits.

Markup-Kit-Commit: dd1e6eb5270e62e0c8b6c202b3d01f0da6e00ddc
This commit is contained in:
Weft packages 2026-11-19 20:43:26 +00:00
commit 306b143104
72 changed files with 10915 additions and 0 deletions

54
markdown/tests/spec.weft Normal file
View file

@ -0,0 +1,54 @@
// Runs the spec's examples: `weft run tests/spec.weft [commonmark|gfm] [-v]` prints every failure and a summary.
import { args, exit } from "std/process"
import { log } from "std/log"
import { toHtml } from "../markdown"
import { COMMONMARK, GFM } from "./cases"
import type { Case } from "./cases"
/// Where the GFM spec (written against CommonMark 0.29) and CommonMark 0.31.2 give different HTML for the same text,
/// CommonMark wins: cmark-gfm's renderer folds nested `<strong>`, which CommonMark's examples keep.
fn followsCommonMark(c: Case, got: string): boolean {
return COMMONMARK.some(o => o.markdown == c.markdown && o.html == got)
}
fn runAll(name: string, cases: Case[], verbose: boolean): int {
let mut failed = 0
let mut disagreements = 0
let mut bySection = Map<string, int>()
for c of cases {
let got = toHtml(c.markdown, { gfm: c.gfm, html: "trust" })
if got != c.html && followsCommonMark(c, got) {
disagreements += 1
} else if got != c.html {
failed += 1
bySection.set(c.section, (bySection.get(c.section) ?? 0) + 1)
if verbose {
log(`--- ${name} example ${c.id} (${c.section})`)
log(`markdown: ${c.markdown}`)
log(`expected: ${c.html}`)
log(`got: ${got}`)
}
}
}
log(
`${name}: ${cases.length - failed - disagreements} of ${cases.length} pass, ${disagreements} follow CommonMark 0.31.2 where the specs disagree, ${failed} fail`,
)
for [section, n] of bySection {
log(` ${n} failing in ${section}`)
}
return failed
}
let argv = args()
let verbose = argv.includes("-v")
let only = argv.filter(a => a != "-v").at(0)
let mut failures = 0
if only == null || only == "commonmark" {
failures += runAll("CommonMark", COMMONMARK, verbose)
}
if only == null || only == "gfm" {
failures += runAll("GFM", GFM, verbose)
}
if failures > 0 {
exit(1)
}