Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a custom element name for highlight spans #172

Merged
merged 1 commit into from
Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion h/static/scripts/annotator/highlighter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ $ = require('jquery')
# Returns an array of highlight Elements.
exports.highlightRange = (normedRange, cssClass='annotator-hl') ->
white = /^\s*$/
hl = $("<span class='#{cssClass}'></span>")

# A custom element name is used here rather than `<span>` to reduce the
# likelihood of highlights being hidden by page styling.
hl = $("<hypothesis-highlight class='#{cssClass}'></hypothesis-highlight>")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the CSS class is a bit redundant now, so perhaps in future we could look into removing that.


# Ignore text nodes that contain only whitespace characters. This prevents
# spans being injected between elements that can only contain a restricted
Expand Down
1 change: 1 addition & 0 deletions h/static/scripts/annotator/test/highlighter-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe "highlightRange", ->
result = highlighter.highlightRange(r)
assert.equal(result.length, 1)
assert.strictEqual(el.childNodes[0], result[0])
assert.equal(result[0].nodeName, 'HYPOTHESIS-HIGHLIGHT');
assert.isTrue(result[0].classList.contains('annotator-hl'))

it 'skips text nodes that are only white space', ->
Expand Down