mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-22 15:15:19 +00:00
html titles
This commit is contained in:
@@ -7,23 +7,6 @@ import { make_session_slug_processor } from '@sveltejs/site-kit/utils/slug';
|
|||||||
import marked from 'marked';
|
import marked from 'marked';
|
||||||
import hljs from 'highlight.js';
|
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 = [
|
const block_types = [
|
||||||
'blockquote',
|
'blockquote',
|
||||||
'html',
|
'html',
|
||||||
@@ -115,15 +98,13 @@ export default function generate_docs(dir) {
|
|||||||
const slug = level <= 4 && make_slug(rawtext);
|
const slug = level <= 4 && make_slug(rawtext);
|
||||||
|
|
||||||
if (level === 3 || level === 4) {
|
if (level === 3 || level === 4) {
|
||||||
const title = unescape(
|
const title = text
|
||||||
text
|
.replace(/<\/?code>/g, '')
|
||||||
.replace(/<\/?code>/g, '')
|
.replace(/\.(\w+)(\((.+)?\))?/, (m, $1, $2, $3) => {
|
||||||
.replace(/\.(\w+)(\((.+)?\))?/, (m, $1, $2, $3) => {
|
if ($3) return `.${$1}(...)`;
|
||||||
if ($3) return `.${$1}(...)`;
|
if ($2) return `.${$1}()`;
|
||||||
if ($2) return `.${$1}()`;
|
return `.${$1}`;
|
||||||
return `.${$1}`;
|
});
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
subsections.push({ slug, title, level });
|
subsections.push({ slug, title, level });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user