summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/components/log/line.vue
blob: 791664c05d981ef3ca1b38589009857c0e0941d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<script>
import linkifyHtml from 'linkifyjs/html';
import { sanitize } from '~/lib/dompurify';
import { isAbsolute } from '~/lib/utils/url_utility';
import LineNumber from './line_number.vue';

const linkifyOptions = {
  attributes: {
    // eslint-disable-next-line @gitlab/require-i18n-strings
    rel: 'nofollow noopener',
  },
  className: 'gl-reset-color!',
  defaultProtocol: 'https',
  validate: {
    email: false,
    url(value) {
      return isAbsolute(value);
    },
  },
};

export default {
  functional: true,
  props: {
    line: {
      type: Object,
      required: true,
    },
    path: {
      type: String,
      required: true,
    },
  },
  render(h, { props }) {
    const { line, path } = props;

    const chars = line.content.map(content => {
      const linkfied = linkifyHtml(content.text, linkifyOptions);
      return h('span', {
        class: ['gl-white-space-pre-wrap', content.style],
        domProps: {
          innerHTML: sanitize(linkfied, {
            ALLOWED_TAGS: ['a'],
          }),
        },
      });
    });

    return h('div', { class: 'js-line log-line' }, [
      h(LineNumber, {
        props: {
          lineNumber: line.lineNumber,
          path,
        },
      }),
      ...chars,
    ]);
  },
};
</script>