2017-03-19 07:14:17 -04:00
|
|
|
/**
|
|
|
|
* @dgProcessor fixInternalDocumentLinks
|
|
|
|
* @description
|
|
|
|
* Add in the document path to links that start with a hash.
|
|
|
|
* This is important when the web app has a base href in place,
|
|
|
|
* since links like: `<a href="#some-id">` would get mapped to
|
|
|
|
* the URL `base/#some-id` even if the current location is `base/some/doc`.
|
|
|
|
*/
|
|
|
|
module.exports = function fixInternalDocumentLinks() {
|
|
|
|
|
2017-03-21 07:27:39 -04:00
|
|
|
var INTERNAL_LINK = /(<a [^>]*href=")(#[^"]*)/g;
|
2017-03-19 07:14:17 -04:00
|
|
|
|
|
|
|
return {
|
|
|
|
$runAfter: ['inlineTagProcessor'],
|
2017-04-19 11:03:15 -04:00
|
|
|
$runBefore: ['convertToJsonProcessor'],
|
2017-03-19 07:14:17 -04:00
|
|
|
$process: function(docs) {
|
|
|
|
docs.forEach(doc => {
|
|
|
|
doc.renderedContent = doc.renderedContent.replace(INTERNAL_LINK, (_, pre, hash) => {
|
|
|
|
return pre + doc.path + hash;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|