diff --git a/scratch.js b/scratch.js index 14e8a51a..671b4970 100644 --- a/scratch.js +++ b/scratch.js @@ -1,12 +1,12 @@ import wtf from './src/index.js' console.log('start') -let str = `before {{Vgrtbl|NA|1989-03-12|EU|August 16, 2008}} after +let str = `before {{literal translation|a|b}} after ` let doc = wtf(str) // const doc = await wtf.fetch('https://en.wikivoyage.org/wiki/Interstate_5') -console.log(doc.template().json()) +// console.log(doc.template().json()) console.log(doc.text()) diff --git a/src/template/custom/aliases.js b/src/template/custom/aliases.js index 1f8cd448..89d93028 100644 --- a/src/template/custom/aliases.js +++ b/src/template/custom/aliases.js @@ -31,6 +31,9 @@ let aliases = { under: 'underline', brackets: 'bracket', raise: 'lower', + 'born-in': 'born in', + 'c.': 'circa', + 'r.': 'reign', } //multiple aliases @@ -256,6 +259,7 @@ let multi = { // https://en.wikipedia.org/wiki/Template:Ferry 'station link': ['amtk', 'cta', 'bts', 'mnrr', 'mtams', 'munis', 'njts', 'scax', 'wmata', 'rwsa'], 'video game release': ['vgrelease', 'video game release hlist', 'vgrtbl', 'vgrelease hlist', 'vgrh'], + aka: ['a.k.a.', 'also known as'], } // - other languages - diff --git a/src/template/custom/text-only/abbreviations.js b/src/template/custom/text-only/abbreviations.js new file mode 100644 index 00000000..10d4c97b --- /dev/null +++ b/src/template/custom/text-only/abbreviations.js @@ -0,0 +1,54 @@ +import parse from '../../parse/toJSON/index.js' + +let shorthands = [ + // {{HWV|251d}} - handel, bach + ['bwv', 'BWV'], + ['hwv', 'HWV'], + ['d.', 'D '], //Deutsch catalogue + ['aka', 'a.k.a. '], + + // date abbreviations + ['cf.', 'cf. '], + ['fl.', 'fl. '], + ['circa', 'c. '], + ['born in', 'b. '], + ['died-in', 'd. '], + ['married-in', 'm. '], +] +// create a function for each one +let fns = shorthands.reduce((h, a) => { + let [name, out] = a + h[name] = (tmpl) => { + let { first } = parse(tmpl, ['first']) + if (first || first === 0) { + return out + (first || '') + } + return out + } + return h +}, {}) + +// return only the name of the template +let justNames = [ + 'they', + 'them', + 'their', + 'theirs', + 'themself', + 'they are', + 'they were', + 'they have', + 'they do', + 'he or she', + 'him or her', + 'his or her', + 'his or hers', + 'he/she', + 'him/her', + 'his/her', +] +justNames.forEach((str) => { + fns[str] = str +}) + +export default fns diff --git a/src/template/custom/text-only/easy-inline.js b/src/template/custom/text-only/easy-inline.js index c9fcbb8c..dde32ac3 100644 --- a/src/template/custom/text-only/easy-inline.js +++ b/src/template/custom/text-only/easy-inline.js @@ -100,11 +100,14 @@ let zeros = [ 'bigdiv', 'strikethroughdiv', 'strikethrough color', - 'pbpe'//pt + 'pbpe', //pt + 'video game release/abbr', + 'nobel abbr', + 'gloss', + 'gcl', ] zeros.forEach((k) => { templates[k] = 0 }) - export default templates diff --git a/src/template/custom/text-only/functions.js b/src/template/custom/text-only/functions.js index 2c32a833..4e4f90e2 100644 --- a/src/template/custom/text-only/functions.js +++ b/src/template/custom/text-only/functions.js @@ -73,11 +73,6 @@ export default { return `(r. ${obj.start} – ${obj.end})` }, - circa: (tmpl) => { - let { year } = parse(tmpl, ['year']) - return year ? `c. ${year}` : 'c. ' - }, - // https://en.wikipedia.org/wiki/Template:Decade_link 'decade link': (tmpl) => { let { year } = parse(tmpl, ['year']) diff --git a/src/template/custom/text-only/index.js b/src/template/custom/text-only/index.js index 967e271b..0438ba43 100644 --- a/src/template/custom/text-only/index.js +++ b/src/template/custom/text-only/index.js @@ -1,18 +1,10 @@ import hardcoded from './hardcoded.js' import easyInline from './easy-inline.js' -import shorthand from './shorthands.js' +import shorthand from './shorthand-link.js' import functions from './functions.js' +import abbreviations from './abbreviations.js' import moreLangs from './languages.js' import flags from './flags.js' import table from './table-cell.js' -export default Object.assign( - {}, - hardcoded, - easyInline, - shorthand, - functions, - moreLangs, - flags, - table, -) +export default Object.assign({}, hardcoded, easyInline, shorthand, functions, moreLangs, abbreviations, flags, table) diff --git a/src/template/custom/text-only/shorthands.js b/src/template/custom/text-only/shorthand-link.js similarity index 100% rename from src/template/custom/text-only/shorthands.js rename to src/template/custom/text-only/shorthand-link.js