Properly html escape rendered text in editor and render empty lines.

This commit is contained in:
Danny Greg & Nathan Sobo 2012-01-19 19:08:40 -08:00
parent 62d8aa72e2
commit 98947877e5
3 changed files with 13 additions and 3 deletions

View File

@ -16,8 +16,14 @@ fdescribe "Editor", ->
describe ".setBuffer", ->
beforeEach ->
it "creates a pre element for each line in the buffer", ->
it "creates a pre element for each line in the buffer, with the html-escaped text of the line", ->
expect(editor.lines.find('pre').length).toEqual(buffer.numLines())
expect(buffer.getLine(2)).toContain('<')
expect(editor.lines.find('pre:eq(2)').html()).toContain '&lt;'
it "renders a non-breaking space for empty lines", ->
expect(buffer.getLine(10)).toBe ''
expect(editor.lines.find('pre:eq(10)').html()).toBe '&nbsp;'
it "sets the cursor to the beginning of the file", ->
expect(editor.getPosition()).toEqual(row: 0, col: 0)

View File

@ -8,5 +8,6 @@ var quicksort = function () {
}
return sort(left).concat(pivot).concat(sort(right));
};
return sort(Array.apply(this, arguments));
};

View File

@ -2,6 +2,7 @@ Template = require 'template'
Buffer = require 'buffer'
Cursor = require 'cursor'
$ = require 'jquery'
$$ = require 'template/builder'
_ = require 'underscore'
module.exports =
@ -71,8 +72,10 @@ class Editor extends Template
setBuffer: (@buffer) ->
@lines.empty()
for line in @buffer.getLines()
line = '&nbsp;' if line is ''
@lines.append "<pre>#{line}</pre>"
if line is ''
@lines.append $$.pre -> @raw('&nbsp;')
else
@lines.append $$.pre(line)
@setPosition(row: 0, col: 0)
setPosition: (position) ->