All files index.tsx

95.65% Statements 22/23
100% Branches 6/6
83.33% Functions 5/6
95.45% Lines 21/22

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 621x 1x         6x 6x     2x                 2x   2x 1x             2x         6x 6x   6x   2x 2x 1x   1x     4x 1x   3x         1x           1x  
import hljs from 'highlight.js';
import React from 'react';
 
class Highlight extends React.Component {
    //@ts-ignore
    constructor(props) {
      super(props)
      this.setEl = this.setEl.bind(this)
    }
    componentDidMount() {
        this.highlightCode();
    }
 
    componentDidUpdate() {
        this.highlightCode();
    }
 
    highlightCode() {
        //@ts-ignore
        const nodes = this.el.querySelectorAll('pre code');
 
        for (let i = 0; i < nodes.length; i++) {
            hljs.highlightBlock(nodes[i])
        }
    }
 
    //@ts-ignore
    setEl(el) {
        //@ts-ignore
        this.el = el;
    };
 
    render() {
        //@ts-ignore
        const {children, className, element: Element, innerHTML} = this.props;
        const props = { ref: this.setEl, className };
 
        if (innerHTML) {
            //@ts-ignore
            props.dangerouslySetInnerHTML = { __html: children };
            if (Element) {
                return <Element {...props} />;
            }
            return <div {...props} />;
        }
 
        if (Element) {
            return <Element {...props}>{children}</Element>;
        }
        return <pre ref={this.setEl}><code className={className}>{children}</code></pre>;
    }
}
 
//@ts-ignore
Highlight.defaultProps = {
    innerHTML: false,
    className: null,
    element: null,
};
 
export default Highlight;