2019-12-04 20:38:33 +05:30
|
|
|
<script>
|
2021-01-29 00:20:46 +05:30
|
|
|
import { linkRegex } from '../../utils';
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
import LineNumber from './line_number.vue';
|
|
|
|
|
|
|
|
export default {
|
2020-07-28 23:09:34 +05:30
|
|
|
functional: true,
|
2019-12-04 20:38:33 +05:30
|
|
|
props: {
|
|
|
|
line: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
path: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2022-08-13 15:12:31 +05:30
|
|
|
searchResults: {
|
|
|
|
type: Array,
|
|
|
|
required: false,
|
|
|
|
default: () => [],
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
},
|
2020-07-28 23:09:34 +05:30
|
|
|
render(h, { props }) {
|
2022-08-13 15:12:31 +05:30
|
|
|
const { line, path, searchResults } = props;
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const chars = line.content.map((content) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
return h(
|
|
|
|
'span',
|
|
|
|
{
|
|
|
|
class: ['gl-white-space-pre-wrap', content.style],
|
|
|
|
},
|
|
|
|
// Simple "tokenization": Split text in chunks of text
|
|
|
|
// which alternate between text and urls.
|
2021-03-08 18:12:59 +05:30
|
|
|
content.text.split(linkRegex).map((chunk) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
// Return normal string for non-links
|
|
|
|
if (!chunk.match(linkRegex)) {
|
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
return h(
|
|
|
|
'a',
|
|
|
|
{
|
|
|
|
attrs: {
|
|
|
|
href: chunk,
|
|
|
|
class: 'gl-reset-color! gl-text-decoration-underline',
|
|
|
|
rel: 'nofollow noopener noreferrer', // eslint-disable-line @gitlab/require-i18n-strings
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
},
|
|
|
|
chunk,
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
let applyHighlight = false;
|
|
|
|
|
|
|
|
if (searchResults.length > 0) {
|
|
|
|
const linesToHighlight = searchResults.map((searchResultLine) => searchResultLine.lineNumber);
|
|
|
|
|
|
|
|
linesToHighlight.forEach((num) => {
|
|
|
|
if (num === line.lineNumber) {
|
|
|
|
applyHighlight = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return h(
|
|
|
|
'div',
|
|
|
|
{
|
|
|
|
class: ['js-line', 'log-line', applyHighlight ? 'gl-bg-gray-500' : ''],
|
|
|
|
},
|
|
|
|
[
|
|
|
|
h(LineNumber, {
|
|
|
|
props: {
|
|
|
|
lineNumber: line.lineNumber,
|
|
|
|
path,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
...chars,
|
|
|
|
],
|
|
|
|
);
|
2020-07-28 23:09:34 +05:30
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
};
|
|
|
|
</script>
|