test(docs): type check docs code examples (#3180)
This PR adds the initial seeds of type checking the code in all code
blocks for the Markdown Docs.
- Adds a unit test, disabled due to the many remaining errors, that can
help find incorrect code
- Fixes a bunch of syntax errors, type errors, and other code issues
found in the docs
## Future improvements
A lot of remaining issues is mostly related to missing imports, e.g.
`App`, `staticFiles`, `HttpError` etc. There's a couple of different
directions to solve this in future PR's.
- Add explicit imports to all docs examples (may become unnecessarily
verbose)
- Add code to docs code blocks, but with a hint to remove it when
rendering the markdown as HTML
```tsx
import { App } from "fresh";
// #docs-start
// Everything above marker above is trimmed away
const app = new App();
```
- Add a `types.d.ts` with "global" types used during type checking, so
globals, imports and so on can be handled globally
I do think that some examples probably should be more explicit with
imports, but it would be overkill for a lot of places such as `app.md`
and `context.md`.
This commit is contained in:
@@ -235,15 +235,16 @@ export function renderMarkdown(
|
||||
opts: MarkdownOptions = {},
|
||||
): { headings: MarkdownHeading[]; html: string } {
|
||||
const renderer = new DefaultRenderer();
|
||||
const markedOpts: Marked.MarkedOptions = {
|
||||
const markedOpts: Marked.MarkedOptions & { async: false } = {
|
||||
gfm: true,
|
||||
async: false,
|
||||
renderer,
|
||||
};
|
||||
|
||||
try {
|
||||
const html = opts.inline
|
||||
? Marked.parseInline(input, markedOpts) as string
|
||||
: Marked.parse(input, markedOpts) as string;
|
||||
? Marked.parseInline(input, markedOpts)
|
||||
: Marked.parse(input, markedOpts);
|
||||
|
||||
return { headings: renderer.headings, html };
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user