diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee
index 0aca4b840..a222d8303 100644
--- a/spec/app/editor-spec.coffee
+++ b/spec/app/editor-spec.coffee
@@ -1765,7 +1765,7 @@ describe "Editor", ->
editor.edit(emptyEditSession)
expect(editor.gutter.lineNumbers.find('.line-number').length).toBe 1
- describe "when the editor is mini", ->
+ fdescribe "when the editor is mini", ->
it "hides the gutter", ->
miniEditor = new Editor(mini: true)
miniEditor.attachToDom()
diff --git a/src/app/editor.coffee b/src/app/editor.coffee
index d433e890f..1b4f66761 100644
--- a/src/app/editor.coffee
+++ b/src/app/editor.coffee
@@ -1317,17 +1317,24 @@ class Editor extends View
buildLineElementsForScreenRows: (startRow, endRow) ->
div = document.createElement('div')
- div.innerHTML = @buildLinesHtml(startRow, endRow)
+ div.innerHTML = @buildHtmlLines(startRow, endRow)
new Array(div.children...)
- buildLinesHtml: (startRow, endRow) ->
+ buildHtmlLines: (startRow, endRow) ->
lines = @activeEditSession.linesForScreenRows(startRow, endRow)
htmlLines = []
screenRow = startRow
for line in @activeEditSession.linesForScreenRows(startRow, endRow)
- htmlLines.push(@buildLineHtml(line, screenRow++))
+ htmlLines.push(@buildHtmlFromLine(line, screenRow++))
htmlLines.join('\n\n')
+ @buildEmptyLineHtml: (guideIndentation, showInvisibles, activeEditSession) ->
+ if guideIndentation > 0
+ indentationHtml = "#{_.multiplyString(' ', @activeEditSession.getTabLength())}"
+ return _.multiplyString(indentationHtml, indentation)
+ else if not showInvisibles
+ ' '
+
buildEndOfLineInvisibles: (screenLine) ->
invisibles = []
for invisible in @getEndOfLineInvisibles(screenLine)
@@ -1337,12 +1344,19 @@ class Editor extends View
getEndOfLineInvisibles: (screenLine) ->
return [] unless @showInvisibles and @invisibles
return [] if @mini or screenLine.isSoftWrapped()
+
+ buildLineHtml: (screenLine, screenRow) ->
+ { tokens, text, lineEnding, fold } = screenLine
+ if fold
+ attributes = { class: 'fold line', 'fold-id': fold.id }
+ else
+ attributes = { class: 'line' }
invisibles = []
invisibles.push(@invisibles.cr) if @invisibles.cr and screenLine.lineEnding is '\r\n'
invisibles.push(@invisibles.eol) if @invisibles.eol
invisibles
-
+
buildEmptyLineHtml: (screenRow) ->
if not @mini and @showIndentGuide
guideIndentation = 0
@@ -1353,13 +1367,10 @@ class Editor extends View
guideIndentation = Math.ceil(@activeEditSession.indentLevelForLine(bufferLine))
break
- if indentation > 0
- indentationHtml = "#{_.multiplyString(' ', @activeEditSession.getTabLength())}"
- return _.multiplyString(indentationHtml, indentation)
+ invisibles = @invisibles if @showInvisibles
+ Editor.buildLineHtmlHelper({tokens, text, lineEnding, fold, isSoftWrapped, invisibles, attributes, guideIndentation, @showInvisibles, @activeEditSession, @mini})
- return ' ' unless @showInvisibles
-
- @buildLineHtmlHelper: ({tokens, text, lineEnding, fold, isSoftWrapped, attributes, guideIndentation, showInvisibles}) ->
+ @buildHtmlHelper: ({tokens, text, lineEnding, fold, isSoftWrapped, invisibles, attributes, guideIndentation, showInvisibles, activeEditSession, mini}) =>
scopeStack = []
line = []
@@ -1388,10 +1399,8 @@ class Editor extends View
attributePairs.push "#{attributeName}=\"#{value}\"" for attributeName, value of attributes
line.push("
")
- invisibles = @invisibles if showInvisibles
-
- if screenLine.text == ''
- html = @buildEmptyLineHtml(screenRow)
+ if text == ''
+ html = Editor.buildEmptyLineHtml(guideIndentation, showInvisibles, activeEditSession)
line.push(html) if html
else
firstNonWhitespacePosition = text.search(/\S/)
@@ -1407,8 +1416,8 @@ class Editor extends View
position += token.value.length
popScope() while scopeStack.length > 0
- if invisibles and not @mini and not screenLine.isSoftWrapped()
- if invisibles.cr and screenLine.lineEnding is '\r\n'
+ if invisibles and not @mini and not isSoftWrapped
+ if invisibles.cr and lineEnding is '\r\n'
line.push("#{invisibles.cr}")
if invisibles.eol
line.push("#{invisibles.eol}")
diff --git a/src/packages/markdown-preview/lib/markdown-preview-view.coffee b/src/packages/markdown-preview/lib/markdown-preview-view.coffee
index e343f52a4..acbcd0a62 100644
--- a/src/packages/markdown-preview/lib/markdown-preview-view.coffee
+++ b/src/packages/markdown-preview/lib/markdown-preview-view.coffee
@@ -21,7 +21,7 @@ class MarkdownPreviewView extends ScrollView
initialize: (@buffer) ->
super
- @fetchRenderedMarkdown()
+ @renderMarkdown()
@on 'core:move-up', => @scrollUp()
@on 'core:move-down', => @scrollDown()
@@ -71,22 +71,29 @@ class MarkdownPreviewView extends ScrollView
for codeBlock in preList.toArray()
codeBlock = $(codeBlock.firstChild)
- if className = codeBlock.attr('class')
- fenceName = className.replace(/^lang-/, '')
- if extension = fenceNameToExtension[fenceName]
- text = codeBlock.text()
- syntax.selectGrammar("foo.#{extension}", text)
- if grammar = syntax.selectGrammar("foo.#{extension}", text)
- continue if grammar is syntax.nullGrammar
- tokens = grammar.tokenizeLines(text)
- grouping = ""
- for token in tokens
- grouping += Editor.buildLineHtml(token, text)
- codeBlock.replaceWith(grouping)
+ # go to next block unless this one has a class
+ continue unless className = codeBlock.attr('class')
+
+ fenceName = className.replace(/^lang-/, '')
+ # go to next block unless the class name is matches `lang`
+ continue unless extension = fenceNameToExtension[fenceName]
+ text = codeBlock.text()
+ syntax.selectGrammar("foo.#{extension}", text)
+
+ # go to next block if this grammar is not mapped
+ continue unless grammar = syntax.selectGrammar("foo.#{extension}", text)
+ continue if grammar is syntax.nullGrammar
+
+ tokens = grammar.tokenizeLines(text)
+ grouping = ""
+ for token in tokens
+ grouping += Editor.buildHtmlLine(token, text)
+ codeBlock.replaceWith(grouping)
+
html
- fetchRenderedMarkdown: ->
+ renderMarkdown: ->
@setLoading()
roaster(@buffer.getText(), {}, (err, html) =>
if err
diff --git a/src/packages/markdown-preview/spec/markdown-preview-view-spec.coffee b/src/packages/markdown-preview/spec/markdown-preview-view-spec.coffee
index 747f7f777..b3ae8b63c 100644
--- a/src/packages/markdown-preview/spec/markdown-preview-view-spec.coffee
+++ b/src/packages/markdown-preview/spec/markdown-preview-view-spec.coffee
@@ -16,12 +16,12 @@ describe "MarkdownPreviewView", ->
describe "on construction", ->
- it "shows a loading spinner and fetches the rendered markdown", ->
+ it "shows a loading spinner and renders the markdown", ->
preview.setLoading()
expect(preview.find('.markdown-spinner')).toExist()
expect(preview.buffer.getText()).toBe buffer.getText()
- preview.fetchRenderedMarkdown()
+ preview.renderMarkdown()
expect(preview.find(".emoji")).toExist()
it "shows an error message on error", ->
@@ -33,7 +33,7 @@ describe "MarkdownPreviewView", ->
newPreview = deserialize(preview.serialize())
expect(newPreview.buffer).toBe buffer
- fdescribe "code block tokenization", ->
+ describe "code block tokenization", ->
describe "when the code block's fence name has a matching grammar", ->
it "tokenizes the code block with the grammar", ->
expect(preview.find("pre span.entity.name.function.ruby")).toExist()