Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Preview most recent version of images #53

Merged
merged 3 commits into from
Aug 6, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 26 additions & 2 deletions lib/renderer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ roaster = null # Defer until used
pandocHelper = null # Defer until used
{scopeForFenceName} = require './extension-helper'
mathjaxHelper = require './mathjax-helper'
pathWatcher = require 'pathwatcher'

MarkdownPreviewView = null # Defer until used
isMarkdownPreviewView = (object) ->
MarkdownPreviewView ?= require './markdown-preview-view'
object instanceof MarkdownPreviewView

highlighter = null
{resourcePath} = atom.getLoadSettings()
packagePath = path.dirname(__dirname)
imgVersion = []

exports.toDOMFragment = (text='', filePath, grammar, renderLaTeX, callback) ->
render text, filePath, renderLaTeX, (error, html) ->
Expand Down Expand Up @@ -97,9 +104,26 @@ resolveImagePaths = (html, filePath) ->

if src[0] is '/'
unless fs.isFileSync(src)
img.attr('src', path.join(rootDirectory, src.substring(1)))
src = path.join(rootDirectory, src.substring(1))
else
src = path.resolve(path.dirname(filePath), src)

# Use most recent version of image
if imgVersion[src]?
if imgVersion[src] > 0
src = "#{src}##{imgVersion[src]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like "#{src}?v=#{imgVersion[src]}" more 👍

else
img.attr('src', path.resolve(path.dirname(filePath), src))
imgVersion[src] = 0
srcClosure = (src) ->
return _.debounce(((event, path) ->
imgVersion[src] += 1
for item in atom.workspace.getPaneItems()
if isMarkdownPreviewView(item)
item.renderMarkdown()
return), 250)
pathWatcher.watch src, srcClosure(src)

img.attr('src', src)

o.html()

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"fs-plus": "^2.0.0",
"grim": "^1.2.1",
"highlights": "^1.0.0",
"pathwatcher": "^4.3",
"pathwatcher": "^4.4.3",
"pdc": "~0.2.2",
"roaster": "https://github.com/Galadirith/roaster/tarball/marked-mathjax",
"temp": "^0.8.1",
Expand Down