"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _unified = require("unified");
var _remarkParse = _interopRequireDefault(require("remark-parse"));
var _remarkGfm = _interopRequireDefault(require("remark-gfm"));
var _remarkMath = _interopRequireDefault(require("remark-math"));
var _core = require("../../extension/core");
var _transform = require("./transform");
// md string -> md ast
const getProcessor = () => {
  const processor = (0, _unified.unified)().use(_remarkParse.default) // Handles markdown basic syntax
  .use(_remarkGfm.default) // Handle markdown extension syntax
  .use(_remarkMath.default); // Handles markdown math formulas

  return processor;
};
const reconciledSlateNodes = nodes => {
  return nodes;
};

// md string --> md ast --> slate ast
// https://github.com/syntax-tree/mdast
const mdStringToSlate = mdString => {
  if (!mdString) return [(0, _core.generateDefaultParagraph)()];
  let content = mdString;
  if (typeof mdString === 'number') {
    content = mdString + '';
  }

  // md string --> md ast
  const root = getProcessor().parse(content);

  // the mdString is '\r\n'
  if (root.children.length === 0) {
    return [(0, _core.generateDefaultParagraph)()];
  }

  // md ast --> slate ast
  const slateNodes = (0, _transform.formatMdToSlate)(root.children);

  // Format the document
  return reconciledSlateNodes(slateNodes);
};
var _default = exports.default = mdStringToSlate;