Skip to content

Commit

Permalink
Merge pull request #471 from openannotation/rework-markdown-plugin
Browse files Browse the repository at this point in the history
Allow creator to provide a custom renderer to the Viewer.
  • Loading branch information
aron committed Dec 19, 2014
2 parents ec07b74 + 501501e commit a304c19
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ui/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ var Viewer = Widget.extend({
this.hideTimerActivity = null;
this.mouseDown = false;

function defaultTextRenderer(text) {
return Util.escapeHtml(text);
}
var renderText = this.options.renderText || defaultTextRenderer;

var self = this;
if (this.options.defaultFields) {
this.addField({
load: function (field, annotation) {
if (annotation.text) {
$(field).html(Util.escapeHtml(annotation.text));
$(field).html(renderText(annotation.text));
} else {
$(field).html("<i>" + _t('No Comment') + "</i>");
}
Expand All @@ -107,8 +113,6 @@ var Viewer = Widget.extend({
throw new TypeError("permitDelete callback must be a function");
}

var self = this;

if (this.options.autoViewHighlights) {
this.document = this.options.autoViewHighlights.ownerDocument;

Expand Down
23 changes: 23 additions & 0 deletions test/spec/ui/viewer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,29 @@ describe('UI.Viewer', function () {
});
});

describe('renderText', function () {
var renderText = null;

beforeEach(function () {
renderText = sinon.stub().returns("Wolves with sheep");

v = new UI.Viewer({
defaultFields: true,
renderText: renderText
});
});

afterEach(function () {
v.destroy();
});

it('calls the defaultRenderer to render the text field.', function () {
v.load([{text: "Tigers with cameras"}]);
var html = v.element.html();
assert.isTrue(html.indexOf("Wolves with sheep") >= 0);
});
});

describe('event handlers', function () {
var hl = null,
clock = null;
Expand Down

0 comments on commit a304c19

Please sign in to comment.