2020-09-28 05:14:00 -07:00
|
|
|
<script>
|
2020-09-28 08:51:26 -07:00
|
|
|
import Icon from './Icon';
|
|
|
|
|
2020-09-28 05:14:00 -07:00
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
text: { required: true },
|
|
|
|
},
|
|
|
|
render(h) {
|
2020-09-28 08:51:26 -07:00
|
|
|
if (!this.text) {
|
|
|
|
return h('span');
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:14:00 -07:00
|
|
|
let isLink = false;
|
2020-09-28 08:51:26 -07:00
|
|
|
let isIcon = false;
|
2020-09-28 05:14:00 -07:00
|
|
|
let buffer = '';
|
|
|
|
let linkBuffer = '';
|
|
|
|
const children = [];
|
|
|
|
const buildLink = _ => {
|
2020-09-28 08:51:26 -07:00
|
|
|
if (isIcon) {
|
|
|
|
return h(Icon, {props: { v: buffer}});
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:14:00 -07:00
|
|
|
if (!isLink) {
|
|
|
|
return buffer.indexOf('<') !== -1
|
|
|
|
? h('span', {domProps: { innerHTML: buffer }})
|
|
|
|
: buffer;
|
|
|
|
}
|
|
|
|
|
2020-09-28 08:51:26 -07:00
|
|
|
if (linkBuffer.indexOf('https://') === 0 || linkBuffer.indexOf('http://') === 0 || linkBuffer.indexOf('mailto:') === 0) {
|
2020-09-28 05:14:00 -07:00
|
|
|
return h(
|
|
|
|
'a',
|
|
|
|
{domProps: {href: linkBuffer, target: '_blank', rel: 'noopener'}},
|
|
|
|
buffer,
|
2020-09-28 08:51:26 -07:00
|
|
|
);
|
2020-09-28 05:14:00 -07:00
|
|
|
}
|
|
|
|
|
2020-09-28 10:22:36 -07:00
|
|
|
return h('nuxt-link', {props: { to: linkBuffer || '/' + this.config.nouns.route + '#' + buffer }}, buffer);
|
2020-09-28 05:14:00 -07:00
|
|
|
}
|
|
|
|
const addChild = _ => {
|
|
|
|
if (!buffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
children.push(buildLink());
|
|
|
|
buffer = '';
|
|
|
|
linkBuffer = '';
|
|
|
|
}
|
|
|
|
for (let c of this.text) {
|
|
|
|
if (c === '{') {
|
|
|
|
addChild();
|
|
|
|
isLink = true;
|
|
|
|
continue;
|
|
|
|
} else if (c === '}') {
|
|
|
|
addChild();
|
|
|
|
isLink = false;
|
|
|
|
continue;
|
|
|
|
} else if (isLink && c === '=') {
|
2020-10-10 09:31:31 -07:00
|
|
|
if (linkBuffer) {
|
|
|
|
linkBuffer += '='
|
|
|
|
}
|
|
|
|
linkBuffer += buffer;
|
2020-09-28 05:14:00 -07:00
|
|
|
buffer = '';
|
|
|
|
continue;
|
2020-09-28 08:51:26 -07:00
|
|
|
} else if (c === '[') {
|
|
|
|
addChild();
|
|
|
|
isIcon = true;
|
|
|
|
continue;
|
|
|
|
} else if (c === ']') {
|
|
|
|
addChild();
|
|
|
|
isIcon = false;
|
|
|
|
continue;
|
2020-09-28 05:14:00 -07:00
|
|
|
}
|
|
|
|
buffer += c;
|
|
|
|
}
|
|
|
|
addChild();
|
|
|
|
|
|
|
|
return h('span', children);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|