import { type IListItem } from "../lib/core/parseListItem"; import { parseNormalText } from "../lib/core/parseText"; // 正则 export const matchTitle: RegExp = /(#+)\s(.*)/g, matchOrderList = /^\s*(\d+)\.\s(.+)/, matchSuperLink = /\[(.*)\]\((.*)\)/, matchImage = /!\[(.*)\]\((.*)\)/; export function processFormat(list: string[]) { // 多个换行合并为一个 if (/^\s+/.test(list[0])) { list[0] = list[0].replace(/^(\s+)/g, ($1) => "\n"); } // 如果第一个元素没有换行符 那么就给他加上(后续的判断需要依赖换行符) if (!list[0].startsWith("\n")) { list[0] = "\n" + list[0]; } } // 有序列表无序列表的生成 function processListItem(nodes: IListItem[], order: boolean) { let s = order ? "
    " : "
" : ""; return s; } export function genTemplateStringOfNodes(nodes: IListItem[]) { let s = "", i = 0, n = nodes.length; if (n === 0) return ""; while (i < n) { const order_list = [], no_order_list = []; while (i < n && nodes[i].type === "no_order") { no_order_list.push(nodes[i]); i++; } s += processListItem(no_order_list, false); while (i < n && nodes[i].type === "order") { order_list.push(nodes[i]); i++; } s += processListItem(order_list, true); } return s.replace(/