This is raw HTML" }} />;
```
This will output:
-```html
+```html Response body
This is raw HTML
diff --git a/docs/canary/getting-started/index.md b/docs/canary/getting-started/index.md
index 68d4c921..04f7da43 100644
--- a/docs/canary/getting-started/index.md
+++ b/docs/canary/getting-started/index.md
@@ -16,8 +16,8 @@ This will span a short wizard that guides you through the setup, like the
project name, if you want to use tailwindcss and if you're using vscode. Your
project folder should look like this:
-```sh Project structure
-
+```txt-files Project structure
+
├── islands/ # Components that need JS to run client-side
│ └── Counter.tsx
├── routes/ # File system based routes
diff --git a/docs/canary/introduction/index.md b/docs/canary/introduction/index.md
index 3eb7d00f..314cbe9f 100644
--- a/docs/canary/introduction/index.md
+++ b/docs/canary/introduction/index.md
@@ -9,7 +9,7 @@ Fresh is a small, fast and extensible full stack web framework built on Web
Standards. It's designed for building high-quality, performant, and personalized
web applications.
-```tsx
+```tsx main.tsx
import { App } from "fresh";
const app = new App()
diff --git a/docs/canary/plugins/cors.md b/docs/canary/plugins/cors.md
index 0158932f..e6a4bace 100644
--- a/docs/canary/plugins/cors.md
+++ b/docs/canary/plugins/cors.md
@@ -7,7 +7,7 @@ The `cors()` middleware can be used to add
to HTTP requests. These allow the server to indicate which origins (domains,
scheme or port) other than its own is permitted to load resources from.
-```ts
+```ts main.ts
import { cors } from "fresh";
const app = new App()
diff --git a/docs/canary/plugins/csrf.md b/docs/canary/plugins/csrf.md
index e2af9775..2e289bff 100644
--- a/docs/canary/plugins/csrf.md
+++ b/docs/canary/plugins/csrf.md
@@ -13,7 +13,7 @@ header. to HTTP requests. These allow the server to indicate which origins
(domains, scheme or port) other than its own is permitted to load resources
from.
-```ts
+```ts main.ts
const app = new App();
app.use(csrf());
diff --git a/docs/canary/plugins/index.md b/docs/canary/plugins/index.md
index 36f8d47c..86bfdf11 100644
--- a/docs/canary/plugins/index.md
+++ b/docs/canary/plugins/index.md
@@ -12,7 +12,7 @@ If you need to modify requests, add HTTP headers or pass additional data to
other middlewares via `ctx.state`, then going with a middleware is the way to
go.
-```ts
+```ts middleware/fresh.ts
const addXFreshHeader = define.middleware(async (ctx) => {
const res = await ctx.next();
res.headers.set("X-Fresh", "served by Fresh");
diff --git a/docs/canary/plugins/tailwindcss.md b/docs/canary/plugins/tailwindcss.md
index dc2ceac9..f6ab2306 100644
--- a/docs/canary/plugins/tailwindcss.md
+++ b/docs/canary/plugins/tailwindcss.md
@@ -41,7 +41,7 @@ For more information on how to use tailwindcss, check out
You can customize the tailwind plugin via the following options:
-```ts
+```ts dev.ts
tailwind(builder, app, {
// Exclude certain files from processing
exclude: ["/admin/**", "*.temp.css"],
diff --git a/docs/canary/plugins/trailing-slashes.md b/docs/canary/plugins/trailing-slashes.md
index 0ea34752..900b77e1 100644
--- a/docs/canary/plugins/trailing-slashes.md
+++ b/docs/canary/plugins/trailing-slashes.md
@@ -6,7 +6,7 @@ The `trailingSlashes()` middleware can be used to ensure URL pathnames always
end with a slash character or will never end with one. It redirects the user's
request respectively.
-```ts
+```ts main.ts
import { trailingSlashes } from "fresh";
const app = new App()
@@ -16,7 +16,7 @@ const app = new App()
Always append a trailing slash:
-```ts
+```ts main.ts
import { trailingSlashes } from "fresh";
const app = new App()
diff --git a/docs/canary/testing/index.md b/docs/canary/testing/index.md
index 9f3ec288..6795f46d 100644
--- a/docs/canary/testing/index.md
+++ b/docs/canary/testing/index.md
@@ -13,7 +13,7 @@ write tests.
To test [middlewares](/docs/canary/concepts/middleware) we're going to create a
dummy app and return the relevant info we want to check in a custom `/` handler.
-```ts
+```ts middleware.test.ts
import { expect } from "@std/expect";
import { App } from "fresh";
@@ -43,7 +43,7 @@ that adds a header to the returned response, you can assert against that too.
Both the [app wrapper](/docs/canary/advanced/app-wrapper) component and
[layouts](/docs/canary/advanced/layouts) can be tested in the same way.
-```tsx
+```tsx routes/_app.test.tsx
import { expect } from "@std/expect";
import { App } from "fresh";
@@ -77,7 +77,7 @@ Deno.test("App Wrapper - renders title and content", async () => {
Same can be done for layouts.
-```tsx
+```tsx routes/_layout.test.tsx
import { expect } from "@std/expect";
import { App } from "fresh";
diff --git a/docs/latest/concepts/ahead-of-time-builds.md b/docs/latest/concepts/ahead-of-time-builds.md
index 9aef771a..2bf3280e 100644
--- a/docs/latest/concepts/ahead-of-time-builds.md
+++ b/docs/latest/concepts/ahead-of-time-builds.md
@@ -22,7 +22,7 @@ pre-process or generate CSS files, for example.
To have Fresh optimize all the assets, run one of the following commands:
-```sh
+```sh Terminal
# As a task in newer Fresh projects
deno task build
# or invoke it manually
diff --git a/docs/latest/concepts/deployment.md b/docs/latest/concepts/deployment.md
index e33bf70e..2f8a7e17 100644
--- a/docs/latest/concepts/deployment.md
+++ b/docs/latest/concepts/deployment.md
@@ -8,8 +8,8 @@ deployed to any system or platform that can run a Deno based web server.
Here are instructions for specific providers / systems:
-- [Deno Deploy](#deno-deploy)
-- [Docker](#docker)
+- [Deno Deploy](#-deno-deploy)
+- [Docker](#-docker)
## Deno Deploy
diff --git a/docs/latest/concepts/error-pages.md b/docs/latest/concepts/error-pages.md
index 20852b04..a224aa98 100644
--- a/docs/latest/concepts/error-pages.md
+++ b/docs/latest/concepts/error-pages.md
@@ -57,7 +57,7 @@ export default function BlogpostPage({ data }) {
This can also be achieved by throwing an error, if you're uninterested in
passing specific data to your 404 page:
-```tsx
+```tsx routes/missing-page.tsx
import { Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
diff --git a/docs/latest/concepts/islands.md b/docs/latest/concepts/islands.md
index a39c628e..9d1aa2f7 100644
--- a/docs/latest/concepts/islands.md
+++ b/docs/latest/concepts/islands.md
@@ -131,7 +131,7 @@ enough information to put the islands where they are supposed to go without
requiring hydration for the static children of interactive islands. No
Javascript is sent to the client when no interactivity is needed.
-```html
+```html Response body
Counter is at 0.
diff --git a/docs/latest/concepts/layouts.md b/docs/latest/concepts/layouts.md
index 9de5130e..bf04dad6 100644
--- a/docs/latest/concepts/layouts.md
+++ b/docs/latest/concepts/layouts.md
@@ -7,7 +7,8 @@ A layout is defined in a `_layout.tsx` file in any sub directory (at any level)
under the `routes/` folder. It must contain a default export that is a regular
Preact component. Only one such layout is allowed per sub directory.
-```txt Project structure
+```txt-files Project structure
+
└── routes
├── sub
│ ├── page.tsx
@@ -64,7 +65,7 @@ To make it a little quicker to write async layouts, Fresh ships with a
`defineLayout` helper which automatically infers the correct types for the
function arguments.
-```tsx
+```tsx routes/greet/_layout.tsx
import { defineLayout } from "$fresh/server.ts";
export default defineLayout(async (req, ctx) => {
@@ -85,8 +86,8 @@ Sometimes you want to opt out of the layout inheritance mechanism for a
particular route. This can be done via route configuration. Picture a directory
structure like this:
-```txt Project structure
-└── routes
+```txt-files Project structure
+└── /routes
├── sub
│ ├── _layout_.tsx
│ ├── special.tsx # should not inherit layouts
diff --git a/docs/latest/concepts/middleware.md b/docs/latest/concepts/middleware.md
index 3e5502c1..ae3f2df7 100644
--- a/docs/latest/concepts/middleware.md
+++ b/docs/latest/concepts/middleware.md
@@ -50,8 +50,8 @@ specific first).
For example, take a project with the following routes:
-```txt Project Structure
-└── routes
+```txt-files Project Structure
+└── /routes
├── _middleware.ts
├── index.ts
└── admin
@@ -118,7 +118,7 @@ the value of `acme` in your middleware.
To set the stage for this section, let's focus on the part of `FreshContext`
that looks like this:
-```ts
+```ts fresh 🍋
export interface FreshContext> {
...
next: () => Promise;
@@ -135,7 +135,7 @@ export interface FreshContext> {
and `router.DestinationKind` is defined like this:
-```ts
+```ts fresh 🍋
export type DestinationKind = "internal" | "static" | "route" | "notFound";
```
@@ -203,7 +203,7 @@ is only supposed to deal with routes.
If you want to redirect a request from a middleware, you can do so by returning:
-```ts
+```ts routes/_middleware.ts
export function handler(req: Request): Response {
return Response.redirect("https://example.com", 307);
}
@@ -212,7 +212,7 @@ export function handler(req: Request): Response {
`307` stands for temporary redirect. You can also use `301` for permanent
redirect. You can also redirect to a relative path by doing:
-```ts
+```ts routes/_middleware.ts
export function handler(req: Request): Response {
return new Response("", {
status: 307,
diff --git a/docs/latest/concepts/partials.md b/docs/latest/concepts/partials.md
index 559cab42..1b697dcf 100644
--- a/docs/latest/concepts/partials.md
+++ b/docs/latest/concepts/partials.md
@@ -62,7 +62,7 @@ picks out the relevant parts of the response. We can optimize this pattern
further by only rendering the parts we need, instead of always rendering the
full page. This is done by adding the `f-partial` attribute to a link.
-```diff
+```diff routes/_app.tsx
- Routes
+ Routes
```
@@ -180,7 +180,7 @@ achieved by adding the `mode` prop to a `Partial` component.
Personally, we’ve found that the `append` mode is really useful when you have an
UI which displays log messages or similar list-like data.
-```tsx
+```tsx routes/log.tsx
export default function LogView() {
const lines = getNewLogLines();
@@ -203,7 +203,7 @@ If you want to exempt a particular element from triggering a partial request
like on a particular link, form or button, you can opt out of it by setting
`f-client-nav={false}` on the element or one of the ancestor elements.
-```tsx
+```tsx routes/index.tsx
{/* This will cause a partial navigation */}
With partials
diff --git a/docs/latest/concepts/plugins.md b/docs/latest/concepts/plugins.md
index 8999a416..fdc39278 100644
--- a/docs/latest/concepts/plugins.md
+++ b/docs/latest/concepts/plugins.md
@@ -40,7 +40,7 @@ A Fresh plugin is just a JavaScript object that conforms to the
required property of a plugin is its name. Names must only contain the
characters `a`-`z`, and `_`.
-```ts
+```ts my-plugin.ts
import { Plugin } from "$fresh/server.ts";
const plugin: Plugin = {
diff --git a/docs/latest/concepts/routes.md b/docs/latest/concepts/routes.md
index f627ddbb..c1aa4a11 100644
--- a/docs/latest/concepts/routes.md
+++ b/docs/latest/concepts/routes.md
@@ -172,7 +172,7 @@ To make it a little quicker to write async routes, Fresh ships with a
`defineRoute` helper which automatically infers the correct types for the
function arguments.
-```tsx
+```tsx routes/hello.tsx
import { defineRoute } from "$fresh/server.ts";
export default defineRoute(async (req, ctx) => {
diff --git a/docs/latest/concepts/routing.md b/docs/latest/concepts/routing.md
index e095d77b..8ff59f83 100644
--- a/docs/latest/concepts/routing.md
+++ b/docs/latest/concepts/routing.md
@@ -61,7 +61,7 @@ suggested by the URL segment.
Let's illustrate that with an example:
-```txt
+```txt Example page layout
/about -> layout A
/career -> layout A
/archive -> layout B
@@ -71,7 +71,8 @@ Let's illustrate that with an example:
Without any way to group routes this is a problem because every route segment
can only have one `_layout` file.
-```txt Project structure
+```txt-files Project structure
+
└── routes
├── _layout.tsx # applies to all routes here :(
├── about.tsx
@@ -85,8 +86,8 @@ a name that is wrapped in parentheses. For example `(info)` would be considered
a route group and so would `(marketing)`. This enables us to group related
routes in a folder and use a different `_layout` file for each group.
-```txt Project structure
-└── routes
+```txt-files Project structure
+└── /routes
├── (marketing)
│ ├── _layout.tsx # only applies to about.tsx and career.tsx
│ ├── about.tsx
@@ -101,8 +102,8 @@ routes in a folder and use a different `_layout` file for each group.
> URL. Such scenarios will lead to ambiguity as to which route file should be
> picked.
>
-> ```txt Project structure
-> └── routes
+> ```txt-files Project structure
+> └── /routes
> ├── (group-1)
> │ └── about.tsx # Bad: Maps to same `/about` url
> └── (group-2)
@@ -128,8 +129,8 @@ to house these.
The one special name is `(_islands)` which tells Fresh to treat all files in
that folder as an island.
-```txt Project structure
-└── routes
+```txt-files Project structure
+└── /routes
├── (marketing)
│ ├── _layout.tsx
│ ├── about.tsx
diff --git a/docs/latest/concepts/server-configuration.md b/docs/latest/concepts/server-configuration.md
index 3b162aa7..bd8af9e6 100644
--- a/docs/latest/concepts/server-configuration.md
+++ b/docs/latest/concepts/server-configuration.md
@@ -18,7 +18,7 @@ things get interesting.
[`FreshConfig`](https://deno.land/x/fresh/server.ts?s=FreshConfig) looks like
this:
-```ts
+```ts fresh 🍋
export interface FreshConfig {
build?: {
/**
@@ -44,7 +44,7 @@ export interface FreshConfig {
And for completeness here are the remaining two types:
-```ts
+```ts fresh 🍋
export type RenderFunction = (
ctx: RenderContext,
render: InnerRenderFunction,
@@ -81,7 +81,7 @@ export interface RouterOptions {
As the comment suggests, this can be used to configure where generated files are
written:
-```tsx
+```tsx dev.ts
await dev(import.meta.url, "./main.ts", {
build: {
outDir: Deno.env.get("FRESH_TEST_OUTDIR") ?? undefined,
@@ -93,7 +93,7 @@ await dev(import.meta.url, "./main.ts", {
This should be a valid ES Build target.
-```tsx
+```tsx dev.ts
await dev(import.meta.url, "./main.ts", {
build: {
target: "es2015",
diff --git a/docs/latest/concepts/static-files.md b/docs/latest/concepts/static-files.md
index 880de300..5af5d2d1 100644
--- a/docs/latest/concepts/static-files.md
+++ b/docs/latest/concepts/static-files.md
@@ -46,6 +46,10 @@ and `` HTML tags. These will automatically use "locked" paths if Fresh
deems it safe to do so. You can always opt out of this behaviour per tag, by
adding the `data-fresh-disable-lock` attribute.
-```tsx
+```tsx routes/user.tsx
+{/* Locked URL source */}
;
+
+{/* Preserve URL source and disable lock */}
+ ;
```
diff --git a/docs/latest/concepts/updating.md b/docs/latest/concepts/updating.md
index b3ae1daa..a47e05ac 100644
--- a/docs/latest/concepts/updating.md
+++ b/docs/latest/concepts/updating.md
@@ -97,7 +97,7 @@ the recommended way to use JSX in Fresh projects. Instead, starting with version
1.1.0, Fresh projects should use the automatic JSX transform that requires no
JSX pragma or preact import.
-```diff
+```diff routes/hello-world.tsx
- /** @jsx h */
- import { h } from "preact";
diff --git a/docs/latest/examples/active-links.md b/docs/latest/examples/active-links.md
index 5b4ee3fc..df3727d2 100644
--- a/docs/latest/examples/active-links.md
+++ b/docs/latest/examples/active-links.md
@@ -8,18 +8,18 @@ aria-current attribute when rendering links that match the current URL. This
attribute is recognized by assistive technologies and clearly indicates the
current page within a set of pages.
-- aria-current="page" - Added to links with an exact path match, enhancing
+- `aria-current="page"` - Added to links with an exact path match, enhancing
accessibility by indicating the current page to assistive technologies.
-As we aim to improve accessibility, we encourage the use of aria-current for
+As we aim to improve accessibility, we encourage the use of `aria-current` for
styling current links where applicable.
## Styling with CSS
-The aria-current attribute is easily styled with CSS using attribute selectors,
-providing a native way to visually differentiate the active link.
+The `aria-current` attribute is easily styled with CSS using attribute
+selectors, providing a native way to visually differentiate the active link.
-```css
+```css static/styles.css
/* Give links pointing to the current page a green color */
a[aria-current="page"] {
color: green;
@@ -38,7 +38,7 @@ elements with the aria-current attribute using bracket notation in your class
definitions. However, the specific syntax varies slightly between Tailwind and
Twind. For Tailwind, use the syntax:
-```tsx
+```tsx component/Menu.tsx
function Menu() {
return (
@@ -50,7 +50,7 @@ function Menu() {
For Twind, the syntax is:
-```tsx
+```tsx component/Menu.tsx
function Menu() {
return (
@@ -65,7 +65,7 @@ function Menu() {
The original twind plugin (`import twindPlugin from "$fresh/plugins/twind.ts";`)
supports the above style:
-```tsx
+```tsx routes/page.tsx
class="[aria-current='page']:text-green-600"
```
@@ -74,6 +74,6 @@ class="[aria-current='page']:text-green-600"
The new twind plugin (`import twindPlugin from "$fresh/plugins/twindv1.ts";`)
requires a slightly different syntax (note the position of the left bracket):
-```tsx
+```tsx routes/page.tsx
class="aria-[current='page']:text-green-600"
```
diff --git a/docs/latest/examples/changing-the-src-dir.md b/docs/latest/examples/changing-the-src-dir.md
index a85dea6e..1bb62405 100644
--- a/docs/latest/examples/changing-the-src-dir.md
+++ b/docs/latest/examples/changing-the-src-dir.md
@@ -6,8 +6,8 @@ description: |
When you initialize a project with `deno run -A -r https://fresh.deno.dev`,
you'll end up with a project like the following:
-```txt Project Structure
-.
+```txt-files Project Structure
+
├── README.md
├── components
│ └── Button.tsx
@@ -53,8 +53,8 @@ Here's what the diff of `deno.json` looks like:
The resulting file structure looks like this:
-```txt Project Structure
-.
+```txt-files Project Structure
+
├── README.md
├── deno.json
└── src
diff --git a/docs/latest/examples/client-side-components-and-libraries.md b/docs/latest/examples/client-side-components-and-libraries.md
index 0224881c..39cf2662 100644
--- a/docs/latest/examples/client-side-components-and-libraries.md
+++ b/docs/latest/examples/client-side-components-and-libraries.md
@@ -29,7 +29,7 @@ rendering might not be feasible.
> [warn]: Proper typing might not be easily available, so we might need to
> define our own types or not use types at all.
-```ts
+```ts context.ts
export const leafletContext = createContext(null);
```
@@ -46,7 +46,7 @@ state, and this value will be handled/shared with our other components.
> script and css may cause issues. Leaflet, for instance, will throw errors if
> we try to load it again.
-```tsx
+```tsx context.ts
function LeafletProvider(props: { children: ComponentChildren }) {
if (!IS_BROWSER) {
return (
@@ -85,7 +85,7 @@ cases where the context has not loaded values yet is a good practice as well, in
this way we can have a smooth integration and manipulation of client-side data
and logic on our server-side code.
-```tsx
+```tsx component/Map.tsx
function MapComponent() {
const leaf = useContext(leafletContext);
if (!leaf) return Context not ready. Component placeholder
;
@@ -105,7 +105,7 @@ to demonstrate a simple usage. In real cases, it's usually better to add the
Provider directly to our Page and then use Components that depend on that
provider inside it.
-```tsx
+```tsx islands/MapIsland.tsx
export default function MapIsland() {
return (
@@ -117,7 +117,7 @@ export default function MapIsland() {
## Full code:
-```tsx MapIsland.tsx
+```tsx islands/MapIsland.tsx
import * as Leaflet from "https://esm.sh/v135/@types/leaflet@1.9.4/index.d.ts";
import { IS_BROWSER } from "$fresh/runtime.ts";
import { useContext, useEffect } from "preact/hooks";
diff --git a/docs/latest/examples/creating-a-crud-api.md b/docs/latest/examples/creating-a-crud-api.md
index 54fcc92e..9d6a22e2 100644
--- a/docs/latest/examples/creating-a-crud-api.md
+++ b/docs/latest/examples/creating-a-crud-api.md
@@ -19,12 +19,13 @@ In this example we'll be creating a small API that uses
Our project structure will look like this (in addition to the rest of the Fresh
code from a new project):
-```txt Project Structure
-routes
-└── api
- └── users
- ├── [id].ts
- └── index.ts
+```txt-files Project Structure
+
+└── routes
+ └── api
+ └── users
+ ├── [id].ts
+ └── index.ts
```
In each section about a method, only the relevant handler will be shown. The
@@ -50,7 +51,7 @@ Test this with Postman (or your favorite client) with a URL like
`http://localhost:8000/api/users` and a method of `POST`. Make sure to have a
payload like:
-```json
+```json Request body
{
"id": "2",
"name": "TestUserName"
@@ -59,7 +60,7 @@ payload like:
You should receive the same thing back:
-```json
+```json Response body
{ "id": "2", "name": "TestUserName" }
```
@@ -82,7 +83,7 @@ export const handler: Handlers = {
Let's practice retrieving our user! A `GET` request to
`http://localhost:8000/api/users/2` should return:
-```json
+```json Response body
{ "id": "2", "name": "TestUserName" }
```
@@ -116,7 +117,7 @@ export const handler: Handlers = {
Time to change their name. We'll now `PUT` a request to
`http://localhost:8000/api/users/2` like:
-```json
+```json Request body
{
"id": "2",
"name": "New Name"
@@ -125,14 +126,14 @@ Time to change their name. We'll now `PUT` a request to
We should receive:
-```json
+```json Response body
{ "id": "2", "name": "New Name" }
```
If, on the other hand, we chose to implement this as a `PATCH` operation, the
request would just involve the changed property like this:
-```json
+```json Response body
{
"name": "New Name"
}
@@ -161,7 +162,7 @@ export const handler: Handlers = {
Try sending `DELETE` to `http://localhost:8000/api/users/2` without a body.
We'll get back:
-```txt
+```txt Response body
user 2 deleted
```
@@ -174,9 +175,9 @@ request checks for complex CORS use cases. See more on the
## Full File Reference
-[id].ts
+[id].ts
-```ts
+```ts routes/api/users/[id].ts
import { Handlers } from "$fresh/server.ts";
type User = {
@@ -218,9 +219,9 @@ export const handler: Handlers = {
-index.ts
+index.ts
-```ts
+```ts routes/api/users/index.ts
import { Handlers } from "$fresh/server.ts";
type User = {
diff --git a/docs/latest/examples/handling-complex-routes.md b/docs/latest/examples/handling-complex-routes.md
index 757c5ded..1e7d0f4d 100644
--- a/docs/latest/examples/handling-complex-routes.md
+++ b/docs/latest/examples/handling-complex-routes.md
@@ -35,7 +35,7 @@ Now if we hit the server with a request like
`http://localhost:8000/x/bestModule@1.33.7/asdf`, then logging the params will
show the following:
-```
+```txt Console output
{
module: "bestModule",
version: "1.33.7",
@@ -66,18 +66,18 @@ Values are available via `params.resource` and `params.id`.
Here are some example URLs that match this:
-- /api/db/bar/1
-- /api/db/jobs/1
-- /api/db/job/1
-- /api/db/job
-- /api/db/jobs
-- /api/db/bar
+- `/api/db/bar/1`
+- `/api/db/jobs/1`
+- `/api/db/job/1`
+- `/api/db/job`
+- `/api/db/jobs`
+- `/api/db/bar`
Here are some that don't:
-- /api/db/other/123
-- /api/db/jobs/abc
-- /api/db
+- `/api/db/other/123`
+- `/api/db/jobs/abc`
+- `/api/db`
## Regex
diff --git a/docs/latest/examples/init-the-server.md b/docs/latest/examples/init-the-server.md
index f7fc7e58..6f1c0d56 100644
--- a/docs/latest/examples/init-the-server.md
+++ b/docs/latest/examples/init-the-server.md
@@ -86,7 +86,7 @@ have access to the complicated initialization step by calling
When you run `deno task start` you should see the following output:
-```
+```txt Terminal output
Task start deno run -A --watch=static/,routes/ dev.ts
Watcher Process started.
i'm logged during initialization, and not during handling!
@@ -98,7 +98,7 @@ The manifest has been generated for 6 routes and 1 islands.
Going to `http://localhost:8000/` should produce:
-```
+```txt Terminal output
i'm logged during a request!
Context { complicatedStartupValue: 42 }
```
@@ -107,7 +107,7 @@ Context { complicatedStartupValue: 42 }
When you run `deno task build` you should see:
-```
+```txt Terminal output
Task build deno run -A dev.ts build
i'm logged during initialization, and not during handling!
The manifest has been generated for 6 routes and 1 islands.
@@ -121,7 +121,7 @@ initialization occurred.
Finally when you run `deno task preview` you should see:
-```
+```txt Terminal output
Task preview deno run -A main.ts
i'm logged during initialization, and not during handling!
Using snapshot found at /Users/reed/code/temp/1763/_fresh
@@ -132,7 +132,7 @@ Using snapshot found at /Users/reed/code/temp/1763/_fresh
Going to `http://localhost:8000/` should produce:
-```
+```txt Terminal output
i'm logged during a request!
Context { complicatedStartupValue: 42 }
```
diff --git a/docs/latest/examples/migrating-to-tailwind.md b/docs/latest/examples/migrating-to-tailwind.md
index 889485a4..b3cbbfcf 100644
--- a/docs/latest/examples/migrating-to-tailwind.md
+++ b/docs/latest/examples/migrating-to-tailwind.md
@@ -121,9 +121,9 @@ That's it! Now you can use Tailwind CSS in your project.
> apply. In other words, to use dynamic classes, you need to ensure that they
> are present in the final CSS file.
>
-> | Twind | Tailwind CSS |
-> | --------------------------------- | ------------------------------------------------------------ |
-> | ` ` | ` ` |
+> | Twind | Tailwind CSS |
+> | ----------------------------------- | -------------------------------------------------------------- |
+> | `` `` | `` `` |
## Frequently Asked Questions (FAQ)
diff --git a/docs/latest/examples/modifying-the-head.md b/docs/latest/examples/modifying-the-head.md
index ba1d2d04..e2009dbc 100644
--- a/docs/latest/examples/modifying-the-head.md
+++ b/docs/latest/examples/modifying-the-head.md
@@ -43,30 +43,30 @@ You might end up with duplicate tags, when multiple ` ` components are
rendered on the same page. This can happen when you render ` ` in a route
and another ` ` in another component for example.
-```tsx
-// routes/page-a.tsx
+```tsx routes/page-a.tsx
-
+;
+```
-// components/MyTitle.tsx
+```tsx components/MyTitle.tsx
-
+;
```
To ensure that the tag is not duplicated, Fresh supports setting the `key` prop.
By giving matching elements the same `key` prop, only the last one will be
rendered.
-```diff
- // routes/page-a.tsx
+```diff routes/page-a.tsx
-
+
+```
- // components/MyTitle.tsx
+```diff components/MyTitle.tsx
-
+
diff --git a/docs/latest/examples/rendering-markdown.md b/docs/latest/examples/rendering-markdown.md
index 02d28b37..572dd48c 100644
--- a/docs/latest/examples/rendering-markdown.md
+++ b/docs/latest/examples/rendering-markdown.md
@@ -92,7 +92,7 @@ description: testFromText
You'll also need to import the `Github Flavored Markdown` module:
-```sh
+```sh Terminal
deno add jsr:@deno/gfm
```
diff --git a/docs/latest/examples/rendering-raw-html.md b/docs/latest/examples/rendering-raw-html.md
index d03f9a10..b7f8bd06 100644
--- a/docs/latest/examples/rendering-raw-html.md
+++ b/docs/latest/examples/rendering-raw-html.md
@@ -22,7 +22,7 @@ you trust.
Suppose we need to add some microdata markup to a page. The following will
result in **escaped characters, and will not work**:
-```tsx
+```tsx components/json-ld.tsx
const json = `
{
"@context": "http://schema.org",
@@ -40,7 +40,7 @@ export default function JsonLd() {
Instead, we can use `dangerouslySetInnerHTML`:
-```tsx
+```tsx components/json-ld.tsx
export default function JsonLd() {
return (
```
@@ -179,7 +179,7 @@ function CartItem(props: CartItemProps) {
Now we can add the islands to our site by doing the following:
-```tsx
+```tsx routes/cart.tsx
diff --git a/docs/latest/examples/using-csp.md b/docs/latest/examples/using-csp.md
index 7393104b..55da188c 100644
--- a/docs/latest/examples/using-csp.md
+++ b/docs/latest/examples/using-csp.md
@@ -25,7 +25,7 @@ Fresh's CSP implementation supports the following
directives
-```ts
+```ts fresh 🍋
export interface ContentSecurityPolicyDirectives {
// Fetch directives
/**
@@ -175,7 +175,7 @@ export default function Home(req: Request, ctx: RouteContext) {
We can hit `http://localhost:8000/noCSP` and we should see the following:
-```txt
+```txt Response body
This page doesn't use CSP at all. Styles will be applied.
```
@@ -212,7 +212,7 @@ export const config: RouteConfig = {
We can hit `http://localhost:8000/incorrectCSP` and we should see the following:
-```txt
+```txt Response body
This page violates our configured CSP. Styles won't be applied.
```
@@ -247,7 +247,7 @@ export const config: RouteConfig = {
We can hit `http://localhost:8000/correctCSP` and we should see the following:
-```txt
+```txt Response body
This page adheres to our configured CSP. Styles will be applied.
```
@@ -282,7 +282,7 @@ export default function Home(req: Request, ctx: RouteContext) {
We can hit `http://localhost:8000/cspNoRouteConfig` and we should see the
following:
-```txt
+```txt Response body
This page violates our configured CSP. But we don't have a RouteConfig enabled, so Fresh doesn't know to use the CSP. Styles will be applied.
```
@@ -342,7 +342,7 @@ export const handler = {
We can hit `http://localhost:8000/incorrectCSPwithReport` and we should see the
following:
-```txt
+```txt Response body
This page violates our configured CSP. But we're using "reportOnly". Styles will be applied.
```
diff --git a/docs/latest/examples/using-twind-v1.md b/docs/latest/examples/using-twind-v1.md
index 2aad8898..07e7d75f 100644
--- a/docs/latest/examples/using-twind-v1.md
+++ b/docs/latest/examples/using-twind-v1.md
@@ -36,12 +36,7 @@ export default defineConfig({
Let's bump that up to v1:
-```diff
-diff --git a/fresh.config.ts b/fresh.config.ts
-index 548e16a..e00d557 100644
---- a/fresh.config.ts
-+++ b/fresh.config.ts
-@@ -1,5 +1,5 @@
+```diff fresh.config.ts
import { defineConfig } from "$fresh/server.ts";
-import twindPlugin from "$fresh/plugins/twind.ts";
+import twindPlugin from "$fresh/plugins/twindv1.ts";
diff --git a/docs/latest/examples/writing-tests.md b/docs/latest/examples/writing-tests.md
index 51952b9d..678ce1fc 100644
--- a/docs/latest/examples/writing-tests.md
+++ b/docs/latest/examples/writing-tests.md
@@ -93,7 +93,7 @@ ok | 1 passed (3 steps) | 0 failed (236ms)
This function is typed as follows:
-```ts
+```ts fresh 🍋
export async function createHandler(
manifest: Manifest,
config: FreshConfig = {},
@@ -107,7 +107,7 @@ free to provide your own bag of options.
[`FreshConfig`](https://deno.land/x/fresh/server.ts?s=FreshConfig) is declared
as follows:
-```ts
+```ts fresh 🍋
export interface FreshConfig {
build?: {
outDir?: string;
diff --git a/www/static/markdown.css b/www/static/markdown.css
index 4d30ead0..3c2e22d0 100644
--- a/www/static/markdown.css
+++ b/www/static/markdown.css
@@ -834,3 +834,10 @@ ol.nested li:before {
.highlight-source-yml .string {
color: var(--color-prettylights-syntax-string);
}
+
+.markdown-body pre.highlight-source-txt-files {
+ line-height: 1.35;
+}
+.highlight-source-txt-files .function {
+ font-weight: 600;
+}
diff --git a/www/utils/markdown.ts b/www/utils/markdown.ts
index e6ee0122..d230fd69 100644
--- a/www/utils/markdown.ts
+++ b/www/utils/markdown.ts
@@ -53,7 +53,7 @@ const LOGOS = [
text: "Markdown",
},
{
- lang: /^txt$/,
+ lang: /^txt(-files)?$/,
file: /\.txt$/,
src: asset("/logos/text.svg"),
text: "Text",
diff --git a/www/utils/prism.ts b/www/utils/prism.ts
index 67065003..8389ec72 100644
--- a/www/utils/prism.ts
+++ b/www/utils/prism.ts
@@ -6,5 +6,44 @@ import "prismjs/components/prism-diff.js";
import "prismjs/components/prism-json.js";
import "prismjs/components/prism-bash.js";
import "prismjs/components/prism-yaml.js";
+import "prismjs/components/prism-ignore.js";
+
+/** Extends `sh` with `deno` as a function token in Shell/Bash languages */
+Prism.languages.sh.deno = {
+ pattern: /(^|[\s;|&]|[<>]\()(?:deno)(?=$|[)\s;|&])/,
+ lookbehind: true,
+ alias: "function",
+};
+Prism.languages.bash.deno = Prism.languages.sh.deno;
+
+/**
+ * Adds `txt-files` language for file-structure code blocks.
+ *
+ * - Comments: Makes `#` and everything after a comment
+ * - Operator: Matches the file structure symbols like `├──`, `└──`, and `│ `
+ * - Root: Matches `` or `` to indicate the root of the file structure
+ * - Remaining text is rendered as plain text
+ *
+ * @example
+ * ```txt-files
+ *
+ * ├── routes/ # File system based routes
+ * │ ├── _app.tsx # Renders the outer content structure
+ * │ └── index.tsx # Renders /
+ * ├── dev.ts # Run this during development
+ * └── main.ts # Run this for production
+ * ```
+ */
+Prism.languages["txt-files"] = {
+ comment: {
+ pattern: /#.*|$/,
+ greedy: true,
+ },
+ operator: /├──|└──|│\s+ /,
+ root: {
+ pattern: /|/,
+ alias: "function",
+ },
+};
export { Prism };