Refactor niceLinks and add where missing.

Signed-off-by: Lapo Luchini <lapo@lapo.it>
This commit is contained in:
Lapo Luchini
2020-06-30 19:15:15 +02:00
parent d53f5bfa92
commit b8056e5f84
4 changed files with 21 additions and 13 deletions

View File

@@ -9,7 +9,7 @@
</div>
<div class="card-content">
<div class="content">
<p class="description title">{{ pinItem.description }}</p>
<p class="description title" v-html="niceLinks(pinItem.description)"></p>
</div>
<div class="media">
<div class="media-left">
@@ -60,6 +60,8 @@
</template>
<script>
import niceLinks from './utils/niceLinks';
export default {
name: 'PinPreview',
props: ['pinItem'],
@@ -70,6 +72,7 @@ export default {
{ name: 'pin', params: { pinId: this.pinItem.id } },
);
},
niceLinks,
},
};
</script>

View File

@@ -83,6 +83,7 @@ import noMore from './noMore.vue';
import scroll from './utils/scroll';
import bus from './utils/bus';
import EditorUI from './editors/PinEditorUI.vue';
import niceLinks from './utils/niceLinks';
function createImageItem(pin) {
const image = {};
@@ -126,18 +127,6 @@ function initialData() {
};
}
const encoder = document.createElement('div');
function escapeHTML(text) {
encoder.innerText = text;
return encoder.innerHTML;
}
const reURL = /https?:[/][/](?:www[.])?([^/]+)(?:[/]([.]?[^\s,.<>])+)?/g;
function niceLinks(text) {
if (!text) return '';
return escapeHTML(text).replace(reURL, '<a href="$&" target="_blank">$1</a>');
}
export default {
name: 'pins',
components: {

View File

@@ -13,6 +13,7 @@
v-on:imageUploadSucceed="onUploadDone"
v-on:imageUploadProcessing="onUploadProcessing"
></FileUpload>
<div class="description" v-show="pinModel.form.description.value" v-html="niceLinks(pinModel.form.description.value)"></div>
</div>
<div class="column">
<b-field label="Image URL"
@@ -109,6 +110,7 @@ import bus from '../utils/bus';
import ModelForm from '../utils/ModelForm';
import Loading from '../utils/Loading';
import AutoComplete from '../utils/AutoComplete';
import niceLinks from '../utils/niceLinks';
function isURLBlank(url) {
return url !== null && url === '';
@@ -271,6 +273,7 @@ export default {
},
);
},
niceLinks,
},
};
</script>

View File

@@ -0,0 +1,13 @@
const encoder = document.createElement('div');
function escapeHTML(text) {
encoder.innerText = text;
return encoder.innerHTML;
}
const reURL = /https?:[/][/](?:www[.])?([^/]+)(?:[/]([.]?[^\s,.<>])+)?/g;
function niceLinks(text) {
if (!text) return '';
return escapeHTML(text).replace(reURL, '<a href="$&" target="_blank">$1</a>');
}
export default niceLinks;