diff --git a/web/script.js b/web/script.js
index 2f3014c..5161f8d 100644
--- a/web/script.js
+++ b/web/script.js
@@ -33,13 +33,28 @@ function showArticle(article) {
document.getElementById('title').innerHTML = article.title
document.getElementById('link').innerHTML = `[ Original Article ]`
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 += `${adlib_input.value} `
+
+ 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 += `${adlibInput.value}`
}
else {
- output += `${token.token} `
+ output += `${token.token}`
+ }
+
+ if(noSpaceAfterTags.has(token.tag) || noSpaceAfterTokens.has(token.token)) {
+ spaceBefore = false
}
})
document.getElementById('summary').innerHTML = output