Improve highlights
This commit is contained in:
parent
9cbb329c62
commit
fc9fc0ec8f
1 changed files with 23 additions and 1 deletions
24
bundle.js
24
bundle.js
|
@ -22,7 +22,29 @@ $(function() {
|
|||
|
||||
var examples = []
|
||||
data['examples'].forEach(function(item) {
|
||||
examples.push('<li>' + item[0] + ' — ' + item[1] + '</li>')
|
||||
var left = item['left']
|
||||
var right = item['right']
|
||||
var highlights = item['highlights']
|
||||
|
||||
var highlighted = []
|
||||
if (highlights.length == 0) {
|
||||
highlighted.push(left)
|
||||
} else {
|
||||
var last_pos = 0
|
||||
highlights.forEach(function(highlight) {
|
||||
var pos = highlight['pos']
|
||||
var len = highlight['len']
|
||||
if (pos > 0) { highlighted.push(left.substring(last_pos, pos)) }
|
||||
last_pos = pos + len
|
||||
highlighted.push(
|
||||
'<b>' + left.substring(pos, pos + len) + '</b>'
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
examples.push(
|
||||
'<li>' + highlighted.join('') + ' — ' + right + '</li>'
|
||||
)
|
||||
})
|
||||
|
||||
$('#primary-form').text(primary_form)
|
||||
|
|
Loading…
Add table
Reference in a new issue