import { CodeHighlightParser } from './code-highlight-parser.abstract';
/**
 * Plain text parse logic.
 */
export class DefaultCodeHighlightParseController extends CodeHighlightParser {
  /**
   * Default parser will handle if others not catch.
   *
   * @returns {boolean} True value.
   */
  canParse() {
    const { code, language } = this.value || { code: '' };
    return !code || !language || language === 'plainText' || !this.isHighlightLanguage(language);
  }
  /**
   * The default parse will split the html tag and create the line number.
   *
   * @returns {CodeNodeType[]} - The code node array.
   */
  parse() {
    var _a, _b;
    const code = (_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : '';
    const nodes = code.split(/(\n)/);
    let result = [];
    nodes.forEach((item) => {
      if (item) {
        const textArray = this.splitTag(item);
        result.push(...textArray.map((text) => ({ text, key: '', className: '' })));
      }
    });
    result = this.markLineNumberNodes(result);
    return result;
  }
}
