import { isHeadLayoutStart, isMultColumn, isMultColumnEnd, isMultColumnStart } from "../../utils/index"; import parseHeadLayout from "./parseHeadLayout"; import { ITransformOptions, markdownToHTML } from "./parseToHTML"; export default function parseLayout(templates: string[], i: number, templateLength: number, options: ITransformOptions) { let resultStr = `
`, tmpS = ''; ++i; while (i < templateLength && !isMultColumnEnd(templates[i])) { if (isMultColumnStart(templates[i])) { const { result, startIdx } = parseLayout(templates, i, templateLength, options); tmpS += result; i = startIdx; } else if (isHeadLayoutStart(templates[i])) { const { result, startIdx } = parseHeadLayout(templates, i, templateLength, options) tmpS += result; i = startIdx; } else if (isMultColumn(templates[i])) { resultStr += `
${markdownToHTML(tmpS, { ...options, xss: false })}
`; tmpS = ''; } else { tmpS += templates[i].trim() ? '\n' + templates[i] + '\n' : ''; } i++; } resultStr += `
${markdownToHTML(tmpS, { ...options, xss: false })}
`; resultStr += `
`; return { result: resultStr, startIdx: i } }