matchElements function

void matchElements(
  1. String value
)

Implementation

void matchElements (String value) {
  /// WARNING: DO NOT USE LOOKBEHIND it is unsupported in safari and other browsers.
  RegExp bdO =  RegExp(r"(([ \*\_\^\#\`])|\\)(\*\*)(?![ \*])"); // \ will escape the mandatory space before or after a character.
  RegExp bdC =  RegExp(r"\*\*((?=[ \*\_\^\#\`\\])|\\)");
  RegExp itO =  RegExp(r"(([ \*\_\^\#\`\\])|\\)(\*)(?![ \*])");
  RegExp itC =  RegExp(r"\*((?=[ \*\_\^\#\`\\])|\\)");
  RegExp sbO =  RegExp(r"(([ \*\_\^\#\`\\])|\\)(\^\^)(?![ \^])");
  RegExp sbC =  RegExp(r"\^\^((?=[ \*\_\^\#\`\\])|\\)");
  RegExp spO =  RegExp(r"(([ \*\_\^\#\`\\])|\\)(\^)(?![ \^])");
  RegExp spC =  RegExp(r"\^((?=[ \*\_\^\#\`\\])|\\)");
  RegExp unO =  RegExp(r"(([ \*\_\^\#\`\\])|\\)(\_)(?![ \_])");
  RegExp unC =  RegExp(r"(\_)((?=[ \*\_\^\#\`\\])|\\)");
  RegExp ovO =  RegExp(r"(([ \*\_\^\#\`\\])|\\)(\_\_\_)(?![ \_])");
  RegExp ovC =  RegExp(r"\_\_\_((?=[ \*\_\^\#\`\\])|\\)");
  RegExp stO =  RegExp(r"(([ \*\_\^\#\`\\])|\\)(\_\_)(?![ \_])");
  RegExp stC =  RegExp(r"\_\_((?=[ \*\_\^\#\`\\])|\\)");
  RegExp codeO = RegExp(r"(([ \*\_\^\#\`\\])|\\)(\`\`\`)(?![ \`])");
  RegExp codeC = RegExp(r"\`\`\`((?=[ \*\_\^\#\`\\])|\\)");

  // pad the value rather than adding extra cases for start and end of line
  if (value.length > 2) value = " " + value + " ";
  else return extractStyles(value, []); // There is nothing to apply markdown to

  while (bdO.firstMatch(value) != null && bdC.firstMatch(value) != null) // add or for start and end or add space to start and end
   {
    //value = value.replaceFirst(bdO, '###bol###');
    value = value.replaceFirstMapped(bdO, (match) => match.group(1)! + "###bol###");
    value = value.replaceFirst(bdC, '###bol###');
  }

  while (itO.firstMatch(value) != null && itC.firstMatch(value) != null)
  {
    //value = value.replaceFirst(itO, '###ita###', 1);
    value = value.replaceFirstMapped(itO, (match) => match.group(1)! + "###ita###");
    value = value.replaceFirst(itC, '###ita###');
  }





  while (sbO.firstMatch(value) != null && sbC.firstMatch(value) != null)
  {
    value = value.replaceFirstMapped(sbO, (match) => match.group(1)! + "###sub###");
    value = value.replaceFirst(sbC, '###sub###');
  }

  while (spO.firstMatch(value) != null && spC.firstMatch(value) != null)
  {
    value = value.replaceFirstMapped(spO, (match) => match.group(1)! + "###sup###");
    value = value.replaceFirst(spC, '###sup###');
  }

  while (ovO.firstMatch(value) != null && ovC.firstMatch(value) != null)
  {
    value = value.replaceFirstMapped(ovO, (match) => match.group(1)! + "###ove###");
    value = value.replaceFirst(ovC, '###ove###');
  }

  while (stO.firstMatch(value) != null && stC.firstMatch(value) != null)
  {
    value = value.replaceFirstMapped(stO, (match) => match.group(1)! + "###str###");
    value = value.replaceFirst(stC, '###str###');
  }

  while (unO.firstMatch(value) != null && unC.firstMatch(value) != null)
  {
    value = value.replaceFirstMapped(unO, (match) => match.group(1)! + "###und###");
    value = value.replaceFirst(unC, '###und###');
  }


  while (codeO.firstMatch(value) != null && codeC.firstMatch(value) != null) {
    value = value.replaceFirstMapped(codeO, (match) => match.group(1)! + "###code###");
    value = value.replaceFirst(codeC, '###code###');
  }

  return extractStyles(value, []);

}