A calm place to write long-form, and publish it to the open social web.
skypress.blog/
1/**
2 * Splits a lexicon description into plain-text and inline-code segments.
3 *
4 * Schema descriptions (from the lexicon JSON) use Markdown-style `code` spans. Astro
5 * outputs interpolated strings as plain text, so the backticks would otherwise render
6 * literally. The page maps these segments to `<code>` for code parts and bare text for
7 * the rest; Astro escapes the text nodes, so no raw HTML is injected on the read path.
8 */
9export interface DescSegment {
10 text: string;
11 code: boolean;
12}
13
14export function parseInlineCode( text: string ): DescSegment[] {
15 const segments: DescSegment[] = [];
16 const span = /`([^`]+)`/g;
17 let last = 0;
18 let match: RegExpExecArray | null;
19
20 while ( ( match = span.exec( text ) ) !== null ) {
21 if ( match.index > last ) {
22 segments.push( { text: text.slice( last, match.index ), code: false } );
23 }
24 segments.push( { text: match[ 1 ], code: true } );
25 last = match.index + match[ 0 ].length;
26 }
27
28 if ( last < text.length ) {
29 segments.push( { text: text.slice( last ), code: false } );
30 }
31
32 return segments;
33}