function i(o, t) {
  const c = o.pos, n = o.src.charCodeAt(c);
  if (t || n !== 95 && n !== 42)
    return !1;
  const e = o.scanDelims(o.pos, n === 42);
  for (let k = 0; k < e.length; k++) {
    const s = o.push("text", "", 0);
    s.content = String.fromCharCode(n), o.delimiters.push({
      // Char code of the starting marker (number).
      //
      marker: n,
      // Total length of these series of delimiters.
      //
      length: e.length,
      // A position of the token this delimiter corresponds to.
      //
      token: o.tokens.length - 1,
      // If this delimiter is matched as a valid opener, `end` will be
      // equal to its position, otherwise it's `-1`.
      //
      end: -1,
      // Boolean flags that determine if this delimiter could open or close
      // an emphasis.
      //
      open: e.can_open,
      close: e.can_close
    });
  }
  return o.pos += e.length, !0;
}
function g(o, t) {
  const c = t.length;
  for (let n = c - 1; n >= 0; n--) {
    const e = t[n];
    if (e.marker !== 95 && e.marker !== 42 || e.end === -1)
      continue;
    const k = t[e.end], s = n > 0 && t[n - 1].end === e.end + 1 && // check that first two markers match and adjacent
    t[n - 1].marker === e.marker && t[n - 1].token === e.token - 1 && // check that last two markers are adjacent (we can safely assume they match)
    t[e.end + 1].token === k.token + 1, r = String.fromCharCode(e.marker), m = o.tokens[e.token];
    m.type = s ? "strong_open" : "em_open", m.tag = s ? "strong" : "em", m.nesting = 1, m.markup = s ? r + r : r, m.content = "";
    const p = o.tokens[k.token];
    p.type = s ? "strong_close" : "em_close", p.tag = s ? "strong" : "em", p.nesting = -1, p.markup = s ? r + r : r, p.content = "", s && (o.tokens[t[n - 1].token].content = "", o.tokens[t[e.end + 1].token].content = "", n--);
  }
}
function a(o) {
  const t = o.tokens_meta, c = o.tokens_meta.length;
  g(o, o.delimiters);
  for (let n = 0; n < c; n++)
    t[n] && t[n].delimiters && g(o, t[n].delimiters);
}
const f = {
  tokenize: i,
  postProcess: a
};
export {
  f as default
};
