Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions docs/latest/examples/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ First, let's install the [`@deno/gfm`](https://jsr.io/@deno/gfm) package that
can transform markdown to html.

1. Run `deno install jsr:@deno/gfm`
2. Create a markdown file like `content.md`:
2. Create a markdown file like `content/example.md`:

```md path/to/content.md
```md content/example.md
## some heading

and some interesting text here
Expand All @@ -24,25 +24,30 @@ and some interesting text here

3. Add a route that renders that file

```tsx main.ts
```tsx routes/markdown.tsx
import { define } from "@/utils.ts";
import { CSS, render as renderMarkdown } from "@deno/gfm";

const app = new App();

app.get("/", async (ctx) => {
const content = await Deno.readTextFile("path/to/content.md");
export default define.page(async () => {
const content = await Deno.readTextFile("./content/example.md");
const html = renderMarkdown(content);

return await ctx.render(
return (
<div>
<h1>Here comes a markdown post:</h1>
{/* deno-lint-ignore react-no-danger */}
<style dangerouslySetInnerHTML={{ __html: CSS }} />
{/* deno-lint-ignore react-no-danger */}
<div dangerouslySetInnerHTML={{ __html: html }} />
</div>,
</div>
);
});
```

For a more elaborate markdown system with Fresh, take a look at the
[source code](https://github.com/denoland/fresh/tree/main/www) for this
documentation website.

## Other libraries

There are several other popular libraries besides `@deno/gfm` that can be used
Expand Down
Loading