All files / app/assets/javascripts/content_editor/extensions reference.js

91.67% Statements 11/12
50% Branches 1/2
100% Functions 9/9
90.91% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 61 62 63 64 65 66 67 68      7x 20x                           623x     4x       4x       4x       4x       4x           89x                       4x                        
import { Node } from '@tiptap/core';
import { PARSE_HTML_PRIORITY_HIGHEST } from '../constants';
 
const getAnchor = (element) => {
  Eif (element.nodeName === 'A') return element;
  return element.querySelector('a');
};
 
export default Node.create({
  name: 'reference',
 
  inline: true,
 
  group: 'inline',
 
  atom: true,
 
  addAttributes() {
    return {
      className: {
        default: null,
        parseHTML: (element) => getAnchor(element).className,
      },
      referenceType: {
        default: null,
        parseHTML: (element) => getAnchor(element).dataset.referenceType,
      },
      originalText: {
        default: null,
        parseHTML: (element) => getAnchor(element).dataset.original,
      },
      href: {
        default: null,
        parseHTML: (element) => getAnchor(element).getAttribute('href'),
      },
      text: {
        default: null,
        parseHTML: (element) => getAnchor(element).textContent,
      },
    };
  },
 
  parseHTML() {
    return [
      {
        tag: 'a.gfm:not([data-link=true])',
        priority: PARSE_HTML_PRIORITY_HIGHEST,
      },
      {
        tag: 'span.gl-label',
      },
    ];
  },
 
  renderHTML({ node }) {
    return [
      'a',
      {
        class: node.attrs.className,
        href: node.attrs.href,
        'data-reference-type': node.attrs.referenceType,
        'data-original': node.attrs.originalText,
      },
      node.attrs.text,
    ];
  },
});