Improving output to use spaces more properly around punctuation.

main
gamerdonkey 2022-08-19 05:18:00 +00:00
parent c7767fc3a4
commit 809ae9c737
1 changed files with 19 additions and 4 deletions

View File

@ -33,14 +33,29 @@ function showArticle(article) {
document.getElementById('title').innerHTML = article.title
document.getElementById('link').innerHTML = `[ <a href='${article.url}'>Original Article</a> ]`
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) {
let adlib_input = document.getElementById(`token_${token.id}`);
if(adlib_input && adlib_input.value) {
output += `<strong>${adlib_input.value}</strong> `
if(spaceBefore && !noSpaceBeforeTags.has(token.tag) && !noSpaceBeforeTokens.has(token.token)) {
output += ' '
}
spaceBefore = true
let adlibInput = document.getElementById(`token_${token.id}`);
if(adlibInput && adlibInput.value) {
output += `<strong>${adlibInput.value}</strong>`
}
else {
output += `${token.token}`
}
if(noSpaceAfterTags.has(token.tag) || noSpaceAfterTokens.has(token.token)) {
spaceBefore = false
}
})
document.getElementById('summary').innerHTML = output