Use uploaded images in markdown preview
This commit is contained in:
@@ -26,7 +26,7 @@ module.exports = class MarkdownImage extends BaseModel
|
||||
'empty': 'empty'
|
||||
'creatable': 'creatable'
|
||||
'unchanged': 'unchanged'
|
||||
'updateable': 'updatable'
|
||||
'updateable': 'updateable'
|
||||
}
|
||||
|
||||
constructor: (attributes={}, options={})->
|
||||
@@ -46,6 +46,12 @@ module.exports = class MarkdownImage extends BaseModel
|
||||
getFullPath: ->
|
||||
return "#{@path}/#{@fileName}"
|
||||
|
||||
getImageUrl: ->
|
||||
if @mimeType? and @encodedData?
|
||||
return "data:#{@mimeType};base64,#{@encodedData}"
|
||||
else
|
||||
return @fullPath
|
||||
|
||||
getMimeType: ->
|
||||
if not @_mimeType?
|
||||
for mimeType in MimeTypes
|
||||
@@ -57,6 +63,7 @@ module.exports = class MarkdownImage extends BaseModel
|
||||
|
||||
Object.defineProperties @prototype,
|
||||
fullPath: {get:@prototype.getFullPath}
|
||||
imageUrl: {get:@prototype.getImageUrl}
|
||||
mimeType: {get:@prototype.getMimeType}
|
||||
|
||||
# BaseModel Overrides ##########################################################################
|
||||
|
||||
@@ -30,11 +30,20 @@ module.exports = class MarkdownImageList extends BaseModel
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
getImageUrlForFile: (fileName)->
|
||||
result = @_images[fileName]?.imageUrl
|
||||
result ?= "#{@imageBase}/#{fileName}"
|
||||
return result
|
||||
|
||||
loadImages: ->
|
||||
for fileName, image of @_images
|
||||
if image.status is MarkdownImage.Status.unknown
|
||||
image.fetch()
|
||||
|
||||
reset: ->
|
||||
@_images = {}
|
||||
@_analyzeMarkdownText()
|
||||
|
||||
# Property Methods #############################################################################
|
||||
|
||||
getAll: ->
|
||||
|
||||
Reference in New Issue
Block a user