Skip to content

Commit ec41b16

Browse files
authored
Chore: Rework codebase, prepare for next release (#10)
* refactor: change how table is assembled * feature: Add lineWidth option, add docs for options * chore: refactor docs snapper * fix: readd try-catch in thematicBreak * fmt * refactor for better fmt * chore: update Readme, add NodePosition type * feat: add start of proper node types * feat: Add node types * refactor: typeings * chore Update CI deno version
1 parent 5336921 commit ec41b16

19 files changed

+795
-599
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Install deno
2929
uses: denolib/setup-deno@master
3030
with:
31-
deno-version: 1.24.0
31+
deno-version: 1.42.4
3232

3333
- name: Running tests
3434
if: matrix.config.kind == 'test'

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
.vscode
2-
eggs-debug.log
2+
cov
3+
4+
TODO.md
5+
test/tableTest.md
6+
test/listest.md

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ Feedback and contributions are always welcome. Open an issue or a PR, or contact
123123
- [x] fix lists
124124
- [x] remove dots from codeblock backgrounds
125125
- [x] links with images
126-
- [x] ```# Header with *italic*```
126+
- [x] `# Header with *italic*`
127127
- [x] strikethrough, ~~underline~~
128128
- [x] basic tests
129129
- [x] lint
130-
- [ ] fmt
130+
- [x] fmt
131131
- [ ] Look into alternatives for the AST generation.

cli.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import {renderMarkdown} from './mod.ts';
1+
import { renderMarkdown } from "./mod.ts";
22

3-
if(!Deno.args) {
4-
throw Error('Please provide a path or url to a file or a markdown string');
3+
if (!Deno.args) {
4+
throw Error("Please provide a path or url to a file or a markdown string");
55
} else {
6-
if(!Deno.args[0] || !Deno.args[1]) {
7-
throw Error("Please provide -l, -r and a path, or -s and a markdown string as arguments");
8-
}
6+
if (!Deno.args[0] || !Deno.args[1]) {
7+
throw Error("Please provide -l, -r and a path, or -s and a markdown string as arguments");
8+
}
99

10-
let text;
11-
switch(Deno.args[0]) {
12-
case '-l':
13-
text = Deno.readTextFileSync(Deno.args[1]);
14-
break;
15-
case '-r': {
16-
const resp = await fetch(Deno.args[1]);
17-
text = await resp.text();
18-
break;
19-
}
20-
case '-s':
21-
text = Deno.args[1];
22-
break;
23-
default:
24-
throw Error('Only -l, -r and -s is allowed');
10+
let text;
11+
switch (Deno.args[0]) {
12+
case "-l":
13+
text = Deno.readTextFileSync(Deno.args[1]);
14+
break;
15+
case "-r": {
16+
const resp = await fetch(Deno.args[1]);
17+
text = await resp.text();
18+
break;
2519
}
20+
case "-s":
21+
text = Deno.args[1];
22+
break;
23+
default:
24+
throw Error("Only -l, -r and -s is allowed");
25+
}
2626

27-
console.log(renderMarkdown(text));
28-
}
27+
console.log(renderMarkdown(text));
28+
}

deno.json

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
{
2-
"tasks": {
3-
"example": "deno run --unstable example.ts",
4-
"bundle:mdast": "deno bundle --no-check ./mdast_shimmed_dep.ts mdast-util-from-markdown@1_2_0-shimmed.js",
5-
"docs:gen": "deno run -A --unstable ./docs/snapper.ts",
6-
"test": "deno test --allow-read=./test"
7-
},
8-
"fmt": {
9-
"files": {
10-
"exclude": [
11-
"./mdast-util-from-markdown@1_2_0-shimmed.js",
12-
"./test/testCases",
13-
"./test/exampleOutput.out"
14-
]
15-
}
16-
}
17-
}
2+
"tasks": {
3+
"example": "deno run example.ts",
4+
"bundle:mdast": "deno bundle --no-check ./mdast_shimmed_dep.ts mdast-util-from-markdown@1_2_0-shimmed.js",
5+
"docs:gen": "deno run -A ./docs/snapper.ts",
6+
"test": "deno test --allow-read=./test"
7+
},
8+
"fmt": {
9+
"lineWidth": 120,
10+
"exclude": [
11+
"./README.md",
12+
"./docs/docs.md",
13+
"./mdast-util-from-markdown@1_2_0-shimmed.js",
14+
"./test/testCases",
15+
"./test/exampleOutput.out"
16+
]
17+
},
18+
"lock": false
19+
}

deps.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
export * as colors from 'https://deno.land/std@0.105.0/fmt/colors.ts';
1+
export * as colors from "https://deno.land/std@0.105.0/fmt/colors.ts";
22

3-
import { mdast, gfmStrikethroughFromMarkdown, gfmStrikethrough } from './mdast-util-from-markdown@1_2_0-shimmed.js';
3+
import { gfmStrikethrough, gfmStrikethroughFromMarkdown, mdast } from "./mdast-util-from-markdown@1_2_0-shimmed.js";
44
export const strikethroughExt = gfmStrikethroughFromMarkdown;
55
export const strike = gfmStrikethrough;
6-
// deno-lint-ignore no-explicit-any
7-
export type mdastFromMarkdownFn = (markdown: string, encodig?: string, options?: {extensions?: any[], mdastExtensions?: any[]}) => any;
6+
export type mdastFromMarkdownFn = (
7+
markdown: string,
8+
encodig?: string,
9+
// deno-lint-ignore no-explicit-any
10+
options?: { extensions?: any[]; mdastExtensions?: any[] },
11+
// deno-lint-ignore no-explicit-any
12+
) => any;
813
export const fromMarkdown: mdastFromMarkdownFn = mdast;

docs/docs.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import {renderMarkdown} from '../mod.ts';
1+
import { renderMarkdown } from "../mod.ts";
22

3-
let md = Deno.readTextFileSync('docs/docs.md');
3+
const md = Deno.readTextFileSync("docs/docs.md");
44
let r = renderMarkdown(md);
5-
// remove empty lines after header, to save space on image
6-
r = r.replace(/\n\n/, "\n").replace(/\n\n/, "\n").replace(/\n\n/, "\n").replace(/\n\n/, "\n").replace(/\n\n/, "\n").replace(/\n\n/, "\n");
7-
console.log(r);
5+
// remove empty lines after headers to save space on image
6+
for (let i = 0; i < 6; i++) {
7+
r = r.replace(/\n\n/, "\n");
8+
}
9+
console.log(r);

docs/snapper.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import {snap} from 'https://deno.land/x/snapper@v0.0.6/mod.ts';
1+
import { snap } from "https://deno.land/x/snapper@v0.0.6/mod.ts";
22
import { renderMarkdown } from "../mod.ts";
33

44
// Usage:
55
// 1. have deno Puppeteer installed
66
// 2. deno run -A --unstable .\docs\snapper.ts
7+
// https://www.diffchecker.com/image-compare/
78

8-
const md = Deno.readTextFileSync('docs/docs.md');
9-
let r = renderMarkdown(md);
10-
// remove empty lines after header, to save space on image
11-
r = r.replace(/\n\n/, "\n").replace(/\n\n/, "\n").replace(/\n\n/, "\n").replace(/\n\n/, "\n").replace(/\n\n/, "\n").replace(/\n\n/, "\n").replace(/_{25}/, '');
9+
const md = Deno.readTextFileSync("docs/docs.md");
10+
let r = renderMarkdown(md, { lineWidth: 69 });
1211

12+
// remove empty lines after headers to save space on image
13+
for (let i = 0; i < 6; i++) {
14+
r = r.replace(/\n\n/, "\n");
15+
}
1316

1417
await snap([
15-
{content: r, imageSavePath: 'docs/showcase.png', viewport: {width: 675}}
16-
]);
18+
{ content: r, imageSavePath: "docs/showcase.png", viewport: { width: 675 } },
19+
]);

example.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {renderMarkdown} from './mod.ts';
1+
import { renderMarkdown } from "./mod.ts";
22

3-
export const demoText = `
3+
export const demoText: string = `
44
# deno charmd
55
66
This is an example, to showcase https://github.com/littletof/charmd
@@ -179,14 +179,14 @@ Autoconverted link https://deno.land
179179
180180
`;
181181

182-
if(import.meta.main) {
182+
if (import.meta.main) {
183183
let md;
184-
if(Deno.args[0]) {
185-
md = Deno.readTextFileSync(Deno.args[0]);
184+
if (Deno.args[0]) {
185+
md = Deno.readTextFileSync(Deno.args[0]);
186186
} else {
187-
md = demoText;
187+
md = demoText;
188188
}
189189

190190
// renderMarkdown(md)
191191
console.log(renderMarkdown(md));
192-
}
192+
}

0 commit comments

Comments
 (0)