All files / app/components/classes/subparagraph subParagraph.ts

100% Statements 3/3
100% Branches 1/1
100% Functions 1/1
100% Lines 3/3

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                                                                                        1814x 1814x 1814x      
import { SubParagraphRoot } from 'src/app/enums/subParagraphRoot';
 
/**
 * SubParagraph class.
 *
 * Used to dynamically create different elements to be nested inside a paragraph
 * with an html root `<p>` `</p>`. Those elements can be `<strong><em>`
 * `</em></strong>` elements, `<br>` elements, `<a/>` elements, or any
 * {@link SubParagraphRoot}.
 *
 * Do note that those elements are designed with the existence of code injection
 * in mind and/or malicious content in mind. For instance, `<a\>` links are
 * designed to be always prefixed by the asset folder path and hence avoid any
 * kind of attacks and injection of link to another domain (or even the same
 * domain but with an unexpected path).
 */
export class SubParagraph {
  /**
   * The root element of the subparagraph. Can be any defined in
   * {@link SubParagraphRoot}.
   */
  root: SubParagraphRoot;
  /** Text content of the subparagraph. */
  content: string;
  /**
   * Only useful when using {@link SubParagraphRoot} representing a link, and
   * this represent the href to the asset the node should link to. Do note that
   * it is necessarily a link to an asset and will, in fine, be prefixed by the
   * asset folder. This prevents any unwanted link to another domain, or to an
   * unwanted route.
   */
  assetHref: string;
 
  /**
   * SubPparagraph constructor.
   *
   * @param root The root element of the subparagraph. Can be any defined in
   *   {@link SubParagraphRoot}.
   * @param content Text content of the subparagraph.
   * @param assetHref Only useful when using {@link SubParagraphRoot}
   *   representing a link, and this represent the href to the asset the node
   *   should link to.
   */
  constructor(root: SubParagraphRoot, content: string, assetHref = '') {
    this.root = root;
    this.content = content;
    this.assetHref = assetHref;
  }
}