Skip to content

Instantly share code, notes, and snippets.

@paoloricciuti
Created October 10, 2025 08:18
Show Gist options
  • Select an option

  • Save paoloricciuti/0336e17e9ba55bece35869d1fe751521 to your computer and use it in GitHub Desktop.

Select an option

Save paoloricciuti/0336e17e9ba55bece35869d1fe751521 to your computer and use it in GitHub Desktop.
Creates a structured and separated sections from the `llms-small.txt` file
function split_docs(txt: string, level = '##') {
return [...txt.matchAll(new RegExp(`^${level}\\s(.+)$`, 'gm'))].map((match, i, arr) => {
const title = match[1]!;
const text = match.input.substring(match.index, arr[i + 1]?.index).trim();
return [title, { title, content: text, slug: slugify(title).toLowerCase() }] as const;
});
}
function clean(markdown: string) {
return markdown
.replace(/(?:^|b)\*\*(.+?)\*\*(?:\b|$)/g, '$1') // bold
.replace(/(?:^|b)_(.+?)_(?:\b|$)/g, '$1') // Italics
.replace(/(?:^|b)\*(.+?)\*(?:\b|$)/g, '$1') // Italics
.replace(/(?:^|b)`(.+?)`(?:\b|$)/g, '$1') // Inline code
.replace(/(?:^|b)~~(.+?)~~(?:\b|$)/g, '$1') // Strikethrough
.replace(/\[(.+?)\]\(.+?\)/g, '$1') // Link
.replace(/\n/g, ' ') // New line
.replace(/ {2,}/g, ' ')
.trim();
}
function slugify(str: string) {
return clean(str)
.replace(/(’|’)/g, "'")
.replace(/&.+?;/g, '')
.replace(/<\/?.+?>/g, '')
.replace(/\.\.\./g, '')
.replace(/[^a-zA-Z0-9-$(.):'_]/g, '-')
.replace(/-{2,}/g, '-')
.replace(/^-/, '')
.replace(/-$/, '');
}
const llm_small = await fetch('https://svelte.dev/llms-small.txt').then((res) => res.text());
const docs = split_docs(llm_small);
const svelte_docs_small = docs.shift()!;
const svelte_docs = split_docs(svelte_docs_small[1].content, '###');
const all = Object.fromEntries([...docs, ...svelte_docs]);
import('node:fs').then(async ({ writeFileSync }) =>
writeFileSync('all.json', JSON.stringify(all, null, 2)),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment