Cleaning up the javascript a bit.
parent
809ae9c737
commit
2b68db2401
|
@ -1,19 +1,3 @@
|
||||||
function parseArticleJSON_old() {
|
|
||||||
fetch('tokens.json')
|
|
||||||
.then((article) => article.json())
|
|
||||||
.then((article_json) => {
|
|
||||||
let output = ''
|
|
||||||
article_json.forEach(function(token) {
|
|
||||||
output += `${token.token} `
|
|
||||||
})
|
|
||||||
document.getElementById('article').innerHTML = output
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log(`Error fetching article: ${error}`)
|
|
||||||
document.getELementById('article').innerHTML = 'Error'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function createInputs(article) {
|
function createInputs(article) {
|
||||||
inputs = ''
|
inputs = ''
|
||||||
article.tokens.forEach(function(token) {
|
article.tokens.forEach(function(token) {
|
||||||
|
@ -30,16 +14,17 @@ function createInputs(article) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function showArticle(article) {
|
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 noSpaceBeforeTags = new Set(['.', ',', ')', ';', ':', '!', '?', "''", 'POS'])
|
||||||
const noSpaceBeforeTokens = new Set(["n't", ']'])
|
const noSpaceBeforeTokens = new Set(["n't", ']'])
|
||||||
const noSpaceAfterTags = new Set(['(', '``'])
|
const noSpaceAfterTags = new Set(['(', '``'])
|
||||||
const noSpaceAfterTokens = new Set(['['])
|
const noSpaceAfterTokens = new Set(['['])
|
||||||
article.tokens.forEach(function(token) {
|
|
||||||
|
|
||||||
|
document.getElementById('title').innerHTML = article.title
|
||||||
|
document.getElementById('link').innerHTML = `[ <a href='${article.url}'>Original Article</a> ]`
|
||||||
|
|
||||||
|
let output = ''
|
||||||
|
let spaceBefore = false
|
||||||
|
article.tokens.forEach(function(token) {
|
||||||
if(spaceBefore && !noSpaceBeforeTags.has(token.tag) && !noSpaceBeforeTokens.has(token.token)) {
|
if(spaceBefore && !noSpaceBeforeTags.has(token.tag) && !noSpaceBeforeTokens.has(token.token)) {
|
||||||
output += ' '
|
output += ' '
|
||||||
}
|
}
|
||||||
|
@ -57,6 +42,7 @@ function showArticle(article) {
|
||||||
spaceBefore = false
|
spaceBefore = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById('summary').innerHTML = output
|
document.getElementById('summary').innerHTML = output
|
||||||
|
|
||||||
document.getElementById('article').classList.add('visible')
|
document.getElementById('article').classList.add('visible')
|
||||||
|
|
Loading…
Reference in New Issue