@ng-doc/builder
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
67 lines • 2.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processLegacySnippets = processLegacySnippets;
const core_1 = require("@ng-doc/core");
const HTMLSnippetStart = /^.*(<!--\s*NgDocHTMLSnippetStart(\(.+\))?\s*-->).*$/gm;
const StylesSnippetStart = /^.*(\/\*\s*NgDocStyleSnippetStart(\(.+\))?\s*\*\/).*$/gm;
const TypeScriptSnippetStart = /^.*(\/\*\s*NgDocCodeSnippetStart(\(.+\))?\s*\*\/).*$/gm;
const HTMLSnippetEnd = (group = '', escape = true) => new RegExp(`^.*(<!--\\s*NgDocHTMLSnippetEnd(\\(${escape ? (0, core_1.escapeRegexp)(group) : group}\\))?\\s*-->).*$`, 'gm');
const StylesSnippetEnd = (group = '', escape = true) => new RegExp(`^.*(\\/\\*\\s*NgDocStyleSnippetEnd(\\(${escape ? (0, core_1.escapeRegexp)(group) : group}\\))?\\s*\\*\\/).*$`, 'gm');
const TypeScriptSnippetEnd = (group = '', escape = true) => new RegExp(`^.*(\\/\\*\\s*NgDocCodeSnippetEnd(\\(${escape ? (0, core_1.escapeRegexp)(group) : group}\\))?\\s*\\*\\/).*$`, 'gm');
/**
* Finds and return all the snippets in the given string.
* @deprecated - Use `processSnippets` instead
* @param content - Content
* @returns - Array of snippets
*/
function processLegacySnippets(content) {
return [
...findSnippet(content, 'angular-html', HTMLSnippetStart, HTMLSnippetEnd),
...findSnippet(content, 'styles', StylesSnippetStart, StylesSnippetEnd),
...findSnippet(content, 'angular-ts', TypeScriptSnippetStart, TypeScriptSnippetEnd),
];
}
/**
* Finds the snippets in the given content.
* @param content - Content
* @param type - Snippet type
* @param snippetStart - Snippet start
* @param snippetEnd - Snippet end
*/
function findSnippet(content, type, snippetStart, snippetEnd) {
const snippets = [];
const startRegexp = new RegExp(snippetStart);
let matchStart;
// eslint-disable-next-line no-cond-assign
while ((matchStart = startRegexp.exec(content))) {
const group = matchStart[2]?.slice(1, matchStart[2].length - 1);
const matchEnd = snippetEnd(group).exec(content);
if (matchEnd) {
const snippetCode = content
.slice(matchStart.index + matchStart[0].length, matchEnd.index)
.trim();
if (snippetCode) {
snippets.push({
code: removeSnippetsInCode(snippetCode),
title: group,
lang: type,
});
}
}
}
return snippets;
}
/**
* Removes the snippets from the given code.
* @param code - Code
*/
function removeSnippetsInCode(code) {
return code
.replace(HTMLSnippetStart, '')
.replace(StylesSnippetStart, '')
.replace(TypeScriptSnippetStart, '')
.replace(HTMLSnippetEnd('.*', false), '')
.replace(StylesSnippetEnd('.*', false), '')
.replace(TypeScriptSnippetEnd('.*', false), '');
}
//# sourceMappingURL=process-legacy-snippets.js.map