private function createNodes($document, $string) {
    foreach (self::$_replacements as $pattern => $replacement) {
      /** @var array $replacement */
      if (preg_match($pattern, $string)) {
        $node = $document->createElement($replacement[0]);
        if (is_array($replacement[1])) {
          foreach ($replacement[1] as $attributeName => $attributePattern) {
            $node->setAttribute(
              $attributeName,
              preg_replace(
                $pattern, $attributePattern, $string
              )
            );
          }
        }
        $text = $document->createTextNode(
          preg_replace(
            $pattern, $replacement[2], $string
          )
        );
        $node->appendChild($text);
        return $node;
      }
    }
    return $document->createTextNode(
      strtr($string, self::$_escaping)
    );
  }