[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Plugins/Litedown/Parser/ -> ParsedText.js (source)

   1  /**
   2  * @type {boolean} Whether to decode HTML entities when decoding text
   3  */
   4  var decodeHtmlEntities = config.decodeHtmlEntities;
   5  
   6  /**
   7  * @type {boolean} Whether text contains escape characters
   8  */
   9  var hasEscapedChars = false;
  10  
  11  /**
  12  * @type {boolean} Whether text contains link references
  13  */
  14  var hasReferences = false;
  15  
  16  /**
  17  * @dict
  18  */
  19  var linkReferences = {};
  20  
  21  if (text.indexOf('\\') >= 0)
  22  {
  23      hasEscapedChars = true;
  24  
  25      // Encode escaped literals that have a special meaning otherwise, so that we don't have
  26      // to take them into account in regexps
  27      text = text.replace(
  28          /\\[!"'()*<>[\\\]^_`~]/g,
  29          function (str)
  30          {
  31              return {
  32                  '\\!': "\x1B0", '\\"' : "\x1B1", "\\'": "\x1B2", '\\(': "\x1B3",
  33                  '\\)': "\x1B4", '\\*' : "\x1B5", '\\<': "\x1B6", '\\>': "\x1B7",
  34                  '\\[': "\x1B8", '\\\\': "\x1B9", '\\]': "\x1BA", '\\^': "\x1BB",
  35                  '\\_': "\x1BC", '\\`' : "\x1BD", '\\~': "\x1BE"
  36              }[str];
  37          }
  38      );
  39  }
  40  
  41  // We append a couple of lines and a non-whitespace character at the end of the text in
  42  // order to trigger the closure of all open blocks such as quotes and lists
  43  text += "\n\n\x17";
  44  
  45  /**
  46  * Decode a chunk of encoded text to be used as an attribute value
  47  *
  48  * Decodes escaped literals and removes slashes and 0x1A characters
  49  *
  50  * @param  {string} str Encoded text
  51  * @return {string}     Decoded text
  52  */
  53  function decode(str)
  54  {
  55      if (HINT.LITEDOWN_DECODE_HTML_ENTITIES && decodeHtmlEntities && str.indexOf('&') > -1)
  56      {
  57          str = html_entity_decode(str);
  58      }
  59      str = str.replace(/\x1A/g, '');
  60  
  61      if (hasEscapedChars)
  62      {
  63          str = str.replace(
  64              /\x1B./g,
  65              function (seq)
  66              {
  67                  return {
  68                      "\x1B0": '!', "\x1B1": '"',  "\x1B2": "'", "\x1B3": '(',
  69                      "\x1B4": ')', "\x1B5": '*',  "\x1B6": '<', "\x1B7": '>',
  70                      "\x1B8": '[', "\x1B9": '\\', "\x1BA": ']', "\x1BB": '^',
  71                      "\x1BC": '_', "\x1BD": '`',  "\x1BE": '~'
  72                  }[seq];
  73              }
  74          );
  75      }
  76  
  77      return str;
  78  }
  79  
  80  /**
  81  * Test whether given position is preceded by whitespace
  82  *
  83  * @param  {number}  pos
  84  * @return {boolean}
  85  */
  86  function isAfterWhitespace(pos)
  87  {
  88      return (pos > 0 && isWhitespace(text.charAt(pos - 1)));
  89  }
  90  
  91  /**
  92  * Test whether given character is alphanumeric
  93  *
  94  * @param  {string}  chr
  95  * @return {boolean}
  96  */
  97  function isAlnum(chr)
  98  {
  99      return (' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.indexOf(chr) > 0);
 100  }
 101  
 102  /**
 103  * Test whether given position is followed by whitespace
 104  *
 105  * @param  {number}  pos
 106  * @return {boolean}
 107  */
 108  function isBeforeWhitespace(pos)
 109  {
 110      return isWhitespace(text[pos + 1]);
 111  }
 112  
 113  /**
 114  * Test whether a length of text is surrounded by alphanumeric characters
 115  *
 116  * @param  {number}  pos Start of the text
 117  * @param  {number}  len Length of the text
 118  * @return {boolean}
 119  */
 120  function isSurroundedByAlnum(pos, len)
 121  {
 122      return (pos > 0 && isAlnum(text[pos - 1]) && isAlnum(text[pos + len]));
 123  }
 124  
 125  /**
 126  * Test whether given character is an ASCII whitespace character
 127  *
 128  * NOTE: newlines are normalized to LF before parsing so we don't have to check for CR
 129  *
 130  * @param  {string}  chr
 131  * @return {boolean}
 132  */
 133  function isWhitespace(chr)
 134  {
 135      return (" \n\t".indexOf(chr) > -1);
 136  }
 137  
 138  /**
 139  * Mark the boundary of a block in the original text
 140  *
 141  * @param {number} pos
 142  */
 143  function markBoundary(pos)
 144  {
 145      text = text.substring(0, pos) + "\x17" + text.substring(pos + 1);
 146  }
 147  
 148  /**
 149  * Overwrite part of the text with substitution characters ^Z (0x1A)
 150  *
 151  * @param  {number} pos Start of the range
 152  * @param  {number} len Length of text to overwrite
 153  */
 154  function overwrite(pos, len)
 155  {
 156      if (len > 0)
 157      {
 158          text = text.substring(0, pos) + new Array(1 + len).join("\x1A") + text.substring(pos + len);
 159      }
 160  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1