UNPKG

@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>

30 lines 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.snippetsFromAsset = snippetsFromAsset; const tslib_1 = require("tslib"); const path_1 = tslib_1.__importDefault(require("path")); const code_type_from_ext_1 = require("./code-type-from-ext"); const process_legacy_snippets_1 = require("./process-legacy-snippets"); const process_snippets_1 = require("./process-snippets"); /** * Finds all snippets in an asset and returns them as assets. * @param asset - Asset * @param inlineStylesType - Inline styles type */ function snippetsFromAsset(asset, inlineStylesType) { const snippets = (0, process_legacy_snippets_1.processLegacySnippets)(asset.code).concat((0, process_snippets_1.processSnippets)(asset.code, path_1.default.dirname(asset.filePath))); const codeType = (0, code_type_from_ext_1.codeTypeFromExt)(asset.filePath); const isStylesFile = ['CSS', 'SCSS', 'LESS', 'SASS'].includes(codeType.toUpperCase()); return snippets.map(({ code, title, lang, icon, opened }, i) => { const language = lang === 'styles' ? (isStylesFile ? codeType : inlineStylesType) : lang; return { ...asset, code, title: title ?? `Snippet #${i + 1}`, icon, opened, lang: language, }; }); } //# sourceMappingURL=snippets-from-asset.js.map