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

Commit

Permalink
Preview most recent version of images
Browse files Browse the repository at this point in the history
This is a WIP towards #49
  • Loading branch information
Galadirith committed Aug 5, 2015
1 parent 88100d6 commit 22d1fdc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
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]}"
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

0 comments on commit 22d1fdc

Please sign in to comment.