Comparing version 7.0.0-0 to 7.0.0-1
@@ -9,2 +9,3 @@ const arrayify = require('array-back') | ||
const state = require('../lib/state') | ||
const urlRe = require('regex-repo').urlRe | ||
@@ -624,13 +625,14 @@ let malformedDataWarningIssued = false | ||
* @param {string} - a string containing one or more {@link} tags | ||
* @returns {Array.<{original: string, caption: string, url: string}>} | ||
* @param {object} - `dmdOptions`; link formatting is influenced by the `clever-links` and `monospace-links` values | ||
* @returns {Array.<{original: string, caption: string, url: string, format: 'code'|'plain'}>} | ||
* @static | ||
*/ | ||
function parseLink (text) { | ||
function parseLink (text, dmdOptions = {}) { | ||
if (!text) return '' | ||
const results = [] | ||
let matches = null | ||
const link1 = /{@link\s+([^\s}|]+?)\s*}/g // {@link someSymbol} | ||
const link2 = /\[([^\]]+?)\]{@link\s+([^\s}|]+?)\s*}/g // [caption here]{@link someSymbol} | ||
const link3 = /{@link\s+([^\s}|]+?)\s*\|([^}]+?)}/g // {@link someSymbol|caption here} | ||
const link4 = /{@link\s+([^\s}|]+?)\s+([^}|]+?)}/g // {@link someSymbol Caption Here} | ||
const link1 = /{@link(code|plain)?\s+([^\s}|]+?)\s*}/g // {@link someSymbol} | ||
const link2 = /\[([^\]]+?)\]{@link(code|plain)?\s+([^\s}|]+?)\s*}/g // [caption here]{@link someSymbol} | ||
const link3 = /{@link(code|plain)?\s+([^\s}|]+?)\s*\|([^}]+?)}/g // {@link someSymbol|caption here} | ||
const link4 = /{@link(code|plain)?\s+([^\s}|]+?)\s+([^}|]+?)}/g // {@link someSymbol Caption Here} | ||
@@ -640,4 +642,5 @@ while ((matches = link4.exec(text)) !== null) { | ||
original: matches[0], | ||
caption: matches[2], | ||
url: matches[1] | ||
caption: matches[3], | ||
url: matches[2], | ||
format: matches[1] | ||
}) | ||
@@ -650,4 +653,5 @@ text = text.replace(matches[0], ' '.repeat(matches[0].length)) | ||
original: matches[0], | ||
caption: matches[2], | ||
url: matches[1] | ||
caption: matches[3], | ||
url: matches[2], | ||
format: matches[1] | ||
}) | ||
@@ -661,3 +665,4 @@ text = text.replace(matches[0], ' '.repeat(matches[0].length)) | ||
caption: matches[1], | ||
url: matches[2] | ||
url: matches[3], | ||
format: matches[2] | ||
}) | ||
@@ -670,7 +675,22 @@ text = text.replace(matches[0], ' '.repeat(matches[0].length)) | ||
original: matches[0], | ||
caption: matches[1], | ||
url: matches[1] | ||
caption: matches[2], | ||
url: matches[2], | ||
format: matches[1] | ||
}) | ||
text = text.replace(matches[0], ' '.repeat(matches[0].length)) | ||
} | ||
results.forEach((result) => { | ||
const format = result.format | ||
if (format === undefined) { | ||
result.format = format // if tag is @linkplain or @linkcode, then that determines the format | ||
// else, if 'clever-links' is true, then if the link is a URL, it's plain, otherwise code format | ||
|| (dmdOptions['clever-links'] && (urlRe.test(result.url) ? 'plain' : 'code')) | ||
// else, if 'monospace-links' is true, then all links are code format | ||
|| (dmdOptions['monospace-links'] && 'code') | ||
// else, it's a plain | ||
|| 'plain' | ||
} | ||
}) | ||
return results | ||
@@ -677,0 +697,0 @@ } |
@@ -43,12 +43,14 @@ const ddata = require('./ddata') | ||
/** | ||
replaces {@link} tags with markdown links in the suppied input text | ||
replaces {@link}, {@linkplain}, and {@linkcode} tags with markdown links in the supplied input text | ||
*/ | ||
function inlineLinks (text, options) { | ||
if (text) { | ||
const links = ddata.parseLink(text) | ||
const dmdOptions = options.data.root.options | ||
const links = ddata.parseLink(text, dmdOptions) | ||
links.forEach(function (link) { | ||
const captionFmt = link.format === 'code' ? '`' : '' | ||
const linked = ddata._link(link.url, options) | ||
if (link.caption === link.url) link.caption = linked.name | ||
if (linked.url) link.url = linked.url | ||
text = text.replace(link.original, '[' + link.caption + '](' + link.url + ')') | ||
text = text.replace(link.original, '[' + captionFmt + link.caption + captionFmt + '](' + link.url + ')') | ||
}) | ||
@@ -55,0 +57,0 @@ } |
@@ -84,2 +84,16 @@ /** | ||
/** | ||
* If true, \{@link XXX} tags are rendered in normal text if XXX is a URL and monospace (code) format otherwise. | ||
* @type {boolean} | ||
* @dafult | ||
*/ | ||
this['clever-links'] = false | ||
/** | ||
* If true, all \{@link} tags are rendered in monospace (code) format. This setting is ignored in `clever-links` is true. | ||
* @type {boolean} | ||
* @default | ||
*/ | ||
this['monospace-links'] = false | ||
/** | ||
* Show identifiers marked `@private` in the output. | ||
@@ -86,0 +100,0 @@ * @type {boolean} |
{ | ||
"name": "dmd", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "7.0.0-0", | ||
"version": "7.0.0-1", | ||
"description": "The default output template for jsdoc-to-markdown", | ||
@@ -39,2 +39,3 @@ "license": "MIT", | ||
"reduce-without": "^1.0.1", | ||
"regex-repo": "^5.0.0", | ||
"test-value": "^3.0.0", | ||
@@ -41,0 +42,0 @@ "walk-back": "^5.1.1" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77340
1702
13
+ Addedregex-repo@^5.0.0
+ Addedregex-repo@5.0.1(transitive)