Skip to content

Commit ee9af31

Browse files
committedOct 19, 2024··
refactor: omit https imports and use jsr
1 parent 42d4aad commit ee9af31

File tree

11 files changed

+28
-76
lines changed

11 files changed

+28
-76
lines changed
 

‎.github/demos/usage-basic/demo.gif

-493 Bytes
Loading

‎.github/demos/usage-dax/demo.gif

-409 KB
Loading

‎.github/demos/usage-dax/demo.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ $.log("your faves are:", faves);
2727
</details>
2828

2929
```ts
30-
const thisDir = $.path.dirname($.path.fromFileUrl(import.meta.url));
30+
const thisDir = $.path(import.meta.url).dirname();
3131
await $`ls ${thisDir}`.printCommand(true);
3232
```

‎.github/demos/usage-no-dax/demo.gif

-2.49 KB
Loading
-53.3 KB
Loading

‎.github/demos/usage-remote/demo.gif

3.55 KB
Loading

‎deno.jsonc

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"@std/io": "jsr:@std/io@0.225.0",
2525
"@std/path": "jsr:@std/path@1.0.6",
2626
"@std/semver": "jsr:@std/semver@1.0.3",
27-
"@std/toml": "jsr:@std/toml@1.0.1",
28-
"@x/rusty_markdown": "https://deno.land/x/rusty_markdown@v0.4.1/mod.ts"
27+
"@std/toml": "jsr:@std/toml@1.0.1"
2928
}
3029
}

‎deno.lock

+13-50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎deps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import { $ as basic$, build$, CommandBuilder } from "@david/dax";
44
import { load as parseHTML } from "@esm.sh/cheerio";
5+
import { toAst as parseMarkdown } from "@littletof/charmd";
56
import { parse as parseTOML } from "@std/toml";
6-
import { tokens as parseMarkdown } from "@x/rusty_markdown";
77

88
export { colors } from "@cliffy/ansi/colors";
99
export { Command, EnumType, ValidationError } from "@cliffy/command";

‎src/markdown.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Deno.test("mdCodeBlocks works for posix", () => {
2222
blocks.at(0)?.code,
2323
$.dedent`
2424
import mod from "file://a/b/mod.ts";
25-
console.log("hello world");\n
25+
console.log("hello world");
2626
`,
2727
);
2828
}
@@ -46,7 +46,7 @@ Deno.test("mdCodeBlocks works for windows", () => {
4646
blocks.at(0)?.code,
4747
$.dedent`
4848
import mod from "file:///D:/a/b/mod.ts";
49-
console.log("hello world");\n
49+
console.log("hello world");
5050
`,
5151
);
5252
}
@@ -85,7 +85,7 @@ Deno.test("mdCodeBlocks works for multiple blocks and block idx is accurate", ()
8585
block?.code,
8686
$.dedent`
8787
import mod from "file://a/b/mod.ts";
88-
console.log("hello world${idx}");\n
88+
console.log("hello world${idx}");
8989
`,
9090
);
9191
}
@@ -131,7 +131,7 @@ Deno.test("mdCodeBlocks works for tilde blocks and block idx works", () => {
131131
blocks.at(0)?.code,
132132
$.dedent`
133133
import mod from "file://a/b/mod.ts";
134-
console.log("hello world");\n
134+
console.log("hello world");
135135
`,
136136
);
137137
}

‎src/markdown.ts

+8-18
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,28 @@ export function mdCodeBlocks(mdContent: string, mdFileUrl: string) {
2323
const mdTokens = $.parseMarkdown(mdContent);
2424

2525
let blockIdx = 0;
26-
mdTokens.forEach((mdToken, idx) => {
26+
mdTokens.children?.forEach((mdToken, idx) => {
2727
if (
28-
mdToken.type === "start" &&
29-
mdToken.tag === "codeBlock" &&
30-
mdToken.kind === "fenced" &&
31-
supportedLanguages.includes(mdToken.language)
28+
mdToken.type === "code" &&
29+
supportedLanguages.includes(mdToken.lang)
3230
) {
3331
const block: CodeBlock = {
3432
idx: blockIdx,
35-
code: "",
33+
code: mdToken.value.trim(),
3634
summary: "",
3735
config: {},
3836
};
3937
blockIdx++;
4038

41-
let codeCursor = idx + 1;
42-
let codeCursorToken = mdTokens.at(codeCursor);
43-
while (codeCursorToken && codeCursorToken.type === "text") {
44-
block.code += codeCursorToken.content;
45-
codeCursor++;
46-
codeCursorToken = mdTokens.at(codeCursor);
47-
}
48-
49-
if (!block.code.trim().length) return;
39+
if (!block.code.length) return;
5040

5141
let configCursor = idx - 1;
52-
let configCursorToken = mdTokens.at(configCursor);
42+
let configCursorToken = mdTokens.children?.at(configCursor);
5343
let blockConfig = "";
5444
while (configCursorToken && configCursor >= 0 && configCursorToken.type === "html") {
55-
blockConfig = `${configCursorToken.content}${blockConfig}`;
45+
blockConfig = `${configCursorToken.value}${blockConfig}`;
5646
configCursor--;
57-
configCursorToken = mdTokens.at(configCursor);
47+
configCursorToken = mdTokens.children?.at(configCursor);
5848
}
5949

6050
// ode to the ol' jquery naming conventions :)

0 commit comments

Comments
 (0)
Please sign in to comment.