Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
feat: support newline characters (#16)
Browse files Browse the repository at this point in the history
* Support newline characters in rows

So we can have multi-line rows without dividers

* feat: support newline characters
  • Loading branch information
bcoe committed Jun 2, 2016
1 parent 4618db4 commit 65259b4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ AnnotationPoller.prototype._applyReplacements = function (obj) {
obj.rows.forEach(function (row, i) {
var flattenedRow = []

// bold any text in between *foo*.
// bold any text in between *foo* and parse newlines.
if (row.text) {
row.text = _this._escape(row.text)
row.text = row.text.replace(/\*(.+)\*/, '<strong>$1</strong>')
row.text = row.text.replace(/\*([\s\S]+)\*/, '<strong>$1</strong>').replace(/\n/g, '<br/>')
}

// escape any HTML in links.
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"mocha": "^2.4.5",
"nyc": "^6.4.4",
"standard": "^7.1.0",
"standard-version": "^2.2.1"
"standard-version": "^2.2.1",
"uuid": "^2.0.2"
},
"dependencies": {
"handlebars": "^4.0.5",
Expand All @@ -52,4 +53,4 @@
"annotation.js",
"LICENSE.txt"
]
}
}
38 changes: 30 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var annotationPoller = require('./')
var pkg = encodeURIComponent('cool module')
var endpoint = '/api/v1/annotations/' + pkg
var $ = require('jquery')
var uuid = require('uuid')

require('jquery-mockjax')($)
$.mockjaxSettings.logging = false
Expand All @@ -25,7 +26,7 @@ describe('annotation-poller', function () {
responseText: [{
id: 'abc-123-abc',
name: 'Awesome Integration',
fingerprint: 'a',
fingerprint: uuid.v4(),
rows: [{
image: {
url: 'http://www.example.com/img',
Expand Down Expand Up @@ -55,7 +56,7 @@ describe('annotation-poller', function () {
responseText: [{
id: 'abc-123-abc',
name: 'second integration',
fingerprint: 'b',
fingerprint: uuid.v4(),
rows: [{
link: {
url: 'http://www.example.com',
Expand Down Expand Up @@ -94,7 +95,7 @@ describe('annotation-poller', function () {
responseText: [{
id: 'abc-123-abc',
name: 'second integration',
fingerprint: 'bb',
fingerprint: uuid.v4(),
rows: [{
link: {
url: 'http://www.example.com',
Expand Down Expand Up @@ -124,7 +125,7 @@ describe('annotation-poller', function () {
responseText: [{
id: 'abc-123-abc',
name: 'second integration',
fingerprint: 'c',
fingerprint: uuid.v4(),
rows: [{
text: 'my *awesome* <b>message</b>'
}]
Expand All @@ -139,13 +140,34 @@ describe('annotation-poller', function () {
})
})

it('replaces \\n with <br />', function (done) {
$.mockjax({
url: endpoint,
responseText: [{
id: 'abc-123-abc',
name: 'second integration',
fingerprint: uuid.v4(),
rows: [{
text: '*my\nawesome\nui*'
}]
}]
})

var poller = annotationPoller({pollInterval: 50, pkg: pkg})
poller.start(function () {
$('strong').html().should.equal('my<br>awesome<br>ui')
poller.stop()
return done()
})
})

it('handles an array of links', function (done) {
$.mockjax({
url: endpoint,
responseText: [{
id: 'abc-123-abc',
name: 'second integration',
fingerprint: 'd',
fingerprint: uuid.v4(),
rows: [{
link: [{url: 'http://example.com', text: 'link 1'}, {url: 'http://2.example.com', text: 'link 2'}]
}]
Expand Down Expand Up @@ -254,7 +276,7 @@ describe('annotation-poller', function () {
responseText: [{
id: 'test-image-render',
name: 'image render test integration',
fingerprint: 'tir',
fingerprint: uuid.v4(),
rows: [{
image: {
url: 'http://www.example.com/img.png',
Expand All @@ -279,7 +301,7 @@ describe('annotation-poller', function () {
responseText: [{
id: 'test-image-link',
name: 'image link test integration',
fingerprint: 'til',
fingerprint: uuid.v4(),
rows: [{
image: {
url: 'http://www.example.com/img.png',
Expand All @@ -305,7 +327,7 @@ describe('annotation-poller', function () {
responseText: [{
id: 'test-multi-mixed-image-links',
name: 'mixed multi image links',
fingerprint: 'tmmil',
fingerprint: uuid.v4(),
rows: [{
image: [{
url: 'http://www.example.com/img1.png',
Expand Down

0 comments on commit 65259b4

Please sign in to comment.