Skip to content

Commit 700b143

Browse files
authored
Publish to JSR instead of /x (#110)
1 parent 4f1f29e commit 700b143

12 files changed

+86
-87
lines changed

.github/workflows/ci.yml

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11
name: ci
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "*"
9+
pull_request:
10+
branches:
11+
- main
412

513
jobs:
614
test:
715
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
id-token: write
819
steps:
9-
- uses: actions/checkout@master
10-
- uses: denoland/setup-deno@main
11-
with:
12-
deno-version: "1.x"
20+
- uses: actions/checkout@v4
21+
22+
- uses: denoland/setup-deno@v1
23+
1324
- name: Run fmt
1425
run: |
1526
deno fmt --check
27+
1628
- name: Run lint
1729
run: |
1830
deno lint
31+
1932
- name: Check project
2033
run: |
2134
deno task check:types
35+
2236
- name: Install Chromium
2337
run: deno run -A --unstable https://deno.land/x/[email protected]/install.ts
2438
env:
2539
PUPPETEER_PRODUCT: chrome
40+
2641
- name: Run tests
2742
run: |
2843
deno task test
44+
45+
- name: Publish package (tag only)
46+
if: startsWith(github.ref, 'refs/tags/')
47+
run: deno publish

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
cov_profile
2+
deno.lock

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CSS, syntax highlighting, and HTML sanitization.
66
## Usage
77

88
```js
9-
import { CSS, render } from "https://deno.land/x/gfm/mod.ts";
9+
import { CSS, render } from "jsr:@deno/gfm@0.6";
1010

1111
const markdown = `
1212
# Hello, world!
@@ -83,12 +83,12 @@ By default syntax highlighting for JavaScript, Markdown, and HTML is included.
8383
You can include more languages importing them:
8484

8585
```js
86-
import { CSS, render } from "https://deno.land/x/gfm/mod.ts";
86+
import { CSS, render } from "jsr:@deno/gfm@0.6";
8787

8888
// Add support for TypeScript, Bash, and Rust.
89-
import "https://esm.sh/[email protected]/components/prism-typescript?no-check";
90-
import "https://esm.sh/[email protected]/components/prism-bash?no-check";
91-
import "https://esm.sh/[email protected]/components/prism-rust?no-check";
89+
import "npm:[email protected]/components/prism-typescript.js";
90+
import "npm:[email protected]/components/prism-bash.js";
91+
import "npm:[email protected]/components/prism-rust.js";
9292
```
9393

9494
A full list of supported languages is available here:
@@ -100,7 +100,7 @@ By default, all rendering is in blocks. There are cases where one would like to
100100
render some inline markdown, and this is achievable using the `inline` setting:
101101

102102
```ts
103-
import { render } from "https://deno.land/x/gfm/mod.ts";
103+
import { render } from "jsr:@deno/gfm@0.6";
104104

105105
const markdown = "My [Deno](https://deno.land) Blog";
106106
const header = render(markdown, { inline: true });
@@ -113,7 +113,7 @@ By default math rendering is disabled. To enable it, you must include the
113113
additional CSS and enable the `allowMath` setting:
114114

115115
```ts
116-
import { CSS, KATEX_CSS, render } from "https://deno.land/x/gfm/mod.ts";
116+
import { CSS, KATEX_CSS, render } from "jsr:@deno/gfm@0.6";
117117

118118
const markdown = `
119119
Block math:

deno.json

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
{
2+
"name": "@deno/gfm",
3+
"version": "0.6.2",
4+
"exports": "./mod.ts",
5+
"imports": {
6+
"emoji": "jsr:@denosaurs/[email protected]",
7+
"marked": "npm:marked@^11.1",
8+
"github-slugger": "npm:github-slugger@^2.0",
9+
"marked-alert": "npm:marked-alert@^2.0",
10+
"marked-footnote": "npm:marked-footnote@^1.2",
11+
"marked-gfm-heading-id": "npm:marked-gfm-heading-id@^3.1",
12+
"prismjs": "npm:prismjs@^1.29",
13+
"sanitize-html": "npm:sanitize-html@^2.11",
14+
"he": "npm:he@^1.2",
15+
"katex": "npm:katex@^0.16",
16+
"@std/assert": "jsr:@std/assert@^0.214"
17+
},
18+
"compilerOptions": {
19+
"lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"]
20+
},
221
"tasks": {
322
"build": "deno run --allow-read --allow-write --allow-net --allow-run --allow-env ./style/patch.ts && deno fmt",
423
"check:types": "deno check **/*.ts",
@@ -11,6 +30,5 @@
1130
},
1231
"fmt": {
1332
"exclude": ["./test/fixtures/alerts.md", "./test/fixtures/lineBreaks.md"]
14-
},
15-
"lock": false
33+
}
1634
}

deps.ts

-26
This file was deleted.

mod.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import {
2-
emojify,
3-
gfmHeadingId,
4-
GitHubSlugger,
5-
htmlEscape,
6-
katex,
7-
Marked,
8-
markedAlert,
9-
markedFootnote,
10-
Prism,
11-
sanitizeHtml,
12-
} from "./deps.ts";
13-
import { CSS, KATEX_CLASSES, KATEX_CSS } from "./style.js";
1+
import { emojify } from "emoji";
2+
import * as Marked from "marked";
3+
import GitHubSlugger from "github-slugger";
4+
import markedAlert from "marked-alert";
5+
import markedFootnote from "marked-footnote";
6+
import { gfmHeadingId } from "marked-gfm-heading-id";
7+
import Prism from "prismjs";
8+
import sanitizeHtml from "sanitize-html";
9+
import he from "he";
10+
import katex from "katex";
11+
12+
import { CSS, KATEX_CLASSES, KATEX_CSS } from "./style.ts";
1413
export { CSS, KATEX_CSS, Marked };
1514

1615
Marked.marked.use(markedAlert());
@@ -48,11 +47,11 @@ export class Renderer extends Marked.Renderer {
4847
return `<h${level} id="${slug}"><a class="anchor" aria-hidden="true" tabindex="-1" href="#${slug}"><svg class="octicon octicon-link" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>${text}</h${level}>\n`;
4948
}
5049

51-
image(src: string, title: string | null, alt: string) {
50+
image(src: string, title: string | null, alt: string): string {
5251
return `<img src="${src}" alt="${alt}" title="${title ?? ""}" />`;
5352
}
5453

55-
code(code: string, language?: string) {
54+
code(code: string, language?: string): string {
5655
// a language of `ts, ignore` should really be `ts`
5756
// and it should be lowercase to ensure it has parity with regular github markdown
5857
language = language?.split(",")?.[0].toLocaleLowerCase();
@@ -67,13 +66,13 @@ export class Renderer extends Marked.Renderer {
6766
? Prism.languages[language]
6867
: undefined;
6968
if (grammar === undefined) {
70-
return `<pre><code class="notranslate">${htmlEscape(code)}</code></pre>`;
69+
return `<pre><code class="notranslate">${he.encode(code)}</code></pre>`;
7170
}
7271
const html = Prism.highlight(code, grammar, language!);
7372
return `<div class="highlight highlight-source-${language} notranslate"><pre>${html}</pre></div>`;
7473
}
7574

76-
link(href: string, title: string | null, text: string) {
75+
link(href: string, title: string | null, text: string): string {
7776
const titleAttr = title ? ` title="${title}"` : "";
7877
if (href.startsWith("#")) {
7978
return `<a href="${href}"${titleAttr}>${text}</a>`;

style.js style.ts

+3-5
Large diffs are not rendered by default.

style/patch.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,13 @@ for (const selector of KATEX_CSS_SELECTORS) {
8080
// de-duplicate classes
8181
classes = [...new Set(classes)];
8282

83-
$.logStep("Writing the final style.js");
84-
const CSS = await cwd.join("dist/main.css").readTextSync();
83+
$.logStep("Writing the final style.ts");
84+
const CSS = cwd.join("dist/main.css").readTextSync();
8585

86-
await cwd.join("../style.js").writeText(
87-
`/** @type {string} */
88-
export const CSS = \`${CSS}\`;
86+
await cwd.join("../style.ts").writeText(`
87+
export const CSS: string = \`${CSS}\`;
8988
90-
/** @type {string} */
91-
export const KATEX_CSS = \`${KATEX_CSS}\`;
89+
export const KATEX_CSS: string = \`${KATEX_CSS}\`;
9290
93-
export const KATEX_CLASSES = ${JSON.stringify(classes)};
94-
`,
95-
);
91+
export const KATEX_CLASSES: string[] = ${JSON.stringify(classes)};
92+
`);

test/server_test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert, assertEquals } from "./test_deps.ts";
1+
import { assert, assertEquals } from "@std/assert";
22
import { browserTest } from "./test_utils.ts";
33

44
Deno.test("basic md table with dollar signs", async () => {

test/test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { assertEquals, assertStringIncludes, DOMParser } from "./test_deps.ts";
1+
import { assertEquals, assertStringIncludes } from "@std/assert";
2+
import { DOMParser } from "https://deno.land/x/[email protected]/deno-dom-wasm.ts";
23
import { render, Renderer } from "../mod.ts";
34

45
Deno.test("Basic markdown", async () => {
@@ -242,7 +243,7 @@ Deno.test(
242243

243244
Deno.test("image title and no alt", () => {
244245
const markdown = `![](image.jpg "best title")`;
245-
const expected = `<p><img src="image.jpg" title="best title" /></p>\n`;
246+
const expected = `<p><img src="image.jpg" alt="" title="best title" /></p>\n`;
246247

247248
const html = render(markdown);
248249
assertEquals(html, expected);

test/test_deps.ts

-11
This file was deleted.

test/test_utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { Page, puppeteer } from "./test_deps.ts";
1+
import {
2+
default as puppeteer,
3+
Page,
4+
} from "https://deno.land/x/[email protected]/mod.ts";
25
import { CSS, render, RenderOptions } from "../mod.ts";
36

47
type TestCase = {

0 commit comments

Comments
 (0)