Skip to content

Allow JSDoc-style @link inline tags #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/lib/models/reflections/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ export abstract class Reflection {
if (alias === '') {
alias = 'reflection-' + this.id;
}
if (this.flags && this.flags.isStatic) {
alias = 'static-' + alias;
}

let target = <Reflection> this;
while (target.parent && !target.parent.isProject() && !target.hasOwnDocument) {
Expand Down Expand Up @@ -469,11 +472,17 @@ export abstract class Reflection {
*/
getChildByName(arg: any): Reflection {
const names: string[] = Array.isArray(arg) ? arg : arg.split('.');
const name = names[0];
let name = names[0];
let result: Reflection = null;
// Did the @link tag use static syntax?
let staticLink = false;
if (name.indexOf('@static-') === 0) {
staticLink = true;
name = name.slice(8);
}

this.traverse((child) => {
if (child.name === name) {
if (child.name === name && !(staticLink && !child.flags.isStatic)) {
if (names.length <= 1) {
result = child;
} else if (child) {
Expand Down
10 changes: 8 additions & 2 deletions src/lib/models/reflections/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ export class ProjectReflection extends ContainerReflection {
*/
findReflectionByName(arg: any): Reflection {
const names: string[] = Array.isArray(arg) ? arg : arg.split('.');
const name = names.pop();
let name = names.pop();
// Did the @link tag use static syntax?
let staticLink = false;
if (name.indexOf('@static-') === 0) {
staticLink = true;
name = name.slice(8);
}

search: for (let key in this.reflections) {
const reflection = this.reflections[key];
if (reflection.name !== name) {
if (reflection.name !== name || (staticLink && !reflection.flags.isStatic)) {
continue;
}

Expand Down
17 changes: 15 additions & 2 deletions src/lib/output/plugins/MarkedLinksPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,21 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent {
private replaceInlineTags(text: string): string {
return text.replace(this.inlineTag, (match: string, leading: string, tagName: string, content: string): string => {
const split = MarkedLinksPlugin.splitLinkText(content);
const target = split.target;
const caption = leading || split.caption;
let target = split.target;
let caption = leading || split.caption;

// Convert any JSDoc-style @link syntax, replacing #s
if (caption === target) {
caption = caption.replace(/#\./, '.').replace(/#/, '.');
// Remove leading ., if there is one
if (caption.charAt(0) === '.') {
caption = caption.slice(1);
}
}
target = target.replace(/#\./, '.@static-').replace(/#/, '.');
if (target.charAt(0) === '.') {
target = target.slice(1);
}

let monospace: boolean;
if (tagName === 'linkcode') {
Expand Down
3 changes: 0 additions & 3 deletions src/lib/output/themes/DefaultTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ export class DefaultTheme extends Theme {
*/
static applyAnchorUrl(reflection: Reflection, container: Reflection) {
let anchor = DefaultTheme.getUrl(reflection, container, '.');
if (reflection['isStatic']) {
anchor = 'static-' + anchor;
}

reflection.url = container.url + '#' + anchor;
reflection.anchor = anchor;
Expand Down