Improving output to use spaces more properly around punctuation.
parent
c7767fc3a4
commit
809ae9c737
|
@ -33,14 +33,29 @@ function showArticle(article) {
|
||||||
document.getElementById('title').innerHTML = article.title
|
document.getElementById('title').innerHTML = article.title
|
||||||
document.getElementById('link').innerHTML = `[ <a href='${article.url}'>Original Article</a> ]`
|
document.getElementById('link').innerHTML = `[ <a href='${article.url}'>Original Article</a> ]`
|
||||||
let output = ''
|
let output = ''
|
||||||
|
let spaceBefore = false
|
||||||
|
const noSpaceBeforeTags = new Set(['.', ',', ')', ';', ':', '!', '?', "''", 'POS'])
|
||||||
|
const noSpaceBeforeTokens = new Set(["n't", ']'])
|
||||||
|
const noSpaceAfterTags = new Set(['(', '``'])
|
||||||
|
const noSpaceAfterTokens = new Set(['['])
|
||||||
article.tokens.forEach(function(token) {
|
article.tokens.forEach(function(token) {
|
||||||
let adlib_input = document.getElementById(`token_${token.id}`);
|
|
||||||
if(adlib_input && adlib_input.value) {
|
if(spaceBefore && !noSpaceBeforeTags.has(token.tag) && !noSpaceBeforeTokens.has(token.token)) {
|
||||||
output += `<strong>${adlib_input.value}</strong> `
|
output += ' '
|
||||||
|
}
|
||||||
|
spaceBefore = true
|
||||||
|
|
||||||
|
let adlibInput = document.getElementById(`token_${token.id}`);
|
||||||
|
if(adlibInput && adlibInput.value) {
|
||||||
|
output += `<strong>${adlibInput.value}</strong>`
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
output += `${token.token}`
|
output += `${token.token}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(noSpaceAfterTags.has(token.tag) || noSpaceAfterTokens.has(token.token)) {
|
||||||
|
spaceBefore = false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
document.getElementById('summary').innerHTML = output
|
document.getElementById('summary').innerHTML = output
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue