Skip to content
Snippets Groups Projects
Commit 3b4999f7 authored by Henrik Askjer's avatar Henrik Askjer
Browse files

regex

parent b76f860d
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
--><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, link_text)" :key="'a'+index" :class="subitem.type">{{subitem.text}}</span><!--
<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>
......@@ -52,7 +52,11 @@ export default {
computed: {
fulltext: function() {
if (this.$route.query.scope && this.$route.query.scope.includes("f")) {
return this.$route.query.q
let q = this.$route.query.q
q = q.replace("*", "[^\\s]*")
q = q.replace("_", "[^\\s]")
console.log(q)
return q
}
return false
},
......@@ -100,21 +104,24 @@ export default {
},
methods: {
highlight_hits: function(text, type) {
if (text !="" && this.fulltext && text.includes(this.fulltext)) {
console.log("split", text.split(new RegExp("("+this.fulltext+")", "gi")))
let components = text.split(new RegExp("("+this.fulltext+")", "gi"))
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 components.map(item => {
if (item == this.fulltext) {
if (regex.test(item)) {
return {text: item, type: "highlighted"}
}
else {
return {text: item, type}
}
})
}
}
else {
return [{text, type}]
}
return [{text, type}]
},
add_highlight: function(text) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment