Skip to content
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

Do not remove image's styles #32

Merged
merged 1 commit into from
May 19, 2015
Merged
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
8 changes: 4 additions & 4 deletions src/tasks/override-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ function recognizeRelativeLinkForLibraryDocs(str, node) {
* @param {BaseNode} doc node
* @returns {*}
*/
function buildSrcForImages(href, doc) {
function buildSrcForImages(str, href, doc) {
var docParentUrl = doc && doc.url.replace(/\/\w*\.md/, '/'); // replace last url's part: repo/docs/a.md -> repo/docs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's a change that there's no doc, src will be broken

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but we have no another way to know whole path to img.


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

/**
Expand Down Expand Up @@ -212,8 +213,7 @@ function overrideLinks(content, node, urlHash, lang, doc) {

content = content.replace(REGEXP.SRC, function(str, href){
//if href is absolute (src="http://..." ) return href
href = /^http/.test(href) ? href : buildSrcForImages(href, doc);
return '<img src="' + href + '"';
return /^http/.test(href) ? str : buildSrcForImages(str, href, doc);
});

content = content.replace(REGEXP.HREF, function (str, href) {
Expand Down