Allow preview of editor if grammar is source.gfm

Previously only markdow file extensions were considered
but any editor whose grammar is GitHub Markdow should have
preview enabled.

Closes #277
This commit is contained in:
Kevin Sawicki
2013-02-14 09:49:03 -08:00
parent b8b989a94c
commit bcaa1a6819
2 changed files with 18 additions and 5 deletions

View File

@@ -26,7 +26,7 @@ class MarkdownPreviewView extends ScrollView
@attach()
attach: ->
return unless @isMarkdownFile(@getActivePath())
return unless @isMarkdownEditor()
rootView.append(this)
@markdownBody.html(@getLoadingHtml())
@loadHtml()
@@ -39,9 +39,6 @@ class MarkdownPreviewView extends ScrollView
rootView.focus()
@detaching = false
getActivePath: ->
rootView.getActiveEditor()?.getPath()
getActiveText: ->
rootView.getActiveEditor()?.getText()
@@ -76,5 +73,8 @@ class MarkdownPreviewView extends ScrollView
setHtml: (html) ->
@markdownBody.html(html) if @hasParent()
isMarkdownFile: (path) ->
isMarkdownEditor: (path) ->
editor = rootView.getActiveEditor()
return unless editor?
return true if editor.getGrammar().scopeName is 'source.gfm'
path and fs.isMarkdownExtension(fs.extension(path))

View File

@@ -1,6 +1,7 @@
$ = require 'jquery'
RootView = require 'root-view'
MarkdownPreview = require 'markdown-preview/lib/markdown-preview-view'
_ = require 'underscore'
describe "MarkdownPreview", ->
beforeEach ->
@@ -33,6 +34,18 @@ describe "MarkdownPreview", ->
markdownPreviewView = rootView.find('.markdown-preview')?.view()
expect(markdownPreviewView.loadHtml).toHaveBeenCalled()
it "displays a preview for a file with the source.gfm grammar scope", ->
gfmGrammar = _.find syntax.grammars, (grammar) -> grammar.scopeName is 'source.gfm'
rootView.open('file.js')
editor = rootView.getActiveEditor()
rootView.project.addGrammarOverrideForPath(editor.getPath(), gfmGrammar)
editor.reloadGrammar()
expect(rootView.find('.markdown-preview')).not.toExist()
editor.trigger('markdown-preview:toggle')
expect(rootView.find('.markdown-preview')).toExist()
markdownPreviewView = rootView.find('.markdown-preview')?.view()
expect(markdownPreviewView.loadHtml).toHaveBeenCalled()
it "does not display a preview for non-markdown file", ->
rootView.open('file.js')
editor = rootView.getActiveEditor()