1
0
Fork 0

Improve highlights

This commit is contained in:
Alex Kotov 2023-02-20 16:39:52 +04:00
parent 9cbb329c62
commit fc9fc0ec8f
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 23 additions and 1 deletions

View File

@ -22,7 +22,29 @@ $(function() {
var examples = []
data['examples'].forEach(function(item) {
examples.push('<li>' + item[0] + ' &mdash; ' + 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('') + ' &mdash; ' + right + '</li>'
)
})
$('#primary-form').text(primary_form)