···
-
import type { List, ListItem, PhrasingContent, Root } from 'mdast';
import { unified } from 'unified';
import { visit } from 'unist-util-visit';
import { defaultSchema as defaultSanitizeSchema } from 'hast-util-sanitize';
···
import remarkGfm from 'remark-gfm';
import remarkParse from 'remark-parse';
import remarkSqueezeParagraphs from 'remark-squeeze-paragraphs';
-
import remarkTitle from 'remark-title';
export async function sanitizeHtml(html: string): Promise<string> {
const vfile = await unified()
···
function extractTitle(markdown: string): string | null {
-
let depth: number | null = null;
-
let title: string | null = null;
-
const toString = (nodes: PhrasingContent[]): string =>
-
return toString(node.children);
-
return `\`${node.value}\``;
-
case 'footnoteReference':
.use(remarkParse, { fragment: true })
···
-
visit(tree, function (node) {
-
if (node.type !== 'heading')
-
if (!depth || node.depth < depth)
-
title = toString(node.children);
export async function transferTitle(from: string, to: string): Promise<string> {
···
incrementListMarker: false,
···
+
import type { Heading, List, ListItem, PhrasingContent, Root } from 'mdast';
import { unified } from 'unified';
import { visit } from 'unist-util-visit';
import { defaultSchema as defaultSanitizeSchema } from 'hast-util-sanitize';
···
import remarkGfm from 'remark-gfm';
import remarkParse from 'remark-parse';
import remarkSqueezeParagraphs from 'remark-squeeze-paragraphs';
+
const toString = (nodes: PhrasingContent[]): string =>
+
return toString(node.children);
+
return `\`${node.value}\``;
+
case 'footnoteReference':
export async function sanitizeHtml(html: string): Promise<string> {
const vfile = await unified()
···
function extractTitle(markdown: string): string | null {
.use(remarkParse, { fragment: true })
···
+
const node = tree.children[0];
+
if (node && node.type === 'heading' && node.depth === 1) {
+
return toString(node.children);
+
function remarkTitle(opts: { title: string }) {
+
return function checkTitleTransformer(root: Root) {
+
const node = root.children[0]!;
+
const replacement: Heading = {
+
{ type: 'text', value: opts.title }
+
if (node && node.type === 'heading') {
+
node.children = replacement.children;
+
root.children?.unshift(replacement);
export async function transferTitle(from: string, to: string): Promise<string> {
···
+
.use(remarkTitle, { title })
incrementListMarker: false,