[pl][nouns] allow multiple abbreviations

This commit is contained in:
Andrea 2022-02-13 23:29:56 +01:00
parent ebb408ae8d
commit 42c5f270b3
1 changed files with 10 additions and 15 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<span> <span>
<abbr v-if="abbr" :title="meaning">{{abbr}}</abbr><template v-if="abbr">&nbsp;</template><slot v-bind:abbr="abbr" v-bind:meaning="meaning" v-bind:word="word"></slot> <template v-for="(meaning, abbr) in abbrs"><abbr v-if="meaning" :title="meaning">{{abbr}}</abbr><span v-else>{{abbr}}</span>&nbsp;</template><slot v-bind:abbrs="abbrs" v-bind:word="word"></slot>
</span> </span>
</template> </template>
@ -12,21 +12,16 @@ export default {
v: {required: true}, v: {required: true},
}, },
data() { data() {
for (let abbr in abbreviations) { const abbrs = {};
if (!abbreviations.hasOwnProperty(abbr)) { continue; } let word = this.v.trim();
if (this.v.startsWith(abbr + ' ')) { let m = null;
return { while ((m = word.match(/^(\w+\.?) /)) !== null) {
abbr, const abbr = m[1];
meaning: abbreviations[abbr], abbrs[abbr] = abbreviations[abbr] || null;
word: this.v.substring(abbr.length + 1), word = word.substring(abbr.length + 1).trim();
};
}
}
return {
abbr: null,
meaning: null,
word: this.v,
} }
return { abbrs, word };
}, },
} }
</script> </script>