@@ -2,38 +2,59 @@ var path = require('canonical-path');
22var fs = require ( "fs" ) ;
33var jsonFile = require ( 'jsonfile' ) ;
44
5- var INLINE_LINK = / ( \S + ) (?: \s + ( [ \s \S ] + ) ) ? / ;
6-
75/**
8- * @dgService linkDevGuideInlineTagDef
6+ * @dgService linkDocsInlineTagDef
97 * @description
10- * Process inline link tags (of the form {@linkDevGuide some/uri 'Some Title'}), replacing them with HTML anchors.
11- * The uri should point to a jade page in the DevGuide without the .jade extension ( under public/docs ).
8+ * Process inline link tags (of the form {@linkDocs some/uri 'Some Title'}), replacing them with HTML anchors.
9+ * The uri should point to a jade page in the Docs without the .jade extension ( under public/docs ).
1210 * If the title is omitted an attempt will be made to determine the title of the jade page being pointed to. If not found
1311 * the the title will simply be the last part of the link.
1412 * Examples
15- * {@linkDevGuide ts/latest/guide/gettingStarted }
16- * {@linkDevGuide js/latest/guide/gettingStarted 'Javascript version of getting started' }
17- * {@linkDevGuide ts/latest/guide/gettingStarted title="Typescript version of getting started" }
13+ * {@linkDocs guide/gettingStarted 'QuickStart'}
14+ * {@linkDocs ts/latest/guide/quickstart }
15+ * {@linkDocs js/latest/guide/quickstart 'Javascript version of getting started' }
16+ * {@linkDocs ts/latest/guide/quickstart title="Typescript version of getting started" }
1817 * @kind function
18+ * @property {string } lang Default docs API page language when not explicitly given in URI; one of ts|js|dart.
19+ * @property {string } vers Default docs version. Currently only 'latest'.
1920 */
20- module . exports = function linkDevGuideInlineTagDef ( parseArgString , createDocMessage , log ) {
21- return {
22- name : 'linkDevGuide' ,
23- description : 'Process inline link tags (of the form {@link some/uri "Some Title"}), replacing them with HTML anchors' ,
24- handler : function ( doc , tagName , tagDescription ) {
21+ module . exports = function linkDocsInlineTagDef ( parseArgString , createDocMessage , log ) {
22+ var _self = {
23+ name : 'linkDocs' ,
24+ lang : 'ts' ,
25+ vers : 'latest' ,
26+ description : 'Process inline link tags (of the form {@linkDocs some/uri [title=]"Some Title"}), replacing them with HTML anchors' ,
2527
28+ handler : function ( doc , tagName , tagDescription ) {
2629 // Parse out the uri and title
2730 var tagArgs = parseArgString ( tagDescription ) ;
2831 var unnamedArgs = tagArgs . _ ;
2932 var uri = unnamedArgs [ 0 ] ;
3033 var title = tagArgs . title || ( unnamedArgs . length > 1 ? unnamedArgs [ 1 ] : null ) ;
3134
35+ // Are there parameters and/or an anchor?
36+ var matches , paramAnchor = '' ;
37+ if ( matches = uri . match ( / ( [ ^ \# \? ] * ) ( [ \# \? ] .* ) / ) ) {
38+ uri = matches [ 1 ] ;
39+ paramAnchor = matches [ 2 ] ;
40+ }
41+
42+ // Is this a chapter-relative uri like 'guide/...'?
43+ if ( ! uri . match ( / ^ ( t s | j s | d a r t ) / ) ) {
44+ var lang = _self . lang ;
45+ var vers = _self . vers ;
46+ var prevUri = uri ;
47+ uri = path . join ( lang , vers , uri ) ;
48+ log . info ( 'Ajusted linkDocs chapter-relative uri (' + doc . fileInfo . baseName + '): ' + prevUri + ' -> ' + uri ) ;
49+ }
50+
51+ var isValid = false ;
3252 var jadePath = path . join ( './public/docs' , uri + '.jade' ) ;
3353 var key = path . basename ( jadePath , '.jade' ) ;
3454 if ( ! fs . existsSync ( jadePath ) ) {
35- log . warn ( createDocMessage ( 'Invalid DevGuide example (unable to locate jade file: "' + jadePath + '")' , doc ) ) ;
55+ log . warn ( createDocMessage ( 'Invalid docs link (unable to locate jade file: "' + jadePath + '")' , doc ) ) ;
3656 } else {
57+ isValid = true ;
3758 if ( ! title ) {
3859 var jsonFilePath = path . join ( path . dirname ( jadePath ) , '_data.json' ) ;
3960 if ( fs . existsSync ( jsonFilePath ) ) {
@@ -42,12 +63,13 @@ module.exports = function linkDevGuideInlineTagDef(parseArgString, createDocMess
4263 }
4364 }
4465 }
45- var url = path . join ( '/docs' , uri + '.html' ) ;
66+ var url = path . join ( '/docs' , uri + '.html' + paramAnchor ) ;
4667 title = title || key || url ;
4768
48- return "<a href='" + url + "'>" + title + "</a>" ;
49-
69+ return isValid ?
70+ '<a href="' + url + '">' + title + '</a>' :
71+ '<span>' + title + '</span>' ;
5072 }
5173 } ;
74+ return _self ;
5275} ;
53-
0 commit comments