Skip to content

Commit 937ac48

Browse files
committed
Forgiving links to 404s
1 parent a598641 commit 937ac48

File tree

7 files changed

+139
-14
lines changed

7 files changed

+139
-14
lines changed

lib/output/util/reroute_links.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var visit = require('unist-util-visit');
99
*/
1010
module.exports = function rerouteLinks(getHref, ast) {
1111
visit(ast, 'link', function (node) {
12-
if (node.jsdoc && !node.url.match(/^(http|https|\.)/)) {
12+
if (node.jsdoc && !node.url.match(/^(http|https|\.)/) && getHref(node.url)) {
1313
node.url = getHref(node.url);
1414
}
1515
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "documentation",
33
"description": "a documentation generator",
4-
"version": "4.0.0-beta6",
4+
"version": "4.0.0-beta7",
55
"author": "Tom MacWright",
66
"bin": {
77
"documentation": "./bin/documentation.js"

test/fixture/html/nested.output.files

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262

263263
<p>Decide whether an object is a Klass instance
264264
This is a [klasssic]<a href="#klass">Klass</a>
265-
This is a [link to something that does not exist]<a href="">DoesNot</a></p>
265+
This is a [link to something that does not exist]<a href="DoesNot">DoesNot</a></p>
266266

267267

268268
<div class='pre p1 fill-light mt0'>isClass(other: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>, also: Any): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></div>

test/fixture/inline-link.input.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ function addOne(a) {
1212
* {@link addOne} to do the math. This demonstrates
1313
* {@link https://en.wikipedia.org/wiki/Addition Addition}
1414
* and {@link https://en.wikipedia.org/wiki/Addition}
15+
*
16+
* This link refers to nothing: {@link nothing}
17+
*
1518
* @param {number} a the input
1619
* @returns {number} numberone
1720
*/

test/fixture/inline-link.output.json

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"column": 1
9595
}
9696
},
97-
"code": "/**\n * Adds one to a number\n * @param {number} a the input\n * @returns {number} the output\n */\nfunction addOne(a) {\n return a + 1;\n}\n\n/**\n * This function returns the number one. Internally, this uses\n * {@link addOne} to do the math. This demonstrates\n * {@link https://en.wikipedia.org/wiki/Addition Addition}\n * and {@link https://en.wikipedia.org/wiki/Addition}\n * @param {number} a the input\n * @returns {number} numberone\n */\nmodule.exports = function (a) {\n return addOne(a);\n};\n"
97+
"code": "/**\n * Adds one to a number\n * @param {number} a the input\n * @returns {number} the output\n */\nfunction addOne(a) {\n return a + 1;\n}\n\n/**\n * This function returns the number one. Internally, this uses\n * {@link addOne} to do the math. This demonstrates\n * {@link https://en.wikipedia.org/wiki/Addition Addition}\n * and {@link https://en.wikipedia.org/wiki/Addition}\n *\n * This link refers to nothing: {@link nothing}\n *\n * @param {number} a the input\n * @returns {number} numberone\n */\nmodule.exports = function (a) {\n return addOne(a);\n};\n"
9898
},
9999
"errors": [],
100100
"params": [
@@ -390,6 +390,66 @@
390390
1
391391
]
392392
}
393+
},
394+
{
395+
"type": "paragraph",
396+
"children": [
397+
{
398+
"type": "text",
399+
"value": "This link refers to nothing: ",
400+
"position": {
401+
"start": {
402+
"line": 6,
403+
"column": 1,
404+
"offset": 217
405+
},
406+
"end": {
407+
"line": 6,
408+
"column": 30,
409+
"offset": 246
410+
},
411+
"indent": []
412+
}
413+
},
414+
{
415+
"type": "link",
416+
"url": "nothing",
417+
"title": null,
418+
"jsdoc": true,
419+
"children": [
420+
{
421+
"type": "text",
422+
"value": "nothing"
423+
}
424+
],
425+
"position": {
426+
"start": {
427+
"line": 6,
428+
"column": 30,
429+
"offset": 246
430+
},
431+
"end": {
432+
"line": 6,
433+
"column": 45,
434+
"offset": 261
435+
},
436+
"indent": []
437+
}
438+
}
439+
],
440+
"position": {
441+
"start": {
442+
"line": 6,
443+
"column": 1,
444+
"offset": 217
445+
},
446+
"end": {
447+
"line": 6,
448+
"column": 45,
449+
"offset": 261
450+
},
451+
"indent": []
452+
}
393453
}
394454
],
395455
"position": {
@@ -399,17 +459,17 @@
399459
"offset": 0
400460
},
401461
"end": {
402-
"line": 4,
403-
"column": 51,
404-
"offset": 215
462+
"line": 6,
463+
"column": 45,
464+
"offset": 261
405465
}
406466
}
407467
},
408468
"tags": [
409469
{
410470
"title": "param",
411471
"description": "the input",
412-
"lineNumber": 5,
472+
"lineNumber": 8,
413473
"type": {
414474
"type": "NameExpression",
415475
"name": "number"
@@ -419,7 +479,7 @@
419479
{
420480
"title": "returns",
421481
"description": "numberone",
422-
"lineNumber": 6,
482+
"lineNumber": 9,
423483
"type": {
424484
"type": "NameExpression",
425485
"name": "number"
@@ -432,28 +492,28 @@
432492
"column": 0
433493
},
434494
"end": {
435-
"line": 17,
495+
"line": 20,
436496
"column": 3
437497
}
438498
},
439499
"context": {
440500
"loc": {
441501
"start": {
442-
"line": 18,
502+
"line": 21,
443503
"column": 0
444504
},
445505
"end": {
446-
"line": 20,
506+
"line": 23,
447507
"column": 2
448508
}
449509
},
450-
"code": "/**\n * Adds one to a number\n * @param {number} a the input\n * @returns {number} the output\n */\nfunction addOne(a) {\n return a + 1;\n}\n\n/**\n * This function returns the number one. Internally, this uses\n * {@link addOne} to do the math. This demonstrates\n * {@link https://en.wikipedia.org/wiki/Addition Addition}\n * and {@link https://en.wikipedia.org/wiki/Addition}\n * @param {number} a the input\n * @returns {number} numberone\n */\nmodule.exports = function (a) {\n return addOne(a);\n};\n"
510+
"code": "/**\n * Adds one to a number\n * @param {number} a the input\n * @returns {number} the output\n */\nfunction addOne(a) {\n return a + 1;\n}\n\n/**\n * This function returns the number one. Internally, this uses\n * {@link addOne} to do the math. This demonstrates\n * {@link https://en.wikipedia.org/wiki/Addition Addition}\n * and {@link https://en.wikipedia.org/wiki/Addition}\n *\n * This link refers to nothing: {@link nothing}\n *\n * @param {number} a the input\n * @returns {number} numberone\n */\nmodule.exports = function (a) {\n return addOne(a);\n};\n"
451511
},
452512
"errors": [],
453513
"params": [
454514
{
455515
"name": "a",
456-
"lineNumber": 5,
516+
"lineNumber": 8,
457517
"description": {
458518
"type": "root",
459519
"children": [

test/fixture/inline-link.output.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ This function returns the number one. Internally, this uses
1515
[Addition](https://en.wikipedia.org/wiki/Addition)
1616
and <https://en.wikipedia.org/wiki/Addition>
1717

18+
This link refers to nothing: [nothing](nothing)
19+
1820
**Parameters**
1921

2022
- `a` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the input

test/fixture/inline-link.output.md.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,66 @@
362362
]
363363
}
364364
},
365+
{
366+
"type": "paragraph",
367+
"children": [
368+
{
369+
"type": "text",
370+
"value": "This link refers to nothing: ",
371+
"position": {
372+
"start": {
373+
"line": 6,
374+
"column": 1,
375+
"offset": 217
376+
},
377+
"end": {
378+
"line": 6,
379+
"column": 30,
380+
"offset": 246
381+
},
382+
"indent": []
383+
}
384+
},
385+
{
386+
"type": "link",
387+
"url": "nothing",
388+
"title": null,
389+
"jsdoc": true,
390+
"children": [
391+
{
392+
"type": "text",
393+
"value": "nothing"
394+
}
395+
],
396+
"position": {
397+
"start": {
398+
"line": 6,
399+
"column": 30,
400+
"offset": 246
401+
},
402+
"end": {
403+
"line": 6,
404+
"column": 45,
405+
"offset": 261
406+
},
407+
"indent": []
408+
}
409+
}
410+
],
411+
"position": {
412+
"start": {
413+
"line": 6,
414+
"column": 1,
415+
"offset": 217
416+
},
417+
"end": {
418+
"line": 6,
419+
"column": 45,
420+
"offset": 261
421+
},
422+
"indent": []
423+
}
424+
},
365425
{
366426
"type": "strong",
367427
"children": [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy