Skip to content

Commit aa2e2c4

Browse files
authored
apply linking logic to inline code spans (#4475)
1 parent b8bd5c6 commit aa2e2c4

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/kit/types/index.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,9 @@ export interface ParamMatcher {
215215
}
216216

217217
/**
218-
* A function exported from an endpoint that corresponds to an
219-
* HTTP verb (`get`, `put`, `patch`, etc) and handles requests with
220-
* that method. Note that since 'delete' is a reserved word in
221-
* JavaScript, delete handles are called `del` instead.
218+
* A `(event: RequestEvent) => RequestHandlerOutput` function exported from an endpoint that corresponds to an HTTP verb (`get`, `put`, `patch`, etc) and handles requests with that method. Note that since 'delete' is a reserved word in JavaScript, delete handles are called `del` instead.
222219
*
223-
* Note that you can use [generated types](/docs/types#generated-types)
224-
* instead of manually specifying the `Params` generic argument.
220+
* Note that you can use [generated types](/docs/types#generated-types) instead of manually specifying the `Params` generic argument.
225221
*/
226222
export interface RequestHandler<
227223
Params extends Record<string, string> = Record<string, string>,

sites/kit.svelte.dev/src/lib/docs/server/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ export async function read_file(dir, file) {
171171
.join('');
172172
}
173173
);
174+
},
175+
codespan: (text) => {
176+
return (
177+
'<code>' +
178+
text.replace(type_regex, (match, prefix, name) => {
179+
const link = `<a href="${type_links.get(name)}">${name}</a>`;
180+
return `${prefix || ''}${link}`;
181+
}) +
182+
'</code>'
183+
);
174184
}
175185
});
176186

@@ -241,7 +251,8 @@ export function read_headings(dir) {
241251
file,
242252
// gross hack to accommodate FAQ
243253
slug: dir === 'faq' ? slug : undefined,
244-
code: () => ''
254+
code: () => '',
255+
codespan: () => ''
245256
});
246257

247258
return {
@@ -259,9 +270,10 @@ export function read_headings(dir) {
259270
* file: string;
260271
* slug: string;
261272
* code: (source: string, language: string, current: string) => string;
273+
* codespan: (source: string) => string;
262274
* }} opts
263275
*/
264-
function parse({ body, file, slug, code }) {
276+
function parse({ body, file, slug, code, codespan }) {
265277
const headings = slug ? [slug] : [];
266278
const sections = [];
267279

@@ -307,7 +319,8 @@ function parse({ body, file, slug, code }) {
307319

308320
return `<h${level} id="${slug}">${html}<a href="#${slug}" class="anchor"><span class="visually-hidden">permalink</span></a></h${level}>`;
309321
},
310-
code: (source, language) => code(source, language, current)
322+
code: (source, language) => code(source, language, current),
323+
codespan
311324
});
312325

313326
return {

0 commit comments

Comments
 (0)