Skip to content

Commit 8d6101d

Browse files
committed
Fix internal linking
1 parent f12c503 commit 8d6101d

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

internal/documentation/jsdoc-to-markdown.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ class MarkdownDocFile extends HTMLUtils {
123123
});
124124

125125
// 2. Parse content
126-
this.markdownElements = this.#parseSections(this.findHTMLTag(html, "article").node);
126+
const articleResult = this.findHTMLTag(html, "article");
127+
if (articleResult.found && articleResult.node) {
128+
this.markdownElements = this.#parseSections(articleResult.node);
129+
} else {
130+
this.markdownElements = [];
131+
}
127132

128133
return this;
129134
}

internal/documentation/jsdoc/docdash/publish.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,6 @@ exports.publish = function(taffyData, opts, tutorials) {
520520
).concat(files),
521521
indexUrl);
522522

523-
// common nav generation, no need for templating here, we already have full html
524-
if (docdash.commonNav) {
525-
fs.writeFileSync(path.join(outdir, 'nav.inc.html'), view.nav, 'utf8');
526-
}
527-
528523
// set up the lists that we'll use to generate pages
529524
var classes = taffy(members.classes);
530525
var modules = taffy(members.modules);
@@ -596,7 +591,7 @@ exports.publish = function(taffyData, opts, tutorials) {
596591
function linkTo(longname, linkText, cssClass, fragmentId) {
597592
const classString = cssClass ? util.format(' class="%s"', cssClass) : '';
598593
let fileUrl;
599-
const fragmentString = fragmentId ? `#${fragmentId}` : '';
594+
let fragmentString = fragmentId ? `#${fragmentId}` : '';
600595
let stripped;
601596
let text;
602597

@@ -621,14 +616,24 @@ function linkTo(longname, linkText, cssClass, fragmentId) {
621616
fileUrl = helper.longnameToUrl[longname] || '';
622617
text = linkText || longname;
623618

619+
// If the URL contains a fragment (hash), extract it
620+
if (fileUrl && fileUrl.indexOf('#') > -1) {
621+
const parts = fileUrl.split('#');
622+
fileUrl = parts[0];
623+
// Only use the URL's fragment if no explicit fragmentId was provided
624+
if (!fragmentId) {
625+
fragmentString = '#' + parts[1];
626+
}
627+
}
628+
624629
// Convert source file links to GitHub URLs if configured
625630
if (fileUrl && githubSourceBaseUrl && (fileUrl.endsWith('.js.md') || longname.endsWith('.js'))) {
626631
fileUrl = convertSourceLinkToGitHub(fileUrl, longname);
627632
}
628633
// Remove .md extension from internal links for VitePress compatibility
629634
// Handle both cases: with and without fragment identifiers
630635
else if (fileUrl) {
631-
fileUrl = fileUrl.replace(/\.md(#|$)/, '$1');
636+
fileUrl = fileUrl.replace(/\.md$/, '');
632637
}
633638
}
634639

internal/documentation/jsdoc/docdash/tmpl/members.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?js
22
var data = obj;
33
var self = this;
4+
var signature = data.signature ? data.signature : '';
5+
// Check if signature already contains closing </div>, if so don't add another one
6+
var hasClosingDiv = signature.includes('</div>');
47
?>
5-
#### <?js= data.attribs + name + (data.signature ? data.signature : '') ?>
8+
#### <div class='jsdoc-object' id='<?js= data.id ?>'><?js= data.attribs.replace(/<div class='jsdoc-object'>/, '').replace(/<\/div>$/, '') + name + signature + (hasClosingDiv ? '' : '</div>') ?>
69

710
<?js if (data.summary) { ?>
811
<?js= summary ?>

internal/documentation/jsdoc/docdash/tmpl/method.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var self = this;
77
## Constructor
88
<?js } ?>
99

10-
#### <?js= data.attribs ?><?js
10+
#### <div class='jsdoc-object' id='<?js= data.id ?>'><?js= data.attribs.replace(/<div class='jsdoc-object'>/, '') ?><?js
1111
if(kind === 'class' && name.indexOf('module:') === 0) {
1212
print('new (require("' + name.slice(7) + '"))');
1313
} else if(kind === 'class') {
@@ -79,7 +79,7 @@ var self = this;
7979
<?js }); ?>
8080
<?js } ?>
8181

82-
<?js if (data.modifies && modifies.length) {?>
82+
<?js if (data.modifies && modifies.length) {?>
8383
##### Modifies:
8484
<?js if (modifies.length > 1) { ?>
8585
<?js modifies.forEach(function(m) { ?>
@@ -115,7 +115,7 @@ var self = this;
115115
<?js });
116116
} } ?>
117117

118-
<?js if (data.yields && yields.length) { ?>
118+
<?js if (data.yields && yields.length) { ?>
119119
##### Yields:
120120
<?js if (yields.length > 1) { ?>
121121
<?js yields.forEach(function(r) { ?>

internal/documentation/jsdoc/jsdoc-workspace.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@
6363
"id": "github_link"
6464
}
6565
},
66-
"githubSourceBaseUrl": "https://github.com/UI5/cli/blob/main"
66+
"githubSourceBaseUrl": "https://github.com/UI5/cli/blob/main/packages"
6767
}
6868
}

internal/documentation/jsdoc/jsdoc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@
6262
"id": "github_link"
6363
}
6464
},
65-
"githubSourceBaseUrl": "https://github.com/UI5/cli/blob/main"
65+
"githubSourceBaseUrl": "https://github.com/UI5/cli/blob/main/pacakges/"
6666
}
6767
}

0 commit comments

Comments
 (0)