diff --git a/Cargo.lock b/Cargo.lock index 4b54627..4eb985e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,42 +3,35 @@ version = 4 [[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "autocfg" -version = "1.4.0" +name = "bumpalo" +version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" [[package]] -name = "bumpalo" -version = "3.17.0" +name = "caseless" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +checksum = "8b6fd507454086c8edfd769ca6ada439193cdb209c7681712ef6275cccbfe5d8" +dependencies = [ + "unicode-normalization", +] [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "comrak" -version = "0.17.0" +version = "0.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b9638d96f93f8bf7b050f7505ba0d82b8267f601965b08faa0eb4882a9bba9" +checksum = "5ccfd7678fba9aff54a74a70352d952b345e568823ed9d5a92ebc8ad0adad8ea" dependencies = [ + "caseless", "entities", "memchr", - "once_cell", - "regex", "slug", "typed-arena", "unicode_categories", @@ -46,7 +39,7 @@ dependencies = [ [[package]] name = "comrak-wasm" -version = "0.4.2" +version = "0.4.4" dependencies = [ "bumpalo", "comrak", @@ -59,9 +52,9 @@ dependencies = [ [[package]] name = "deunicode" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc55fe0d1f6c107595572ec8b107c0999bb1a2e0b75e37429a4fb0d6474a0e7d" +checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04" [[package]] name = "entities" @@ -81,19 +74,18 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.12" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" dependencies = [ - "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.26" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "lol_alloc" @@ -106,68 +98,39 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "once_cell" -version = "1.21.1" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" dependencies = [ "proc-macro2", ] -[[package]] -name = "regex" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" - [[package]] name = "rustversion" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "scopeguard" @@ -227,15 +190,30 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.100" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "typed-arena" version = "2.0.2" @@ -244,9 +222,18 @@ checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] [[package]] name = "unicode_categories" diff --git a/Cargo.toml b/Cargo.toml index 685e33b..40911ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ mt = ["alloc"] [dependencies] - comrak = { version = "=0.17.0", default-features = false } + comrak = { version = "=0.43.0", default-features = false } js-sys = "=0.3.77" serde = { version = "=1.0.219", features = ["derive"] } wasm-bindgen = { version = "=0.2.100", features = [] } diff --git a/mod.ts b/mod.ts index 187750b..3451b49 100644 --- a/mod.ts +++ b/mod.ts @@ -1,5 +1,5 @@ // @ts-types="./lib/comrak_wasm.d.ts" -import { markdown_to_html, type Options } from "./lib/comrak_wasm.js"; +import { markdown_to_html } from "./lib/comrak_wasm.js"; /** * Options for the {@linkcode markdownToHTML} function. @@ -21,9 +21,10 @@ export interface ComrakExtensionOptions { * * ```ts * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; * - * markdownToHTML("Hello www.github.com.\n", { extension: { autolink: true } }); - * // "
Hello www.github.com.
\n" + * const html = markdownToHTML("Hello www.github.com.\n", { extension: { autolink: true } }); + * assert.equal(html, "Hello www.github.com.
\n"); * ``` * * @default {false} @@ -37,9 +38,10 @@ export interface ComrakExtensionOptions { * * ```ts * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; * - * markdownToHTML("Term\n\n: Definition", { extension: { descriptionLists: true } }); - * // "Definition
\nDefinition
\nHi1.
\nA greeting. ↩
\nHi1.
\nA greeting. ↩
\nText
\n" + * const html = markdownToHTML("---\nlayout: post\n---\nText\n", { extension: { frontMatterDelimiter: "---" } }); + * assert.equal(html, "Text
\n"); * ``` * * @default {null} @@ -85,9 +89,10 @@ export interface ComrakExtensionOptions { * * ```ts * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; * - * markdownToHTML("# README\n", { extension: { headerIDs: "user-content-" } }); - * // "Hello world there.
Hello world there.
e = mc2.
\n" + * const html = markdownToHTML("e = mc^2^.\n", { extension: { superscript: true } }); + * assert.equal(html, "e = mc2.
\n"); * ``` * * @default {false} @@ -128,10 +135,10 @@ export interface ComrakExtensionOptions { * * ```ts * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; * - * markdownToHTML("| a | b |\n|---|---|\n| c | d |\n", { extension: { table: true } }); - * // "| a | \nb | \n
|---|---|
| c | \nd | \n
| a | \nb | \n
|---|---|
| c | \nd | \n
Hello <xmp>.
\n<xmp>\n" + * const html = markdownToHTML("HelloHello <xmp>.
\n<xmp>\n"); * ``` * * @default {false} @@ -161,15 +169,164 @@ export interface ComrakExtensionOptions { * * ```ts * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; * - * markdownToHTML("* [x] Done\n* [ ] Not done\n", { extension: { tasklist: true } }); - * // "\n\n"); + * ``` + * + * @default {false} + */ + multilineBlockQuotes?: boolean; + + /** Enables GitHub style alerts. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("> [!note]\n> Something of note", { extension: { alerts: true } }); + * assert.equal(html, "paragraph
\n
Note
\nSomething of note
\n1 + 2 and x = y
\n"); + * ``` + * + * @default {false} + */ + mathDollars?: boolean; + + /** Enables math using code syntax. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("$`1 + 2`$", { extension: { mathCode: true } }); + * assert.equal(html, "1 + 2
underlined text
\n"); + * ``` + * + * @default {false} + */ + underline?: boolean; + + /** Enables subscript text using single tildes. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("H~2~O", { extension: { subscript: true } }); + * assert.equal(html, "H2O
\n"); + * ``` + * + * @default {false} + */ + subscript?: boolean; + + /** Enables spoilers using double vertical bars. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("Darth Vader is ||Luke's father||", { extension: { spoiler: true } }); + * assert.equal(html, "Darth Vader is Luke's father
\n"); + * ``` + * + * @default {false} + */ + spoiler?: boolean; + + /** Requires at least one space after a `>` character to generate a blockquote. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML(">implying implications", { extension: { greentext: true } }); + * assert.equal(html, ">implying implications
\n"); + * ``` + * + * @default {false} + */ + greentext?: boolean; + + /** Recognizes many emphasis that appear in CJK contexts. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("**この文は重要です。**但这句话并不重要。", { extension: { cjkFriendlyEmphasis: true } }); + * assert.equal(html, "この文は重要です。但这句话并不重要。
\n"); + * ``` + * + * @default {false} + */ + cjkFriendlyEmphasis?: boolean; } /** Options for parser functions. */ @@ -179,12 +336,13 @@ export interface ComrakParseOptions { * * ```ts * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; * - * markdownToHTML("\`\`\`\nfn hello();\n\`\`\`\n"); - * // "fn hello();\n\n"
+ * let html = markdownToHTML("\`\`\`\nfn hello();\n\`\`\`\n");
+ * assert.equal(html, "fn hello();\n\n");
*
- * markdownToHTML("\`\`\`\nfn hello();\n\`\`\`\n", { parse: { defaultInfoString: "rust" } });
- * // "fn hello();\n\n"
+ * html = markdownToHTML("\`\`\`\nfn hello();\n\`\`\`\n", { parse: { defaultInfoString: "rust" } });
+ * assert.equal(html, "fn hello();\n\n");
* ```
*
* @default {null}
@@ -194,14 +352,17 @@ export interface ComrakParseOptions {
/** Punctuation (quotes, full-stops and hyphens) are converted into ‘smart’
* punctuation.
*
+ *
* ```ts
* import { markdownToHTML } from "@nick/comrak";
+ * import assert from "node:assert";
*
- * markdownToHTML("'Hello,' \"world\" ...");
- * // "'Hello,' "world" ...
\n" + * let html = markdownToHTML("'Hello,' \"world\" ..."); + * assert.equal(html, "'Hello,' \"world\" ...
\n"); * - * markdownToHTML("'Hello,' \"world\" ...", { parse: { smart: true } }); - * // "‘Hello,’ “world” …
\n" + * html = markdownToHTML("'Hello,' \"world\" ...", { parse: { smart: true } }); + * assert.equal(html, "'Hello,' "world" …
\n"); + * ``` * ``` * * @default {false} @@ -215,6 +376,21 @@ export interface ComrakParseOptions { * @default {false} */ relaxedTasklistMatching?: boolean; + + /** Relax parsing of autolinks, allow links to be detected inside brackets + * and allow all url schemes. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("[https://foo.com]", { extension: { autolink: true }, parse: { relaxedAutolinks: true } }); + * assert.equal(html, "\n"); + * ``` + * + * @default {false} + */ + relaxedAutolinks?: boolean; } /** @@ -225,12 +401,13 @@ export interface ComrakRenderOptions { * * ```ts * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; * - * markdownToHTML("italic text"); - * // "italic text
\n" + * let html = markdownToHTML("italic text"); + * assert.equal(html, "italic text
\n"); * - * markdownToHTML("italic text", { render: { escape: true } }); - * // "<i>italic text</i>
\n" + * html = markdownToHTML("italic text", { render: { escape: true } }); + * assert.equal(html, "<i>italic text</i>
\n"); * ``` * * @default {false} @@ -242,12 +419,13 @@ export interface ComrakRenderOptions { * * ```ts * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; * - * markdownToHTML("\`\`\`rust\nfn hello();\n\`\`\`\n"); - * // "fn hello();\n\n"
+ * let html = markdownToHTML("\`\`\`rust\nfn hello();\n\`\`\`\n");
+ * assert.equal(html, "fn hello();\n\n");
*
- * markdownToHTML("\`\`\`rust\nfn hello();\n\`\`\`\n", { render: { githubPreLang: true } });
- * // "fn hello();\n\n"
+ * html = markdownToHTML("\`\`\`rust\nfn hello();\n\`\`\`\n", { render: { githubPreLang: true } });
+ * assert.equal(html, "fn hello();\n\n");
* ```
*
* @default {false}
@@ -259,12 +437,13 @@ export interface ComrakRenderOptions {
*
* ```ts
* import { markdownToHTML } from "@nick/comrak";
+ * import assert from "node:assert";
*
- * markdownToHTML("Hello.\nWorld.\n");
- * // "Hello.\nWorld.
\n" + * let html = markdownToHTML("Hello.\nWorld.\n"); + * assert.equal(html, "Hello.\nWorld.
\n"); * - * markdownToHTML("Hello.\nWorld.\n", { render: { hardbreaks: true } }); - * // "Hello.
\nWorld.
Hello.
\nWorld.
fn hello();\n\n"
+ * let html = markdownToHTML("\`\`\`rust extra info\nfn hello();\n\`\`\`\n");
+ * assert.equal(html, "fn hello();\n\n");
*
- * markdownToHTML("\`\`\`rust extra info\nfn hello();\n\`\`\`\n", { render: { fullInfoString: true } });
- * // "fn hello();\n\n"
+ * html = markdownToHTML("\`\`\`rust extra info\nfn hello();\n\`\`\`\n", { render: { fullInfoString: true } });
+ * assert.equal(html, "fn hello();\n\n");
* ```
*
* @default {false}
@@ -327,14 +507,131 @@ export interface ComrakRenderOptions {
*
* ```ts
* import { markdownToHTML } from "@nick/comrak";
+ * import assert from "node:assert";
*
- * markdownToHTML("* Item\n* Item\n", { render: { listStyle: "star" } });
- * // "Hello world!
\n"); + * ``` + * + * @default {false} + */ + sourcepos?: boolean; + + /** Wrap escaped characters in a `` to allow any post-processing to recognize them. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("Notify user \\@example", { render: { escapedCharSpans: true } }); + * assert.equal(html, "Notify user @example
\n"); + * ``` + * + * @default {false} + */ + escapedCharSpans?: boolean; + + /** Ignore setext headings in input. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("setext heading\n---", { render: { ignoreSetext: true } }); + * assert.equal(html, "setext heading
\n[]()
\n"); + * ``` + * + * @default {false} + */ + ignoreEmptyLinks?: boolean; + + /** Enables GFM quirks in HTML output which break CommonMark compatibility. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("****abcd****", { render: { gfmQuirks: true } }); + * assert.equal(html, "abcd
\n"); + * ``` + * + * @default {false} + */ + gfmQuirks?: boolean; + + /** Prefer fenced code blocks when outputting CommonMark. + * + * @default {false} + */ + preferFenced?: boolean; + + /** Render the image as a figure element with the title as its caption. + * + * ```ts + * import { markdownToHTML } from "@nick/comrak"; + * import assert from "node:assert"; + * + * const html = markdownToHTML("", { render: { figureWithCaption: true } }); + * assert.equal(html, "