Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
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: 5 additions & 3 deletions lib/renderer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ resolveImagePaths = (html, filePath) ->
o = document.createElement('div')
o.innerHTML = html
for img in o.querySelectorAll('img')
if src = img.src
# We use the raw attribute instead of the .src property because the value
# of the property seems to be transformed in some cases.
if src = img.getAttribute('src')
continue if src.match(/^(https?|atom):\/\//)
continue if src.startsWith(process.resourcesPath)
continue if src.startsWith(resourcePath)
Expand All @@ -63,9 +65,9 @@ resolveImagePaths = (html, filePath) ->
if src[0] is '/'
unless fs.isFileSync(src)
if rootDirectory
src = path.join(rootDirectory, src.substring(1))
img.src = path.join(rootDirectory, src.substring(1))
else
src = path.resolve(path.dirname(filePath), src)
img.src = path.resolve(path.dirname(filePath), src)

o.innerHTML

Expand Down
2 changes: 1 addition & 1 deletion spec/markdown-preview-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe "MarkdownPreviewView", ->
describe "when the image uses a relative path", ->
it "resolves to a path relative to the file", ->
image = preview.element.querySelector("img[alt=Image1]")
expect(image.src).toMatch url.parse(atom.project.getDirectories()[0].resolve('subdir/image1.png'))
expect(image.getAttribute('src')).toBe atom.project.getDirectories()[0].resolve('subdir/image1.png')

describe "when the image uses an absolute path that does not exist", ->
it "resolves to a path relative to the project root", ->
Expand Down