PronounsPage/components/Example.vue
Valentyne Stigloher 07b2b4d75c (ar)(pronouns) correctly connect arabic glyphs via zwj across morpheme boundaries
probably introduced by the font change and some edge cases don’t render completely correctly, but it is totally better then before
https://stackoverflow.com/questions/11155849/partially-colored-arabic-word-in-html
2024-05-23 18:12:42 +02:00

69 lines
2.4 KiB
Vue

<template>
<span>
<span v-for="(part, index) in exampleParts">
<strong v-if="part.variable"><Morpheme
:pronoun="pronoun"
:morpheme="part.str"
:counter="counter"
:prepend="getPrepend(index)"
:append="getAppend(index)"
/></strong>
<span v-else><Spelling :text="getPrepend(index) + part.str + getAppend(index)" /></span>
</span>
<small v-if="link">
(<nuxt-link :to="`/${pronoun.canonicalName}`"><Spelling escape :text="pronoun.canonicalName" /></nuxt-link>)
</small>
<Pronunciation
v-if="pronunciation && pronoun.pronounceable && example.toPronunciationString(pronoun)"
:pronunciation="example.toPronunciationString(pronoun)"
/>
</span>
</template>
<script lang="ts">
import Vue from 'vue';
import { Example, Pronoun } from '../src/classes.ts';
import type { ExamplePart } from '../src/classes.ts';
const startsWithArabicLetter = /^[\u0621-\u064A]/;
const endsWithArabicLetter = /[\u0621-\u064A]$/;
const zeroWidthJoiner = '\u200d';
export default Vue.extend({
props: {
example: { required: true, type: Example },
pronoun: { required: true, type: Pronoun },
counter: { default: 0, type: Number },
link: { type: Boolean },
pronunciation: { type: Boolean },
},
computed: {
exampleParts(): ExamplePart[] {
return this.example.parts(this.pronoun, this.counter);
},
},
methods: {
getContent(index: number): string | null {
if (this.exampleParts[index].variable) {
return this.pronoun.getMorpheme(this.exampleParts[index].str, this.counter);
}
return this.exampleParts[index].str;
},
getPrepend(index: number): string {
if (this.getContent(index)?.match(startsWithArabicLetter) &&
index > 0 && this.getContent(index - 1)?.match(endsWithArabicLetter)) {
return zeroWidthJoiner;
}
return '';
},
getAppend(index: number): string {
if (this.getContent(index)?.match(endsWithArabicLetter) &&
index < this.exampleParts.length - 1 && this.getContent(index + 1)?.match(startsWithArabicLetter)) {
return zeroWidthJoiner;
}
return '';
},
},
});
</script>