@@ -25,6 +25,18 @@ interface ISnippetsFile {
2525export class OfficeYamlDocumenter extends YamlDocumenter {
2626 private _snippets : ISnippetsFile ;
2727
28+ // Default API Set URL when no product match is found.
29+ private _apiSetUrlDefault : string = '/javascript/office/javascript-api-for-office' ;
30+
31+ // Hash set of API Set URLs based on product.
32+ private _apiSetUrls : Object = {
33+ 'Excel' : '/javascript/office/requirement-sets/excel-api-requirement-sets' ,
34+ 'OneNote' : '/javascript/office/requirement-sets/onenote-api-requirement-sets' ,
35+ 'Visio' : '/javascript/office/overview/visio-javascript-reference-overview' ,
36+ 'Outlook' : '/javascript/office/requirement-sets/outlook-api-requirement-sets' ,
37+ 'Word' : '/javascript/office/requirement-sets/word-api-requirement-sets'
38+ } ;
39+
2840 public constructor ( docItemSet : DocItemSet , inputFolder : string ) {
2941 super ( docItemSet ) ;
3042
@@ -89,18 +101,18 @@ export class OfficeYamlDocumenter extends YamlDocumenter {
89101 // Hyperlink it like this:
90102 // \[ [API set: ExcelApi 1.1](http://bing.com?type=excel) \]
91103 markup = markup . replace ( / A p i / , 'API' ) ;
92- if ( uid . search ( / E x c e l / i) !== - 1 ) {
93- return markup . replace ( / \\ \[ ( A P I s e t : [ ^ \] ] + ) \\ \] / , `\\[ [$1](http://bing.com?type=excel) \\]` ) ;
94- } else if ( uid . search ( / O n e N o t e / i) !== - 1 ) {
95- return markup . replace ( / \\ \[ ( A P I s e t : [ ^ \] ] + ) \\ \] / , `\\[ [$1](http://bing.com?type=onenote) \\]` ) ;
96- } else if ( uid . search ( / V i s i o / i) !== - 1 ) {
97- return markup . replace ( / \\ \[ ( A P I s e t : [ ^ \] ] + ) \\ \] / , `\\[ [$1](http://bing.com?type=visio) \\]` ) ;
98- } else if ( uid . search ( / O u t l o o k / i) !== - 1 ) {
99- return markup . replace ( / \\ \[ ( A P I s e t : [ ^ \] ] + ) \\ \] / , `\\[ [$1](http://bing.com?type=outlook) \\]` ) ;
100- } else if ( uid . search ( / W o r d / i) !== - 1 ) {
101- return markup . replace ( / \\ \[ ( A P I s e t : [ ^ \] ] + ) \\ \] / , `\\[ [$1](http://bing.com?type=word) \\]` ) ;
102- } else {
103- return markup . replace ( / \\ \[ ( A P I s e t : [ ^ \] ] + ) \\ \] / , `\\[ [$1](http://bing.com) \\]` ) ;
104+ return markup . replace ( / \\ \[ ( A P I s e t : [ ^ \] ] + ) \\ \] / , '\\[ [$1](' + this . _getApiSetUrl ( uid ) + ') \\]' ) ;
105+ }
106+
107+ // Gets the link to the API set based on product context. Seeks a case-insensitve match in the hash set.
108+ private _getApiSetUrl ( uid : string ) : string {
109+ for ( const key of Object . keys ( this . _apiSetUrls ) ) {
110+ const regexp : RegExp = new RegExp ( key , 'i' ) ;
111+ if ( regexp . test ( uid ) ) {
112+ return this . _apiSetUrls [ key ] ;
113+ }
104114 }
115+ return this . _apiSetUrlDefault ; // match not found.
105116 }
117+
106118}
0 commit comments