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yGC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport colors from 'colors';\nimport * as path from 'path';\nimport yaml = require('js-yaml');\n\nimport type { ApiModel } from '@microsoft/api-extractor-model';\nimport { FileSystem } from '@rushstack/node-core-library';\n\nimport type { IYamlTocItem } from '../yaml/IYamlTocFile';\nimport type { IYamlItem } from '../yaml/IYamlApiFile';\nimport { YamlDocumenter } from './YamlDocumenter';\n\ninterface ISnippetsFile {\n /**\n * The keys are API names like \"Excel.Range.clear\".\n * The values are TypeScript source code excerpts.\n */\n [apiName: string]: string[];\n}\n\n/**\n * Extends YamlDocumenter with some custom logic that is specific to Office Add-ins.\n */\nexport class OfficeYamlDocumenter extends YamlDocumenter {\n private _snippets: ISnippetsFile;\n private _snippetsAll: ISnippetsFile;\n\n // Default API Set URL when no product match is found.\n private _apiSetUrlDefault: string = '/office/dev/add-ins/reference/javascript-api-for-office';\n\n // Hash set of API Set URLs based on product.\n private _apiSetUrls: Record<string, string> = {\n Excel: '/javascript/api/requirement-sets/excel/excel-api-requirement-sets',\n OneNote: '/javascript/api/requirement-sets/onenote/onenote-api-requirement-sets',\n Outlook: '/javascript/api/requirement-sets/outlook/outlook-api-requirement-sets',\n PowerPoint: '/javascript/api/requirement-sets/powerpoint/powerpoint-api-requirement-sets',\n Visio: '/office/dev/add-ins/reference/overview/visio-javascript-reference-overview',\n Word: '/javascript/api/requirement-sets/word/word-api-requirement-sets'\n };\n\n public constructor(apiModel: ApiModel, inputFolder: string, newDocfxNamespaces?: boolean) {\n super(apiModel, newDocfxNamespaces);\n\n const snippetsFilePath: string = path.join(inputFolder, 'snippets.yaml');\n\n console.log('Loading snippets from ' + snippetsFilePath);\n\n const snippetsContent: string = FileSystem.readFile(snippetsFilePath);\n this._snippets = yaml.load(snippetsContent, { filename: snippetsFilePath });\n this._snippetsAll = yaml.load(snippetsContent, { filename: snippetsFilePath });\n }\n\n /** @override */\n public generateFiles(outputFolder: string): void {\n super.generateFiles(outputFolder);\n\n // After we generate everything, check for any unused snippets\n console.log();\n for (const apiName of Object.keys(this._snippets)) {\n console.error(colors.yellow('Warning: Unused snippet ' + apiName));\n }\n }\n\n /** @override */\n protected onGetTocRoot(): IYamlTocItem {\n // override\n return {\n name: 'API reference',\n href: 'overview.md',\n items: []\n };\n }\n\n /** @override */\n protected onCustomizeYamlItem(yamlItem: IYamlItem): void {\n const nameWithoutPackage: string = yamlItem.uid.replace(/^[^.]+\\!/, '');\n if (yamlItem.summary) {\n yamlItem.summary = this._fixupApiSet(yamlItem.summary, yamlItem.uid);\n }\n if (yamlItem.remarks) {\n yamlItem.remarks = this._fixupApiSet(yamlItem.remarks, yamlItem.uid);\n }\n\n const snippets: string[] | undefined = this._snippetsAll[nameWithoutPackage];\n if (snippets) {\n delete this._snippets[nameWithoutPackage];\n const snippetText: string = this._generateExampleSnippetText(snippets);\n if (yamlItem.remarks) {\n yamlItem.remarks += snippetText;\n } else if (yamlItem.syntax && yamlItem.syntax.return) {\n if (!yamlItem.syntax.return.description) {\n yamlItem.syntax.return.description = '';\n }\n yamlItem.syntax.return.description += snippetText;\n } else {\n yamlItem.remarks = snippetText;\n }\n }\n }\n\n private _fixupApiSet(markup: string, uid: string): string {\n // Search for a pattern such as this:\n // \\[Api set: ExcelApi 1.1\\]\n //\n // Hyperlink it like this:\n // \\[ [API set: ExcelApi 1.1](http://bing.com?type=excel) \\]\n markup = markup.replace(/Api/, 'API');\n return markup.replace(/\\\\\\[(API set:[^\\]]+)\\\\\\]/, '\\\\[ [$1](' + this._getApiSetUrl(uid) + ') \\\\]');\n }\n\n // Gets the link to the API set based on product context. Seeks a case-insensitive match in the hash set.\n private _getApiSetUrl(uid: string): string {\n for (const key of Object.keys(this._apiSetUrls)) {\n const regexp: RegExp = new RegExp(key, 'i');\n if (regexp.test(uid)) {\n return this._apiSetUrls[key];\n }\n }\n return this._apiSetUrlDefault; // match not found.\n }\n\n private _generateExampleSnippetText(snippets: string[]): string {\n const text: string[] = ['\\n\\n#### Examples\\n'];\n for (const snippet of snippets) {\n text.push(`\\`\\`\\`TypeScript\\n${snippet}\\n\\`\\`\\``);\n }\n return text.join('\\n');\n }\n}\n"]}
\No newline at end of file