# All files / src/utils MarkdownTokenFactory.js

47.62% Statements 20/42
0% Branches 0/4
0% Functions 0/14
47.62% Lines 20/42

    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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    884x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

    4x

     var RegularMarkdownToken = function(token, isSymetric) {
      this.token = token;
      this.isSymetric = isSymetric;
    };

    RegularMarkdownToken.prototype.applyTokenTo = function(_text) {
      var res = this.token;
      res += _text;

      if (this.isSymetric) {
        res += this.token;
      }

      return res;
    };

    var NullMarkdownToken = function() {
      RegularMarkdownToken.call(this, '', false);
    };

    NullMarkdownToken.prototype = Object.create(RegularMarkdownToken.prototype);

    NullMarkdownToken.prototype.applyTokenTo = function(_text) {
      return _text;
    };

    var HeaderMarkdownToken = function(_token) {
      var t = _token || '##';
      RegularMarkdownToken.call(this, t, false);
    };

    HeaderMarkdownToken.prototype = Object.create(RegularMarkdownToken.prototype);

    HeaderMarkdownToken.prototype.applyTokenTo = function(_text) {
      return '\n' + this.token + ' ' + _text + '\n';
    };

    var SubHeaderMarkdownToken = function() {
      HeaderMarkdownToken.call(this, '###', false);
    };

    SubHeaderMarkdownToken.prototype = Object.create(HeaderMarkdownToken.prototype);

    var UrlMarkdownToken = function() {
      RegularMarkdownToken.call(this, null, false);
    };

    UrlMarkdownToken.prototype = Object.create(RegularMarkdownToken.prototype);

    UrlMarkdownToken.prototype.applyTokenTo = function(_text) {
      return '[' + _text + '](' + _text + ')';
    };

    var ListMarkdownToken = function() {
      RegularMarkdownToken.call(this, null, false);
    };

    ListMarkdownToken.prototype = Object.create(RegularMarkdownToken.prototype);

    ListMarkdownToken.prototype.applyTokenTo = function(_text) {
      var items = _text.split('\n');
      var t = items.reduce(function(acc, item) {
        return acc + '+ ' + item + '\n';
      }, '\n');

      return t + '\n';
    };

    var ImageMarkdownToken = function() {
      RegularMarkdownToken.call(this, null, false);
    };

    ImageMarkdownToken.prototype = Object.create(RegularMarkdownToken.prototype);

    ImageMarkdownToken.prototype.applyTokenTo = function(_text) {
      return '![' + _text + '](' + _text + ')';
    };

    module.exports = {
      RegularMarkdownToken: RegularMarkdownToken,
      NullMarkdownToken: NullMarkdownToken,
      HeaderMarkdownToken: HeaderMarkdownToken,
      SubHeaderMarkdownToken: SubHeaderMarkdownToken,
      UrlMarkdownToken: UrlMarkdownToken,
      ListMarkdownToken: ListMarkdownToken,
      ImageMarkdownToken: ImageMarkdownToken
    };