// TODO put this in site-kit? svelte.dev uses Prism instead of hljs import fs from 'fs'; import path from 'path'; import { SLUG_SEPARATOR, SLUG_PRESERVE_UNICODE } from '../../config'; import { extract_frontmatter, extract_metadata, langs, link_renderer } from '@sveltejs/site-kit/utils/markdown.js'; import { make_session_slug_processor } from '@sveltejs/site-kit/utils/slug'; import marked from 'marked'; import hljs from 'highlight.js'; const escaped = { '"': '"', "'": ''', '&': '&', '<': '<', '>': '>', }; const unescaped = Object.keys(escaped).reduce( (unescaped, key) => ((unescaped[escaped[key]] = key), unescaped), {} ); function unescape(str) { return String(str).replace(/&.+?;/g, match => unescaped[match] || match); } const block_types = [ 'blockquote', 'html', 'heading', 'hr', 'list', 'listitem', 'paragraph', 'table', 'tablerow', 'tablecell' ]; export default function generate_docs(dir) { const make_slug = make_session_slug_processor({ separator: SLUG_SEPARATOR, preserve_unicode: SLUG_PRESERVE_UNICODE }); return fs .readdirSync(`content/${dir}`) .filter(file => file[0] !== '.' && path.extname(file) === '.md') .map(file => { const markdown = fs.readFileSync(`content/${dir}/${file}`, 'utf-8'); const { content, metadata } = extract_frontmatter(markdown); const section_slug = make_slug(metadata.title); const subsections = []; const renderer = new marked.Renderer(); let block_open = false; renderer.link = link_renderer; renderer.hr = () => { block_open = true; return '
${highlighted}