Newer
Older
<li :is="tag" :class="body.type_"><!--
--><span :is="item.tag || 'span'" v-for="(item, index) in assemble_text"
:key="index"
v-bind="item.props"><!--
--><span v-for="(subitem, index) in highlight_hits(item.html)" :key="'a'+index" :class="subitem.type">{{subitem.text}}</span><!--
--><router-link class="article_ref" v-if="item.type == 'article_ref'" :to="item.ref" @click.native="article_link_click(item)" :key="index">
<span v-for="(subitem, index) in highlight_hits(item.link_text, item.link_text)" :key="'a'+index" :class="subitem.type">{{subitem.text}}</span><!--
<span class="homograph" v-if="item.lemmas[0].hgno" :aria-label="`${dictionary=='bm'? 'Betydning': 'Tyding'} ${item.lemmas[0].hgno}`" :title="`${dictionary=='bm'? 'Betydning': 'Tyding'} ${item.lemmas[0].hgno}`" :key="index"><!--
--> ({{roman_hgno(item.lemmas[0])}}{{item.definition_order ? '': ')'}}</span>
<span class="def_order" v-if="item.definition_order" :aria-label="'definisjon '+item.definition_order">{{item.lemmas[0].hgno ? ', ': ' ('}}{{item.definition_order}})</span>
</router-link>
<!--
--><span class="numerator" v-if="item.type == 'fraction'">{{item.num}}</span><!--
-->{{item.type == 'fraction' ? '⁄' : ''}}<!--
--><span class="denominator" v-if="item.type == 'fraction'">{{item.denom}}</span><!--
function replace_grammar_id(item, lang) {
let content = item.content
if (content.includes('$') && (item.items[0].id)){
let replacement_item = entities[lang][item.items[0].id]['expansion']
content = content.replace('$', replacement_item)}
return content
}
body: Object,
tag: {
type: String,
default: 'li'
data: function() {
return {
path: this.$route.fullPath
}
},
fulltext: function() {
if (this.$route.query.scope && this.$route.query.scope.includes("f")) {
let q = this.$route.query.q
q = q.replace("*", "[^\\s]*")
q = q.replace("_", "[^\\s]")
console.log(q)
return q
if (item.type_ == 'usage') return {type: item.type_, html: item.text, tag: 'mark'}
else if (item.type_ == 'article_ref') return {
type: item.type_,
html: '',
link_text: item.word_form || item.lemmas[0].lemma,
ref: '/' + lang + '/' + item.article_id + '/' + encodeURIComponent(item.word_form || item.lemmas[0].lemma) + (item.definition_id ? '#def' + item.definition_id : ''),
definition_id: item.definition_id,
definition_order: item.definition_order,
source: path

Ole Voldsæter
committed
else if (item.type_ == 'pronunciation') return {type: item.type_, html: item.string}
else if (item.type_ == 'pronunciation_guide') return {type: item.type_, body: item, html: '', tag: 'DefElement', props: {body: item, tag: 'i', dictionary: lang}}
else if (item.type_ == 'superscript') return {type: item.type_, html: item.text, tag: 'sup'}
else if (item.type_ == 'subscript') return {type: item.type_, html: item.text, 'tag': 'sub'}
else if (item.type_ == 'quote_inset') return {type: item.type_, body: item, html: '', tag: 'DefElement', props: {body: item, tag: 'i', dictionary: lang}}
else if (item.type_ == 'fraction') return helpers.fraction(item.numerator, item.denominator)
else if (item.id) return {type: item.type_, html: (entities[lang][item.id] || {})['expansion'] || item.id}

Ole Voldsæter
committed
else return {type: item.type_ || 'plain', html: item}
var old_parts = this.body.content.split(/(\$)/)
var text_items = this.unparsed.slice(0).reverse()
var new_parts = []
old_parts.forEach(function(item){
if(item == '$') {
new_parts.push(text_items.pop())
} else if (item.length) {
new_parts.push({type: 'plain', html: item})
}
})
return new_parts
}
if (text != "" && this.fulltext) {
let regex = new RegExp("("+this.fulltext+")", "gi")
if (regex.test(text)) {
console.log("split", text.split(new RegExp("^\s("+this.fulltext+")", "gi")))
console.log(this.fulltext)
let components = text.split(regex)
return {text: item, type: "highlighted"}
}
else {
return {text: item, type}
}
})
},
add_highlight: function(text) {
if (!this.fulltext) {
return text
}
else {
let regex = new RegExp("(^| |-)("+this.fulltext+")(-| |$)", "gi")
let old_parts = text.split(regex)
console.log("OLD",old_parts)
return old_parts.map(item => {
return item == this.fulltext ? {text: item, type: 'strong'}: {text: item}
})
}
},
article_link_click: function(item) {
this.$emit('article-click', item)
},
roman_hgno: helpers.roman_hgno
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.pronunciation_guide {
font-size: smaller;
}
.numerator{
vertical-align: super;
padding-right: 2px;
font-size: smaller;
}
.denominator {
vertical-align: sub;
padding-left: 2px;
font-size: smaller;
i {
font-style: normal;
}
.article_ref {
text-decoration: none;
}
.link_text {
text-decoration: underline;
}
.homograph, .def_order{
text-decoration: none !important;
color: black
q:before {
content: none;
}
q:after {
content: none;
}