Skip to content

Commit

Permalink
Merge 2dac793 into e86872e
Browse files Browse the repository at this point in the history
  • Loading branch information
Gela committed Jul 14, 2015
2 parents e86872e + 2dac793 commit c7d708f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/tasks/override-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ var util = require('util'),
DOC: /^\.?\/?(?:\.\.\/)+?([\w|-]+)\.?[md|html|ru\.md|en\.md]?/,
VERSION_DOC: /^\.?\/?(\d+\.\d+\.\d+)\-([\w|-]+)?\.?[md|html|ru\.md|en\.md]?/,
BLOCK: /^\.\.?\/([\w|-]+)\/?([\w|-]+)?\.?[md|html|ru\.md|en\.md]?/,
BLOCKS: /^\.?\/?(?:\.\.\/)?([\w|-]+)\.blocks\/([\w|-]+)\/?([\w|-]+)?\.?[md|html|ru\.md|en\.md]?/,
BLOCKS: /^\.?\/?(?:\.\.\/)?([\w|-]+)\.blocks\/([\w|-]+)\/?([\w|-]+)?\.[md|html|ru\.md|en\.md]/,
LEVEL: /^\.\.?\/\.\.\/([\w|-]+)\.blocks\/([\w|-]+)\/?([\w|-]+)?\.?[md|html|ru\.md|en\.md]?/,
BLOCK_FILES: /^\.?\/?(?:\.\.\/)?([\w|-]+)\.blocks\/([\w|-]+)\/?([\w|-]+)?\.(?![md|html|ru\.md|en\.md])/,
JSON: /\w+\.json/
}
};
Expand Down Expand Up @@ -156,6 +157,12 @@ function recognizeRelativeLinkForLibraryDocs(str, node) {
[util.format('/libs/%s/%s/%s', lib, version, match[1])];
}

// ../../popup/popup.js
match = str.match(REGEXP.RELATIVE.BLOCK_FILES);
if (match) {
return node.ghLibVersionUrl + '/blob/' + version + str;
}

return [str];
}

Expand All @@ -171,7 +178,7 @@ function buildSrcForImages(str, href, doc, node) {
src = (doc ? docParentUrl : absoluteLink) + href;

// change only src, save styles and attrs
return str = str.replace(/src=("|')?.+("|')?/g, 'src="' + src + '?raw=true"')
return str.replace(/src=("|')?.+("|')?/g, 'src="' + src + '?raw=true"')
}

/**
Expand Down Expand Up @@ -261,8 +268,10 @@ function overrideLinks(content, node, urlHash, lang, doc) {
links.push(href.replace(/\/tree\//, '/blob/'));
links.push(href.replace(/\/blob\//, '/tree/'));
} else {
links.push(buildFullGithubLinkForDocs(href, doc, 'tree', node));
links.push(buildFullGithubLinkForDocs(href, doc, 'blob', node));
if(href.match(REGEXP.RELATIVE.JSON) || doc && doc.repo) {
links.push(buildFullGithubLinkForDocs(href, doc, 'tree', node));
links.push(buildFullGithubLinkForDocs(href, doc, 'blob', node));
}
links = links.concat(recognizeRelativeLinkForLibraryDocs(href, node));
if (node.source && node.source.data) {
links.push(recognizeRelativeBlockLinkOnSameLevel(href, node));
Expand Down

0 comments on commit c7d708f

Please sign in to comment.