@mtcute/markdown-parser 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { InputText, MessageEntity, TextWithEntities } from '@mtcute/client';
1
+ import type { InputText, MessageEntity, TextWithEntities } from '@mtcute/core';
2
2
  /**
3
3
  * Escape a string to be safely used in Markdown.
4
4
  *
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAIvB,MAAM,aAAa,GAAG,6DAA6D,CAAA;AACnF,MAAM,WAAW,GAAG,2BAA2B,CAAA;AAE/C,MAAM,QAAQ,GAAG,IAAI,CAAA;AACrB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,aAAa,GAAG,IAAI,CAAA;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,QAAQ,GAAG,GAAG,CAAA;AACpB,MAAM,OAAO,GAAG,KAAK,CAAA;AAErB,MAAM,aAAa,GAAG,iBAAiB,CAAA;AAEvC;;;;;GAKG;AACH,SAAS,MAAM,CAAC,GAAW;IACvB,OAAO,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAA;AACtD,CAAC;AAED;;GAEG;AACH,SAAS,OAAO,CAAC,KAAgB;IAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IAEnD,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAA;IAErC,qDAAqD;IACrD,MAAM,OAAO,GAAa,EAAE,CAAA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AAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAChD,IAAI,KAAK,CAAC,MAAM,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,SAAS,CAAC,CAAA;SACjD;KACJ;IAED,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,QAAQ;KACX,CAAA;AACL,CAAC;AAED,oEAAoE;AACpE,oDAAoD;AAEvC,QAAA,EAAE,GAmCX,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;IACrB,MAAM;IACN,OAAO;CACV,CAAC,CAAA","sourcesContent":["import Long from 'long'\n\nimport type { InputText, MessageEntity, TextWithEntities, tl } from '@mtcute/client'\n\nconst MENTION_REGEX = /^tg:\\/\\/user\\?id=(\\d+)(?:&hash=(-?[0-9a-fA-F]+)(?:&|$)|&|$)/\nconst EMOJI_REGEX = /^tg:\\/\\/emoji\\?id=(-?\\d+)/\n\nconst TAG_BOLD = '**'\nconst TAG_ITALIC = '__'\nconst TAG_UNDERLINE = '--'\nconst TAG_STRIKE = '~~'\nconst TAG_SPOILER = '||'\nconst TAG_CODE = '`'\nconst TAG_PRE = '```'\n\nconst TO_BE_ESCAPED = /[*_\\-~`[\\\\\\]|]/g\n\n/**\n * Escape a string to be safely used in Markdown.\n *\n * > **Note**: this function is in most cases not needed, as `md` function\n * > handles all `string`s passed to it automatically as plain text.\n */\nfunction escape(str: string): string {\n return str.replace(TO_BE_ESCAPED, (s) => '\\\\' + s)\n}\n\n/**\n * Add Markdown formatting to the text given the plain text and entities contained in it.\n */\nfunction unparse(input: InputText): string {\n if (typeof input === 'string') return escape(input)\n\n let text = input.text\n const entities = input.entities ?? []\n\n // keep track of positions of inserted escape symbols\n const escaped: number[] = []\n text = text.replace(TO_BE_ESCAPED, (s, pos: number) => {\n escaped.push(pos)\n\n return '\\\\' + s\n })\n const hasEscaped = escaped.length > 0\n\n type InsertLater = [number, string]\n const insert: InsertLater[] = []\n\n for (const entity of entities) {\n const type = entity._\n\n let start = entity.offset\n let end = start + entity.length\n\n if (start > text.length) continue\n if (start < 0) start = 0\n if (end > text.length) end = text.length\n\n if (hasEscaped) {\n // determine number of escape chars since the beginning of the string\n let escapedPos = 0\n\n while (escapedPos < escaped.length && escaped[escapedPos] < start) {\n escapedPos += 1\n }\n start += escapedPos\n\n while (escapedPos < escaped.length && escaped[escapedPos] <= end) {\n escapedPos += 1\n }\n end += escapedPos\n }\n\n let startTag\n let endTag: string\n\n switch (type) {\n case 'messageEntityBold':\n startTag = endTag = TAG_BOLD\n break\n case 'messageEntityItalic':\n startTag = endTag = TAG_ITALIC\n break\n case 'messageEntityUnderline':\n startTag = endTag = TAG_UNDERLINE\n break\n case 'messageEntityStrike':\n startTag = endTag = TAG_STRIKE\n break\n case 'messageEntitySpoiler':\n startTag = endTag = TAG_SPOILER\n break\n case 'messageEntityCode':\n startTag = endTag = TAG_CODE\n break\n case 'messageEntityPre':\n startTag = TAG_PRE\n\n if (entity.language) {\n startTag += entity.language\n }\n\n startTag += '\\n'\n endTag = '\\n' + TAG_PRE\n break\n case 'messageEntityTextUrl':\n startTag = '['\n endTag = `](${entity.url})`\n break\n case 'messageEntityMentionName':\n startTag = '['\n endTag = `](tg://user?id=${entity.userId})`\n break\n case 'messageEntityCustomEmoji':\n startTag = '['\n endTag = `](tg://emoji?id=${entity.documentId.toString()})`\n break\n default:\n continue\n }\n\n insert.push([start, startTag])\n insert.push([end, endTag])\n }\n\n // sort by offset desc\n insert.sort((a, b) => b[0] - a[0])\n\n for (const [offset, tag] of insert) {\n text = text.substr(0, offset) + tag + text.substr(offset)\n }\n\n return text\n}\n\nfunction parse(\n strings: TemplateStringsArray | string,\n ...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]\n): TextWithEntities {\n const entities: tl.TypeMessageEntity[] = []\n let result = ''\n\n const stacks: Record<string, tl.Mutable<tl.TypeMessageEntity>[]> = {}\n\n let insideCode = false\n let insidePre = false\n let insideLink = false\n\n function feed(text: string) {\n const len = text.length\n let pos = 0\n\n while (pos < len) {\n const c = text[pos]\n\n if (c === '\\\\') {\n result += text[pos + 1]\n pos += 2\n continue\n }\n\n if (insideCode) {\n if (c === '`') {\n // we can be certain that we're inside code\n\n const ent = stacks.code.pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n insideCode = false\n pos += 1\n } else {\n pos += 1\n result += c\n }\n continue\n }\n\n if (insidePre) {\n if (c === '`' || (c === '\\n' && text[pos + 1] === '`')) {\n if (c === '\\n') pos += 1\n\n if (text[pos + 1] === '`' && text[pos + 2] === '`') {\n // we can be certain that we're inside pre\n\n const ent = stacks.pre.pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n insidePre = false\n pos += 3\n continue\n\n // closed with single or double backtick\n // i.e. not closed actually! this is totally valid md:\n // ```javascript\n // const a = ``;\n // ```\n // compensate that `pos` change we made earliers\n } else if (c === '\\n') {\n pos -= 1\n }\n }\n\n pos += 1\n result += c\n continue\n }\n\n if (insideLink && c === ']') {\n // we can be certain that we're inside link\n\n const ent = stacks.link.pop()!\n\n if (text[pos + 1] !== '(') {\n // [link text]\n // ignore this, and add opening [\n result = `${result.substr(0, ent.offset)}[${result.substr(ent.offset)}]`\n pos += 1\n insideLink = false\n continue\n }\n\n pos += 2\n let url = ''\n\n while (pos < text.length && text[pos] !== ')') {\n url += text[pos++]\n }\n\n pos += 1 // )\n\n if (pos > text.length) {\n throw new Error('Malformed LINK entity, expected )')\n }\n\n if (url.length) {\n ent.length = result.length - ent.offset\n\n let m = url.match(MENTION_REGEX)\n\n if (m) {\n const userId = parseInt(m[1])\n const accessHash = m[2]\n\n if (accessHash) {\n (ent as tl.Mutable<tl.RawInputMessageEntityMentionName>)._ =\n 'inputMessageEntityMentionName'\n ;(ent as tl.Mutable<tl.RawInputMessageEntityMentionName>).userId = {\n _: 'inputUser',\n userId,\n accessHash: Long.fromString(accessHash, false, 16),\n }\n } else {\n (ent as tl.Mutable<tl.RawMessageEntityMentionName>)._ = 'messageEntityMentionName'\n ;(ent as tl.Mutable<tl.RawMessageEntityMentionName>).userId = userId\n }\n } else if ((m = EMOJI_REGEX.exec(url))) {\n (ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>)._ = 'messageEntityCustomEmoji'\n ;(ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>).documentId = Long.fromString(m[1])\n } else {\n if (url.match(/^\\/\\//)) url = 'http:' + url\n ;(ent as tl.Mutable<tl.RawMessageEntityTextUrl>)._ = 'messageEntityTextUrl'\n ;(ent as tl.Mutable<tl.RawMessageEntityTextUrl>).url = url\n }\n entities.push(ent)\n }\n\n insideLink = false\n continue\n }\n\n if (c === '[' && !insideLink) {\n pos += 1\n insideLink = true\n if (!('link' in stacks)) stacks.link = []\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n stacks.link.push({\n offset: result.length,\n length: 0,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any) // other fields are added after the second part\n continue\n }\n\n if (c === '`') {\n const isPre = text[pos + 1] === '`' && text[pos + 2] === '`'\n\n if (isPre) {\n pos += 3\n let language = ''\n\n while (pos < text.length && text[pos] !== '\\n') {\n language += text[pos++]\n }\n\n // newline\n pos += 1\n\n if (pos > text.length) {\n throw new Error('Malformed PRE entity, expected LF after ```')\n }\n\n if (!('pre' in stacks)) stacks.pre = []\n stacks.pre.push({\n _: 'messageEntityPre',\n offset: result.length,\n length: 0,\n language,\n })\n insidePre = true\n } else {\n pos += 1\n if (!('code' in stacks)) stacks.code = []\n stacks.code.push({\n _: 'messageEntityCode',\n offset: result.length,\n length: 0,\n })\n insideCode = true\n }\n\n continue\n }\n\n if (c === text[pos + 1]) {\n // maybe (?) start or end of an entity\n let type: 'Italic' | 'Bold' | 'Underline' | 'Strike' | 'Spoiler' | null = null\n\n switch (c) {\n case '_':\n type = 'Italic'\n break\n case '*':\n type = 'Bold'\n break\n case '-':\n type = 'Underline'\n break\n case '~':\n type = 'Strike'\n break\n case '|':\n type = 'Spoiler'\n break\n }\n\n if (type) {\n if (!(type in stacks)) stacks[type] = []\n const isBegin = stacks[type].length === 0\n\n if (isBegin) {\n stacks[type].push({\n _: `messageEntity${type}`,\n offset: result.length,\n length: 0,\n })\n } else {\n // valid because isBegin is false\n\n const ent = stacks[type].pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n }\n\n pos += 2\n continue\n }\n }\n\n if (c === '\\n') {\n if (pos !== 0) {\n result += '\\n'\n }\n\n const nonWhitespace = text.slice(pos + 1).search(/\\S/)\n\n if (nonWhitespace !== -1) {\n pos += nonWhitespace + 1\n } else {\n pos = len\n result = result.trimEnd()\n }\n continue\n }\n\n // nothing matched => normal character\n result += c\n pos += 1\n }\n }\n\n if (typeof strings === 'string') strings = [strings] as unknown as TemplateStringsArray\n\n sub.forEach((it, idx) => {\n feed(strings[idx])\n\n if (typeof it === 'boolean' || !it) return\n\n if (typeof it === 'string' || typeof it === 'number') {\n result += it\n } else {\n // TextWithEntities or MessageEntity\n const text = it.text\n const innerEntities = 'raw' in it ? [it.raw] : it.entities\n\n const baseOffset = result.length\n result += text\n\n if (innerEntities) {\n for (const ent of innerEntities) {\n entities.push({ ...ent, offset: ent.offset + baseOffset })\n }\n }\n }\n })\n\n feed(strings[strings.length - 1])\n\n for (const [name, stack] of Object.entries(stacks)) {\n if (stack.length) {\n throw new Error(`Unterminated ${name} entity`)\n }\n }\n\n return {\n text: result,\n entities,\n }\n}\n\n// typedoc doesn't support this yet, so we'll have to do it manually\n// https://github.com/TypeStrong/typedoc/issues/2436\n\nexport const md: {\n /**\n * Tagged template based Markdown-to-entities parser function\n *\n * Additionally, `md` function has two static methods:\n * - `md.escape` - escape a string to be safely used in Markdown\n * (should not be needed in most cases, as `md` function itself handles all `string`s\n * passed to it automatically as plain text)\n * - `md.unparse` - add Markdown formatting to the text given the plain text and entities contained in it\n *\n * @example\n * ```typescript\n * const text = md`**${user.displayName}**`\n * ```\n */\n (\n strings: TemplateStringsArray,\n ...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]\n ): TextWithEntities\n /**\n * A variant taking a plain JS string as input\n * and parsing it.\n *\n * Useful for cases when you already have a string\n * (e.g. from some server) and want to parse it.\n *\n * @example\n * ```typescript\n * const string = '**hello**'\n * const text = md(string)\n * ```\n */\n (string: string): TextWithEntities\n escape: typeof escape\n unparse: typeof unparse\n} = Object.assign(parse, {\n escape,\n unparse,\n})\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAIvB,MAAM,aAAa,GAAG,6DAA6D,CAAA;AACnF,MAAM,WAAW,GAAG,2BAA2B,CAAA;AAE/C,MAAM,QAAQ,GAAG,IAAI,CAAA;AACrB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,aAAa,GAAG,IAAI,CAAA;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,QAAQ,GAAG,GAAG,CAAA;AACpB,MAAM,OAAO,GAAG,KAAK,CAAA;AAErB,MAAM,aAAa,GAAG,iBAAiB,CAAA;AAEvC;;;;;GAKG;AACH,SAAS,MAAM,CAAC,GAAW;IACvB,OAAO,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAA;AACtD,CAAC;AAED;;GAEG;AACH,SAAS,OAAO,CAAC,KAAgB;IAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IAEnD,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAA;IAErC,qDAAqD;IACrD,MAAM,OAAO,GAAa,EAAE,CAAA;IAC5B,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,GAAW,EAA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AAC,MAAM,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,SAAS,CAAC,CAAA;SACjD;KACJ;IAED,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,QAAQ;KACX,CAAA;AACL,CAAC;AAED,oEAAoE;AACpE,oDAAoD;AAEvC,QAAA,EAAE,GAmCX,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;IACrB,MAAM;IACN,OAAO;CACV,CAAC,CAAA","sourcesContent":["import Long from 'long'\n\nimport type { InputText, MessageEntity, TextWithEntities, tl } from '@mtcute/core'\n\nconst MENTION_REGEX = /^tg:\\/\\/user\\?id=(\\d+)(?:&hash=(-?[0-9a-fA-F]+)(?:&|$)|&|$)/\nconst EMOJI_REGEX = /^tg:\\/\\/emoji\\?id=(-?\\d+)/\n\nconst TAG_BOLD = '**'\nconst TAG_ITALIC = '__'\nconst TAG_UNDERLINE = '--'\nconst TAG_STRIKE = '~~'\nconst TAG_SPOILER = '||'\nconst TAG_CODE = '`'\nconst TAG_PRE = '```'\n\nconst TO_BE_ESCAPED = /[*_\\-~`[\\\\\\]|]/g\n\n/**\n * Escape a string to be safely used in Markdown.\n *\n * > **Note**: this function is in most cases not needed, as `md` function\n * > handles all `string`s passed to it automatically as plain text.\n */\nfunction escape(str: string): string {\n return str.replace(TO_BE_ESCAPED, (s) => '\\\\' + s)\n}\n\n/**\n * Add Markdown formatting to the text given the plain text and entities contained in it.\n */\nfunction unparse(input: InputText): string {\n if (typeof input === 'string') return escape(input)\n\n let text = input.text\n const entities = input.entities ?? []\n\n // keep track of positions of inserted escape symbols\n const escaped: number[] = []\n text = text.replace(TO_BE_ESCAPED, (s, pos: number) => {\n escaped.push(pos)\n\n return '\\\\' + s\n })\n const hasEscaped = escaped.length > 0\n\n type InsertLater = [number, string]\n const insert: InsertLater[] = []\n\n for (const entity of entities) {\n const type = entity._\n\n let start = entity.offset\n let end = start + entity.length\n\n if (start > text.length) continue\n if (start < 0) start = 0\n if (end > text.length) end = text.length\n\n if (hasEscaped) {\n // determine number of escape chars since the beginning of the string\n let escapedPos = 0\n\n while (escapedPos < escaped.length && escaped[escapedPos] < start) {\n escapedPos += 1\n }\n start += escapedPos\n\n while (escapedPos < escaped.length && escaped[escapedPos] <= end) {\n escapedPos += 1\n }\n end += escapedPos\n }\n\n let startTag\n let endTag: string\n\n switch (type) {\n case 'messageEntityBold':\n startTag = endTag = TAG_BOLD\n break\n case 'messageEntityItalic':\n startTag = endTag = TAG_ITALIC\n break\n case 'messageEntityUnderline':\n startTag = endTag = TAG_UNDERLINE\n break\n case 'messageEntityStrike':\n startTag = endTag = TAG_STRIKE\n break\n case 'messageEntitySpoiler':\n startTag = endTag = TAG_SPOILER\n break\n case 'messageEntityCode':\n startTag = endTag = TAG_CODE\n break\n case 'messageEntityPre':\n startTag = TAG_PRE\n\n if (entity.language) {\n startTag += entity.language\n }\n\n startTag += '\\n'\n endTag = '\\n' + TAG_PRE\n break\n case 'messageEntityTextUrl':\n startTag = '['\n endTag = `](${entity.url})`\n break\n case 'messageEntityMentionName':\n startTag = '['\n endTag = `](tg://user?id=${entity.userId})`\n break\n case 'messageEntityCustomEmoji':\n startTag = '['\n endTag = `](tg://emoji?id=${entity.documentId.toString()})`\n break\n default:\n continue\n }\n\n insert.push([start, startTag])\n insert.push([end, endTag])\n }\n\n // sort by offset desc\n insert.sort((a, b) => b[0] - a[0])\n\n for (const [offset, tag] of insert) {\n text = text.substr(0, offset) + tag + text.substr(offset)\n }\n\n return text\n}\n\nfunction parse(\n strings: TemplateStringsArray | string,\n ...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]\n): TextWithEntities {\n const entities: tl.TypeMessageEntity[] = []\n let result = ''\n\n const stacks: Record<string, tl.Mutable<tl.TypeMessageEntity>[]> = {}\n\n let insideCode = false\n let insidePre = false\n let insideLink = false\n\n function feed(text: string) {\n const len = text.length\n let pos = 0\n\n while (pos < len) {\n const c = text[pos]\n\n if (c === '\\\\') {\n result += text[pos + 1]\n pos += 2\n continue\n }\n\n if (insideCode) {\n if (c === '`') {\n // we can be certain that we're inside code\n\n const ent = stacks.code.pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n insideCode = false\n pos += 1\n } else {\n pos += 1\n result += c\n }\n continue\n }\n\n if (insidePre) {\n if (c === '`' || (c === '\\n' && text[pos + 1] === '`')) {\n if (c === '\\n') pos += 1\n\n if (text[pos + 1] === '`' && text[pos + 2] === '`') {\n // we can be certain that we're inside pre\n\n const ent = stacks.pre.pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n insidePre = false\n pos += 3\n continue\n\n // closed with single or double backtick\n // i.e. not closed actually! this is totally valid md:\n // ```javascript\n // const a = ``;\n // ```\n // compensate that `pos` change we made earliers\n } else if (c === '\\n') {\n pos -= 1\n }\n }\n\n pos += 1\n result += c\n continue\n }\n\n if (insideLink && c === ']') {\n // we can be certain that we're inside link\n\n const ent = stacks.link.pop()!\n\n if (text[pos + 1] !== '(') {\n // [link text]\n // ignore this, and add opening [\n result = `${result.substr(0, ent.offset)}[${result.substr(ent.offset)}]`\n pos += 1\n insideLink = false\n continue\n }\n\n pos += 2\n let url = ''\n\n while (pos < text.length && text[pos] !== ')') {\n url += text[pos++]\n }\n\n pos += 1 // )\n\n if (pos > text.length) {\n throw new Error('Malformed LINK entity, expected )')\n }\n\n if (url.length) {\n ent.length = result.length - ent.offset\n\n let m = url.match(MENTION_REGEX)\n\n if (m) {\n const userId = parseInt(m[1])\n const accessHash = m[2]\n\n if (accessHash) {\n (ent as tl.Mutable<tl.RawInputMessageEntityMentionName>)._ =\n 'inputMessageEntityMentionName'\n ;(ent as tl.Mutable<tl.RawInputMessageEntityMentionName>).userId = {\n _: 'inputUser',\n userId,\n accessHash: Long.fromString(accessHash, false, 16),\n }\n } else {\n (ent as tl.Mutable<tl.RawMessageEntityMentionName>)._ = 'messageEntityMentionName'\n ;(ent as tl.Mutable<tl.RawMessageEntityMentionName>).userId = userId\n }\n } else if ((m = EMOJI_REGEX.exec(url))) {\n (ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>)._ = 'messageEntityCustomEmoji'\n ;(ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>).documentId = Long.fromString(m[1])\n } else {\n if (url.match(/^\\/\\//)) url = 'http:' + url\n ;(ent as tl.Mutable<tl.RawMessageEntityTextUrl>)._ = 'messageEntityTextUrl'\n ;(ent as tl.Mutable<tl.RawMessageEntityTextUrl>).url = url\n }\n entities.push(ent)\n }\n\n insideLink = false\n continue\n }\n\n if (c === '[' && !insideLink) {\n pos += 1\n insideLink = true\n if (!('link' in stacks)) stacks.link = []\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n stacks.link.push({\n offset: result.length,\n length: 0,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any) // other fields are added after the second part\n continue\n }\n\n if (c === '`') {\n const isPre = text[pos + 1] === '`' && text[pos + 2] === '`'\n\n if (isPre) {\n pos += 3\n let language = ''\n\n while (pos < text.length && text[pos] !== '\\n') {\n language += text[pos++]\n }\n\n // newline\n pos += 1\n\n if (pos > text.length) {\n throw new Error('Malformed PRE entity, expected LF after ```')\n }\n\n if (!('pre' in stacks)) stacks.pre = []\n stacks.pre.push({\n _: 'messageEntityPre',\n offset: result.length,\n length: 0,\n language,\n })\n insidePre = true\n } else {\n pos += 1\n if (!('code' in stacks)) stacks.code = []\n stacks.code.push({\n _: 'messageEntityCode',\n offset: result.length,\n length: 0,\n })\n insideCode = true\n }\n\n continue\n }\n\n if (c === text[pos + 1]) {\n // maybe (?) start or end of an entity\n let type: 'Italic' | 'Bold' | 'Underline' | 'Strike' | 'Spoiler' | null = null\n\n switch (c) {\n case '_':\n type = 'Italic'\n break\n case '*':\n type = 'Bold'\n break\n case '-':\n type = 'Underline'\n break\n case '~':\n type = 'Strike'\n break\n case '|':\n type = 'Spoiler'\n break\n }\n\n if (type) {\n if (!(type in stacks)) stacks[type] = []\n const isBegin = stacks[type].length === 0\n\n if (isBegin) {\n stacks[type].push({\n _: `messageEntity${type}`,\n offset: result.length,\n length: 0,\n })\n } else {\n // valid because isBegin is false\n\n const ent = stacks[type].pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n }\n\n pos += 2\n continue\n }\n }\n\n if (c === '\\n') {\n if (pos !== 0) {\n result += '\\n'\n }\n\n const nonWhitespace = text.slice(pos + 1).search(/\\S/)\n\n if (nonWhitespace !== -1) {\n pos += nonWhitespace + 1\n } else {\n pos = len\n result = result.trimEnd()\n }\n continue\n }\n\n // nothing matched => normal character\n result += c\n pos += 1\n }\n }\n\n if (typeof strings === 'string') strings = [strings] as unknown as TemplateStringsArray\n\n sub.forEach((it, idx) => {\n feed(strings[idx])\n\n if (typeof it === 'boolean' || !it) return\n\n if (typeof it === 'string' || typeof it === 'number') {\n result += it\n } else {\n // TextWithEntities or MessageEntity\n const text = it.text\n const innerEntities = 'raw' in it ? [it.raw] : it.entities\n\n const baseOffset = result.length\n result += text\n\n if (innerEntities) {\n for (const ent of innerEntities) {\n entities.push({ ...ent, offset: ent.offset + baseOffset })\n }\n }\n }\n })\n\n feed(strings[strings.length - 1])\n\n for (const [name, stack] of Object.entries(stacks)) {\n if (stack.length) {\n throw new Error(`Unterminated ${name} entity`)\n }\n }\n\n return {\n text: result,\n entities,\n }\n}\n\n// typedoc doesn't support this yet, so we'll have to do it manually\n// https://github.com/TypeStrong/typedoc/issues/2436\n\nexport const md: {\n /**\n * Tagged template based Markdown-to-entities parser function\n *\n * Additionally, `md` function has two static methods:\n * - `md.escape` - escape a string to be safely used in Markdown\n * (should not be needed in most cases, as `md` function itself handles all `string`s\n * passed to it automatically as plain text)\n * - `md.unparse` - add Markdown formatting to the text given the plain text and entities contained in it\n *\n * @example\n * ```typescript\n * const text = md`**${user.displayName}**`\n * ```\n */\n (\n strings: TemplateStringsArray,\n ...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]\n ): TextWithEntities\n /**\n * A variant taking a plain JS string as input\n * and parsing it.\n *\n * Useful for cases when you already have a string\n * (e.g. from some server) and want to parse it.\n *\n * @example\n * ```typescript\n * const string = '**hello**'\n * const text = md(string)\n * ```\n */\n (string: string): TextWithEntities\n escape: typeof escape\n unparse: typeof unparse\n} = Object.assign(parse, {\n escape,\n unparse,\n})\n"]}
package/esm/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { InputText, MessageEntity, TextWithEntities } from '@mtcute/client';
1
+ import type { InputText, MessageEntity, TextWithEntities } from '@mtcute/core';
2
2
  /**
3
3
  * Escape a string to be safely used in Markdown.
4
4
  *
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAIvB,MAAM,aAAa,GAAG,6DAA6D,CAAA;AACnF,MAAM,WAAW,GAAG,2BAA2B,CAAA;AAE/C,MAAM,QAAQ,GAAG,IAAI,CAAA;AACrB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,aAAa,GAAG,IAAI,CAAA;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,QAAQ,GAAG,GAAG,CAAA;AACpB,MAAM,OAAO,GAAG,KAAK,CAAA;AAErB,MAAM,aAAa,GAAG,iBAAiB,CAAA;AAEvC;;;;;GAKG;AACH,SAAS,MAAM,CAAC,GAAW;IACvB,OAAO,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAA;AACtD,CAAC;AAED;;GAEG;AACH,SAAS,OAAO,CAAC,KAAgB;IAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IAEnD,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CA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C,CAAC,CAAC,CAAA;IAEjC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAChD,IAAI,KAAK,CAAC,MAAM,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,SAAS,CAAC,CAAA;SACjD;KACJ;IAED,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,QAAQ;KACX,CAAA;AACL,CAAC;AAED,oEAAoE;AACpE,oDAAoD;AAEpD,MAAM,CAAC,MAAM,EAAE,GAmCX,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;IACrB,MAAM;IACN,OAAO;CACV,CAAC,CAAA","sourcesContent":["import Long from 'long'\n\nimport type { InputText, MessageEntity, TextWithEntities, tl } from '@mtcute/client'\n\nconst MENTION_REGEX = /^tg:\\/\\/user\\?id=(\\d+)(?:&hash=(-?[0-9a-fA-F]+)(?:&|$)|&|$)/\nconst EMOJI_REGEX = /^tg:\\/\\/emoji\\?id=(-?\\d+)/\n\nconst TAG_BOLD = '**'\nconst TAG_ITALIC = '__'\nconst TAG_UNDERLINE = '--'\nconst TAG_STRIKE = '~~'\nconst TAG_SPOILER = '||'\nconst TAG_CODE = '`'\nconst TAG_PRE = '```'\n\nconst TO_BE_ESCAPED = /[*_\\-~`[\\\\\\]|]/g\n\n/**\n * Escape a string to be safely used in Markdown.\n *\n * > **Note**: this function is in most cases not needed, as `md` function\n * > handles all `string`s passed to it automatically as plain text.\n */\nfunction escape(str: string): string {\n return str.replace(TO_BE_ESCAPED, (s) => '\\\\' + s)\n}\n\n/**\n * Add Markdown formatting to the text given the plain text and entities contained in it.\n */\nfunction unparse(input: InputText): string {\n if (typeof input === 'string') return escape(input)\n\n let text = input.text\n const entities = input.entities ?? []\n\n // keep track of positions of inserted escape symbols\n const escaped: number[] = []\n text = text.replace(TO_BE_ESCAPED, (s, pos: number) => {\n escaped.push(pos)\n\n return '\\\\' + s\n })\n const hasEscaped = escaped.length > 0\n\n type InsertLater = [number, string]\n const insert: InsertLater[] = []\n\n for (const entity of entities) {\n const type = entity._\n\n let start = entity.offset\n let end = start + entity.length\n\n if (start > text.length) continue\n if (start < 0) start = 0\n if (end > text.length) end = text.length\n\n if (hasEscaped) {\n // determine number of escape chars since the beginning of the string\n let escapedPos = 0\n\n while (escapedPos < escaped.length && escaped[escapedPos] < start) {\n escapedPos += 1\n }\n start += escapedPos\n\n while (escapedPos < escaped.length && escaped[escapedPos] <= end) {\n escapedPos += 1\n }\n end += escapedPos\n }\n\n let startTag\n let endTag: string\n\n switch (type) {\n case 'messageEntityBold':\n startTag = endTag = TAG_BOLD\n break\n case 'messageEntityItalic':\n startTag = endTag = TAG_ITALIC\n break\n case 'messageEntityUnderline':\n startTag = endTag = TAG_UNDERLINE\n break\n case 'messageEntityStrike':\n startTag = endTag = TAG_STRIKE\n break\n case 'messageEntitySpoiler':\n startTag = endTag = TAG_SPOILER\n break\n case 'messageEntityCode':\n startTag = endTag = TAG_CODE\n break\n case 'messageEntityPre':\n startTag = TAG_PRE\n\n if (entity.language) {\n startTag += entity.language\n }\n\n startTag += '\\n'\n endTag = '\\n' + TAG_PRE\n break\n case 'messageEntityTextUrl':\n startTag = '['\n endTag = `](${entity.url})`\n break\n case 'messageEntityMentionName':\n startTag = '['\n endTag = `](tg://user?id=${entity.userId})`\n break\n case 'messageEntityCustomEmoji':\n startTag = '['\n endTag = `](tg://emoji?id=${entity.documentId.toString()})`\n break\n default:\n continue\n }\n\n insert.push([start, startTag])\n insert.push([end, endTag])\n }\n\n // sort by offset desc\n insert.sort((a, b) => b[0] - a[0])\n\n for (const [offset, tag] of insert) {\n text = text.substr(0, offset) + tag + text.substr(offset)\n }\n\n return text\n}\n\nfunction parse(\n strings: TemplateStringsArray | string,\n ...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]\n): TextWithEntities {\n const entities: tl.TypeMessageEntity[] = []\n let result = ''\n\n const stacks: Record<string, tl.Mutable<tl.TypeMessageEntity>[]> = {}\n\n let insideCode = false\n let insidePre = false\n let insideLink = false\n\n function feed(text: string) {\n const len = text.length\n let pos = 0\n\n while (pos < len) {\n const c = text[pos]\n\n if (c === '\\\\') {\n result += text[pos + 1]\n pos += 2\n continue\n }\n\n if (insideCode) {\n if (c === '`') {\n // we can be certain that we're inside code\n\n const ent = stacks.code.pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n insideCode = false\n pos += 1\n } else {\n pos += 1\n result += c\n }\n continue\n }\n\n if (insidePre) {\n if (c === '`' || (c === '\\n' && text[pos + 1] === '`')) {\n if (c === '\\n') pos += 1\n\n if (text[pos + 1] === '`' && text[pos + 2] === '`') {\n // we can be certain that we're inside pre\n\n const ent = stacks.pre.pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n insidePre = false\n pos += 3\n continue\n\n // closed with single or double backtick\n // i.e. not closed actually! this is totally valid md:\n // ```javascript\n // const a = ``;\n // ```\n // compensate that `pos` change we made earliers\n } else if (c === '\\n') {\n pos -= 1\n }\n }\n\n pos += 1\n result += c\n continue\n }\n\n if (insideLink && c === ']') {\n // we can be certain that we're inside link\n\n const ent = stacks.link.pop()!\n\n if (text[pos + 1] !== '(') {\n // [link text]\n // ignore this, and add opening [\n result = `${result.substr(0, ent.offset)}[${result.substr(ent.offset)}]`\n pos += 1\n insideLink = false\n continue\n }\n\n pos += 2\n let url = ''\n\n while (pos < text.length && text[pos] !== ')') {\n url += text[pos++]\n }\n\n pos += 1 // )\n\n if (pos > text.length) {\n throw new Error('Malformed LINK entity, expected )')\n }\n\n if (url.length) {\n ent.length = result.length - ent.offset\n\n let m = url.match(MENTION_REGEX)\n\n if (m) {\n const userId = parseInt(m[1])\n const accessHash = m[2]\n\n if (accessHash) {\n (ent as tl.Mutable<tl.RawInputMessageEntityMentionName>)._ =\n 'inputMessageEntityMentionName'\n ;(ent as tl.Mutable<tl.RawInputMessageEntityMentionName>).userId = {\n _: 'inputUser',\n userId,\n accessHash: Long.fromString(accessHash, false, 16),\n }\n } else {\n (ent as tl.Mutable<tl.RawMessageEntityMentionName>)._ = 'messageEntityMentionName'\n ;(ent as tl.Mutable<tl.RawMessageEntityMentionName>).userId = userId\n }\n } else if ((m = EMOJI_REGEX.exec(url))) {\n (ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>)._ = 'messageEntityCustomEmoji'\n ;(ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>).documentId = Long.fromString(m[1])\n } else {\n if (url.match(/^\\/\\//)) url = 'http:' + url\n ;(ent as tl.Mutable<tl.RawMessageEntityTextUrl>)._ = 'messageEntityTextUrl'\n ;(ent as tl.Mutable<tl.RawMessageEntityTextUrl>).url = url\n }\n entities.push(ent)\n }\n\n insideLink = false\n continue\n }\n\n if (c === '[' && !insideLink) {\n pos += 1\n insideLink = true\n if (!('link' in stacks)) stacks.link = []\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n stacks.link.push({\n offset: result.length,\n length: 0,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any) // other fields are added after the second part\n continue\n }\n\n if (c === '`') {\n const isPre = text[pos + 1] === '`' && text[pos + 2] === '`'\n\n if (isPre) {\n pos += 3\n let language = ''\n\n while (pos < text.length && text[pos] !== '\\n') {\n language += text[pos++]\n }\n\n // newline\n pos += 1\n\n if (pos > text.length) {\n throw new Error('Malformed PRE entity, expected LF after ```')\n }\n\n if (!('pre' in stacks)) stacks.pre = []\n stacks.pre.push({\n _: 'messageEntityPre',\n offset: result.length,\n length: 0,\n language,\n })\n insidePre = true\n } else {\n pos += 1\n if (!('code' in stacks)) stacks.code = []\n stacks.code.push({\n _: 'messageEntityCode',\n offset: result.length,\n length: 0,\n })\n insideCode = true\n }\n\n continue\n }\n\n if (c === text[pos + 1]) {\n // maybe (?) start or end of an entity\n let type: 'Italic' | 'Bold' | 'Underline' | 'Strike' | 'Spoiler' | null = null\n\n switch (c) {\n case '_':\n type = 'Italic'\n break\n case '*':\n type = 'Bold'\n break\n case '-':\n type = 'Underline'\n break\n case '~':\n type = 'Strike'\n break\n case '|':\n type = 'Spoiler'\n break\n }\n\n if (type) {\n if (!(type in stacks)) stacks[type] = []\n const isBegin = stacks[type].length === 0\n\n if (isBegin) {\n stacks[type].push({\n _: `messageEntity${type}`,\n offset: result.length,\n length: 0,\n })\n } else {\n // valid because isBegin is false\n\n const ent = stacks[type].pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n }\n\n pos += 2\n continue\n }\n }\n\n if (c === '\\n') {\n if (pos !== 0) {\n result += '\\n'\n }\n\n const nonWhitespace = text.slice(pos + 1).search(/\\S/)\n\n if (nonWhitespace !== -1) {\n pos += nonWhitespace + 1\n } else {\n pos = len\n result = result.trimEnd()\n }\n continue\n }\n\n // nothing matched => normal character\n result += c\n pos += 1\n }\n }\n\n if (typeof strings === 'string') strings = [strings] as unknown as TemplateStringsArray\n\n sub.forEach((it, idx) => {\n feed(strings[idx])\n\n if (typeof it === 'boolean' || !it) return\n\n if (typeof it === 'string' || typeof it === 'number') {\n result += it\n } else {\n // TextWithEntities or MessageEntity\n const text = it.text\n const innerEntities = 'raw' in it ? [it.raw] : it.entities\n\n const baseOffset = result.length\n result += text\n\n if (innerEntities) {\n for (const ent of innerEntities) {\n entities.push({ ...ent, offset: ent.offset + baseOffset })\n }\n }\n }\n })\n\n feed(strings[strings.length - 1])\n\n for (const [name, stack] of Object.entries(stacks)) {\n if (stack.length) {\n throw new Error(`Unterminated ${name} entity`)\n }\n }\n\n return {\n text: result,\n entities,\n }\n}\n\n// typedoc doesn't support this yet, so we'll have to do it manually\n// https://github.com/TypeStrong/typedoc/issues/2436\n\nexport const md: {\n /**\n * Tagged template based Markdown-to-entities parser function\n *\n * Additionally, `md` function has two static methods:\n * - `md.escape` - escape a string to be safely used in Markdown\n * (should not be needed in most cases, as `md` function itself handles all `string`s\n * passed to it automatically as plain text)\n * - `md.unparse` - add Markdown formatting to the text given the plain text and entities contained in it\n *\n * @example\n * ```typescript\n * const text = md`**${user.displayName}**`\n * ```\n */\n (\n strings: TemplateStringsArray,\n ...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]\n ): TextWithEntities\n /**\n * A variant taking a plain JS string as input\n * and parsing it.\n *\n * Useful for cases when you already have a string\n * (e.g. from some server) and want to parse it.\n *\n * @example\n * ```typescript\n * const string = '**hello**'\n * const text = md(string)\n * ```\n */\n (string: string): TextWithEntities\n escape: typeof escape\n unparse: typeof unparse\n} = Object.assign(parse, {\n escape,\n unparse,\n})\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAIvB,MAAM,aAAa,GAAG,6DAA6D,CAAA;AACnF,MAAM,WAAW,GAAG,2BAA2B,CAAA;AAE/C,MAAM,QAAQ,GAAG,IAAI,CAAA;AACrB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,aAAa,GAAG,IAAI,CAAA;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,QAAQ,GAAG,GAAG,CAAA;AACpB,MAAM,OAAO,GAAG,KAAK,CAAA;AAErB,MAAM,aAAa,GAAG,iBAAiB,CAAA;AAEvC;;;;;GAKG;AACH,SAAS,MAAM,CAAC,GAAW;IACvB,OAAO,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAA;AACtD,CAAC;AAED;;GAEG;AACH,SAAS,OAAO,CAAC,KAAgB;IAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IAEnD,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAA;IAErC,qDAAqD;IACrD,MAAM,OAAO,GAAa,EAAE,CAAA;IA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,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAChD,IAAI,KAAK,CAAC,MAAM,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,SAAS,CAAC,CAAA;SACjD;KACJ;IAED,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,QAAQ;KACX,CAAA;AACL,CAAC;AAED,oEAAoE;AACpE,oDAAoD;AAEpD,MAAM,CAAC,MAAM,EAAE,GAmCX,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;IACrB,MAAM;IACN,OAAO;CACV,CAAC,CAAA","sourcesContent":["import Long from 'long'\n\nimport type { InputText, MessageEntity, TextWithEntities, tl } from '@mtcute/core'\n\nconst MENTION_REGEX = /^tg:\\/\\/user\\?id=(\\d+)(?:&hash=(-?[0-9a-fA-F]+)(?:&|$)|&|$)/\nconst EMOJI_REGEX = /^tg:\\/\\/emoji\\?id=(-?\\d+)/\n\nconst TAG_BOLD = '**'\nconst TAG_ITALIC = '__'\nconst TAG_UNDERLINE = '--'\nconst TAG_STRIKE = '~~'\nconst TAG_SPOILER = '||'\nconst TAG_CODE = '`'\nconst TAG_PRE = '```'\n\nconst TO_BE_ESCAPED = /[*_\\-~`[\\\\\\]|]/g\n\n/**\n * Escape a string to be safely used in Markdown.\n *\n * > **Note**: this function is in most cases not needed, as `md` function\n * > handles all `string`s passed to it automatically as plain text.\n */\nfunction escape(str: string): string {\n return str.replace(TO_BE_ESCAPED, (s) => '\\\\' + s)\n}\n\n/**\n * Add Markdown formatting to the text given the plain text and entities contained in it.\n */\nfunction unparse(input: InputText): string {\n if (typeof input === 'string') return escape(input)\n\n let text = input.text\n const entities = input.entities ?? []\n\n // keep track of positions of inserted escape symbols\n const escaped: number[] = []\n text = text.replace(TO_BE_ESCAPED, (s, pos: number) => {\n escaped.push(pos)\n\n return '\\\\' + s\n })\n const hasEscaped = escaped.length > 0\n\n type InsertLater = [number, string]\n const insert: InsertLater[] = []\n\n for (const entity of entities) {\n const type = entity._\n\n let start = entity.offset\n let end = start + entity.length\n\n if (start > text.length) continue\n if (start < 0) start = 0\n if (end > text.length) end = text.length\n\n if (hasEscaped) {\n // determine number of escape chars since the beginning of the string\n let escapedPos = 0\n\n while (escapedPos < escaped.length && escaped[escapedPos] < start) {\n escapedPos += 1\n }\n start += escapedPos\n\n while (escapedPos < escaped.length && escaped[escapedPos] <= end) {\n escapedPos += 1\n }\n end += escapedPos\n }\n\n let startTag\n let endTag: string\n\n switch (type) {\n case 'messageEntityBold':\n startTag = endTag = TAG_BOLD\n break\n case 'messageEntityItalic':\n startTag = endTag = TAG_ITALIC\n break\n case 'messageEntityUnderline':\n startTag = endTag = TAG_UNDERLINE\n break\n case 'messageEntityStrike':\n startTag = endTag = TAG_STRIKE\n break\n case 'messageEntitySpoiler':\n startTag = endTag = TAG_SPOILER\n break\n case 'messageEntityCode':\n startTag = endTag = TAG_CODE\n break\n case 'messageEntityPre':\n startTag = TAG_PRE\n\n if (entity.language) {\n startTag += entity.language\n }\n\n startTag += '\\n'\n endTag = '\\n' + TAG_PRE\n break\n case 'messageEntityTextUrl':\n startTag = '['\n endTag = `](${entity.url})`\n break\n case 'messageEntityMentionName':\n startTag = '['\n endTag = `](tg://user?id=${entity.userId})`\n break\n case 'messageEntityCustomEmoji':\n startTag = '['\n endTag = `](tg://emoji?id=${entity.documentId.toString()})`\n break\n default:\n continue\n }\n\n insert.push([start, startTag])\n insert.push([end, endTag])\n }\n\n // sort by offset desc\n insert.sort((a, b) => b[0] - a[0])\n\n for (const [offset, tag] of insert) {\n text = text.substr(0, offset) + tag + text.substr(offset)\n }\n\n return text\n}\n\nfunction parse(\n strings: TemplateStringsArray | string,\n ...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]\n): TextWithEntities {\n const entities: tl.TypeMessageEntity[] = []\n let result = ''\n\n const stacks: Record<string, tl.Mutable<tl.TypeMessageEntity>[]> = {}\n\n let insideCode = false\n let insidePre = false\n let insideLink = false\n\n function feed(text: string) {\n const len = text.length\n let pos = 0\n\n while (pos < len) {\n const c = text[pos]\n\n if (c === '\\\\') {\n result += text[pos + 1]\n pos += 2\n continue\n }\n\n if (insideCode) {\n if (c === '`') {\n // we can be certain that we're inside code\n\n const ent = stacks.code.pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n insideCode = false\n pos += 1\n } else {\n pos += 1\n result += c\n }\n continue\n }\n\n if (insidePre) {\n if (c === '`' || (c === '\\n' && text[pos + 1] === '`')) {\n if (c === '\\n') pos += 1\n\n if (text[pos + 1] === '`' && text[pos + 2] === '`') {\n // we can be certain that we're inside pre\n\n const ent = stacks.pre.pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n insidePre = false\n pos += 3\n continue\n\n // closed with single or double backtick\n // i.e. not closed actually! this is totally valid md:\n // ```javascript\n // const a = ``;\n // ```\n // compensate that `pos` change we made earliers\n } else if (c === '\\n') {\n pos -= 1\n }\n }\n\n pos += 1\n result += c\n continue\n }\n\n if (insideLink && c === ']') {\n // we can be certain that we're inside link\n\n const ent = stacks.link.pop()!\n\n if (text[pos + 1] !== '(') {\n // [link text]\n // ignore this, and add opening [\n result = `${result.substr(0, ent.offset)}[${result.substr(ent.offset)}]`\n pos += 1\n insideLink = false\n continue\n }\n\n pos += 2\n let url = ''\n\n while (pos < text.length && text[pos] !== ')') {\n url += text[pos++]\n }\n\n pos += 1 // )\n\n if (pos > text.length) {\n throw new Error('Malformed LINK entity, expected )')\n }\n\n if (url.length) {\n ent.length = result.length - ent.offset\n\n let m = url.match(MENTION_REGEX)\n\n if (m) {\n const userId = parseInt(m[1])\n const accessHash = m[2]\n\n if (accessHash) {\n (ent as tl.Mutable<tl.RawInputMessageEntityMentionName>)._ =\n 'inputMessageEntityMentionName'\n ;(ent as tl.Mutable<tl.RawInputMessageEntityMentionName>).userId = {\n _: 'inputUser',\n userId,\n accessHash: Long.fromString(accessHash, false, 16),\n }\n } else {\n (ent as tl.Mutable<tl.RawMessageEntityMentionName>)._ = 'messageEntityMentionName'\n ;(ent as tl.Mutable<tl.RawMessageEntityMentionName>).userId = userId\n }\n } else if ((m = EMOJI_REGEX.exec(url))) {\n (ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>)._ = 'messageEntityCustomEmoji'\n ;(ent as tl.Mutable<tl.RawMessageEntityCustomEmoji>).documentId = Long.fromString(m[1])\n } else {\n if (url.match(/^\\/\\//)) url = 'http:' + url\n ;(ent as tl.Mutable<tl.RawMessageEntityTextUrl>)._ = 'messageEntityTextUrl'\n ;(ent as tl.Mutable<tl.RawMessageEntityTextUrl>).url = url\n }\n entities.push(ent)\n }\n\n insideLink = false\n continue\n }\n\n if (c === '[' && !insideLink) {\n pos += 1\n insideLink = true\n if (!('link' in stacks)) stacks.link = []\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n stacks.link.push({\n offset: result.length,\n length: 0,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any) // other fields are added after the second part\n continue\n }\n\n if (c === '`') {\n const isPre = text[pos + 1] === '`' && text[pos + 2] === '`'\n\n if (isPre) {\n pos += 3\n let language = ''\n\n while (pos < text.length && text[pos] !== '\\n') {\n language += text[pos++]\n }\n\n // newline\n pos += 1\n\n if (pos > text.length) {\n throw new Error('Malformed PRE entity, expected LF after ```')\n }\n\n if (!('pre' in stacks)) stacks.pre = []\n stacks.pre.push({\n _: 'messageEntityPre',\n offset: result.length,\n length: 0,\n language,\n })\n insidePre = true\n } else {\n pos += 1\n if (!('code' in stacks)) stacks.code = []\n stacks.code.push({\n _: 'messageEntityCode',\n offset: result.length,\n length: 0,\n })\n insideCode = true\n }\n\n continue\n }\n\n if (c === text[pos + 1]) {\n // maybe (?) start or end of an entity\n let type: 'Italic' | 'Bold' | 'Underline' | 'Strike' | 'Spoiler' | null = null\n\n switch (c) {\n case '_':\n type = 'Italic'\n break\n case '*':\n type = 'Bold'\n break\n case '-':\n type = 'Underline'\n break\n case '~':\n type = 'Strike'\n break\n case '|':\n type = 'Spoiler'\n break\n }\n\n if (type) {\n if (!(type in stacks)) stacks[type] = []\n const isBegin = stacks[type].length === 0\n\n if (isBegin) {\n stacks[type].push({\n _: `messageEntity${type}`,\n offset: result.length,\n length: 0,\n })\n } else {\n // valid because isBegin is false\n\n const ent = stacks[type].pop()!\n ent.length = result.length - ent.offset\n entities.push(ent)\n }\n\n pos += 2\n continue\n }\n }\n\n if (c === '\\n') {\n if (pos !== 0) {\n result += '\\n'\n }\n\n const nonWhitespace = text.slice(pos + 1).search(/\\S/)\n\n if (nonWhitespace !== -1) {\n pos += nonWhitespace + 1\n } else {\n pos = len\n result = result.trimEnd()\n }\n continue\n }\n\n // nothing matched => normal character\n result += c\n pos += 1\n }\n }\n\n if (typeof strings === 'string') strings = [strings] as unknown as TemplateStringsArray\n\n sub.forEach((it, idx) => {\n feed(strings[idx])\n\n if (typeof it === 'boolean' || !it) return\n\n if (typeof it === 'string' || typeof it === 'number') {\n result += it\n } else {\n // TextWithEntities or MessageEntity\n const text = it.text\n const innerEntities = 'raw' in it ? [it.raw] : it.entities\n\n const baseOffset = result.length\n result += text\n\n if (innerEntities) {\n for (const ent of innerEntities) {\n entities.push({ ...ent, offset: ent.offset + baseOffset })\n }\n }\n }\n })\n\n feed(strings[strings.length - 1])\n\n for (const [name, stack] of Object.entries(stacks)) {\n if (stack.length) {\n throw new Error(`Unterminated ${name} entity`)\n }\n }\n\n return {\n text: result,\n entities,\n }\n}\n\n// typedoc doesn't support this yet, so we'll have to do it manually\n// https://github.com/TypeStrong/typedoc/issues/2436\n\nexport const md: {\n /**\n * Tagged template based Markdown-to-entities parser function\n *\n * Additionally, `md` function has two static methods:\n * - `md.escape` - escape a string to be safely used in Markdown\n * (should not be needed in most cases, as `md` function itself handles all `string`s\n * passed to it automatically as plain text)\n * - `md.unparse` - add Markdown formatting to the text given the plain text and entities contained in it\n *\n * @example\n * ```typescript\n * const text = md`**${user.displayName}**`\n * ```\n */\n (\n strings: TemplateStringsArray,\n ...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]\n ): TextWithEntities\n /**\n * A variant taking a plain JS string as input\n * and parsing it.\n *\n * Useful for cases when you already have a string\n * (e.g. from some server) and want to parse it.\n *\n * @example\n * ```typescript\n * const string = '**hello**'\n * const text = md(string)\n * ```\n */\n (string: string): TextWithEntities\n escape: typeof escape\n unparse: typeof unparse\n} = Object.assign(parse, {\n escape,\n unparse,\n})\n"]}
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@mtcute/markdown-parser",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Markdown entities parser for mtcute",
5
5
  "author": "Alina Sireneva <alina@tei.su>",
6
6
  "license": "MIT",
7
7
  "main": "cjs/index.js",
8
8
  "type": "module",
9
+ "sideEffects": false,
9
10
  "scripts": {},
10
11
  "dependencies": {
11
12
  "long": "5.2.3"
@@ -1 +0,0 @@
1
- export {};
@@ -1,323 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const long_1 = __importDefault(require("long"));
7
- const vitest_1 = require("vitest");
8
- const client_1 = require("@mtcute/client");
9
- // md is special cased in prettier, we don't want that here
10
- const index_js_1 = require("./index.js");
11
- const createEntity = (type, offset, length, additional) => {
12
- return {
13
- _: type,
14
- offset,
15
- length,
16
- ...(additional ?? {}),
17
- }; // idc really, its not that important
18
- };
19
- (0, vitest_1.describe)('MarkdownMessageEntityParser', () => {
20
- (0, vitest_1.describe)('unparse', () => {
21
- const test = (text, entities, expected) => {
22
- const result = index_js_1.md.unparse({ text, entities });
23
- if (Array.isArray(expected)) {
24
- (0, vitest_1.expect)(expected).to.include(result);
25
- }
26
- else {
27
- (0, vitest_1.expect)(result).eq(expected);
28
- }
29
- };
30
- (0, vitest_1.it)('should return the same text if there are no entities or text', () => {
31
- test('', [], '');
32
- test('some text', [], 'some text');
33
- });
34
- (0, vitest_1.it)('should handle bold, italic, underline, strikethrough and spoiler', () => {
35
- test('plain bold italic underline strikethrough spoiler plain', [
36
- createEntity('messageEntityBold', 6, 4),
37
- createEntity('messageEntityItalic', 11, 6),
38
- createEntity('messageEntityUnderline', 18, 9),
39
- createEntity('messageEntityStrike', 28, 13),
40
- createEntity('messageEntitySpoiler', 42, 7),
41
- ], 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain');
42
- });
43
- (0, vitest_1.it)('should handle code and pre', () => {
44
- test('plain code pre __ignored__ plain', [
45
- createEntity('messageEntityCode', 6, 4),
46
- createEntity('messageEntityPre', 11, 3),
47
- createEntity('messageEntityCode', 15, 11),
48
- ], 'plain `code` ```\npre\n``` `\\_\\_ignored\\_\\_` plain');
49
- });
50
- (0, vitest_1.it)('should handle links and text mentions', () => {
51
- test('plain https://google.com google @durov Pavel Durov mail@mail.ru plain', [
52
- createEntity('messageEntityTextUrl', 25, 6, {
53
- url: 'https://google.com',
54
- }),
55
- createEntity('messageEntityMention', 32, 6),
56
- createEntity('messageEntityMentionName', 39, 11, {
57
- userId: 36265675,
58
- }),
59
- createEntity('messageEntityEmail', 51, 12),
60
- ], 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) mail@mail.ru plain');
61
- });
62
- (0, vitest_1.it)('should handle language in pre', () => {
63
- test('plain console.log("Hello, world!") some code plain', [
64
- createEntity('messageEntityPre', 6, 28, {
65
- language: 'javascript',
66
- }),
67
- createEntity('messageEntityPre', 35, 9, { language: '' }),
68
- ], 'plain ```javascript\nconsole.log("Hello, world!")\n``` ```\nsome code\n``` plain');
69
- });
70
- (0, vitest_1.it)('should support entities on the edges', () => {
71
- test('Hello, world', [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)], '**Hello**, **world**');
72
- });
73
- (0, vitest_1.it)('should clamp out-of-range entities', () => {
74
- test('Hello, world', [createEntity('messageEntityBold', -2, 7), createEntity('messageEntityBold', 7, 10)], '**Hello**, **world**');
75
- });
76
- (0, vitest_1.it)('should ignore entities outside the length', () => {
77
- test('Hello, world', [createEntity('messageEntityBold', 50, 5)], 'Hello, world');
78
- });
79
- (0, vitest_1.it)('should support entities followed by each other', () => {
80
- test('plain Hello, world plain', [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)], [
81
- 'plain **Hello,**__ world__ plain',
82
- // not the most obvious order, but who cares :D
83
- // we support this syntax in parse()
84
- 'plain **Hello,__** world__ plain',
85
- ]);
86
- });
87
- (0, vitest_1.it)('should support nested entities', () => {
88
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 8)], '__Welcome to the **gym zone**!__');
89
- });
90
- (0, vitest_1.it)('should support nested entities with the same edges', () => {
91
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)], ['__Welcome to the **gym zone!**__', '__Welcome to the **gym zone!__**']);
92
- test('Welcome to the gym zone!', [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)], ['**Welcome to the __gym zone!__**', '**Welcome to the __gym zone!**__']);
93
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 7)], ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__']);
94
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)], [
95
- '__**Welcome to the gym zone!**__',
96
- '__**Welcome to the gym zone!__**',
97
- '**__Welcome to the gym zone!**__',
98
- '**__Welcome to the gym zone!__**',
99
- ]);
100
- });
101
- (0, vitest_1.it)('should support overlapping entities', () => {
102
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)], '__Welcome **to the__ gym** zone!');
103
- test('plain bold bold!italic bold!italic!underline underline plain', [
104
- createEntity('messageEntityBold', 6, 38),
105
- createEntity('messageEntityItalic', 11, 33),
106
- createEntity('messageEntityUnderline', 23, 31),
107
- ], [
108
- 'plain **bold __bold!italic --bold!italic!underline**__ underline-- plain',
109
- 'plain **bold __bold!italic --bold!italic!underline__** underline-- plain',
110
- ]);
111
- test('plain bold bold!italic bold!italic!underline italic!underline underline plain', [
112
- createEntity('messageEntityBold', 6, 38),
113
- createEntity('messageEntityItalic', 11, 50),
114
- createEntity('messageEntityUnderline', 23, 48),
115
- ], 'plain **bold __bold!italic --bold!italic!underline** italic!underline__ underline-- plain');
116
- });
117
- (0, vitest_1.it)('should properly handle emojis', () => {
118
- test("best flower: 🌸. don't you even doubt it.", [
119
- createEntity('messageEntityItalic', 0, 11),
120
- createEntity('messageEntityBold', 13, 2),
121
- createEntity('messageEntityItalic', 17, 5),
122
- ], "__best flower__: **🌸**. __don't__ you even doubt it.");
123
- });
124
- (0, vitest_1.it)('should escape reserved symbols', () => {
125
- test('* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\ \\\\', [createEntity('messageEntityItalic', 9, 8)],
126
- // holy shit
127
- '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'
128
- // so we don't have to escape every single backslash lol
129
- .replace(/\//g, '\\'));
130
- test('* ** *** _ __ ___ - -- ---', [
131
- // here we test that the order of the entities does not matter
132
- createEntity('messageEntityItalic', 18, 4),
133
- createEntity('messageEntityItalic', 9, 8),
134
- ], '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\//g, '\\'));
135
- });
136
- });
137
- (0, vitest_1.describe)('parse', () => {
138
- const test = (texts, expectedEntities, expectedText) => {
139
- if (!Array.isArray(texts))
140
- texts = [texts];
141
- for (const text of texts) {
142
- const res = (0, index_js_1.md)(text);
143
- (0, vitest_1.expect)(res.text).eql(expectedText);
144
- (0, vitest_1.expect)(res.entities ?? []).eql(expectedEntities);
145
- }
146
- };
147
- (0, vitest_1.it)('should handle bold, italic, underline, spoiler and strikethrough', () => {
148
- test('plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain', [
149
- createEntity('messageEntityBold', 6, 4),
150
- createEntity('messageEntityItalic', 11, 6),
151
- createEntity('messageEntityUnderline', 18, 9),
152
- createEntity('messageEntityStrike', 28, 13),
153
- createEntity('messageEntitySpoiler', 42, 7),
154
- ], 'plain bold italic underline strikethrough spoiler plain');
155
- });
156
- (0, vitest_1.it)('should handle code and pre', () => {
157
- test([
158
- 'plain `code` ```\npre\n``` `__ignored__` plain',
159
- 'plain `code` ```\npre\n``` `\\_\\_ignored\\_\\_` plain',
160
- 'plain `code` ```\npre``` `\\_\\_ignored\\_\\_` plain',
161
- ], [
162
- createEntity('messageEntityCode', 6, 4),
163
- createEntity('messageEntityPre', 11, 3, { language: '' }),
164
- createEntity('messageEntityCode', 15, 11),
165
- ], 'plain code pre __ignored__ plain');
166
- test('plain ```\npre with ` and ``\n``` plain', [createEntity('messageEntityPre', 6, 17, { language: '' })], 'plain pre with ` and `` plain');
167
- test('plain ```\npre with \n`\n and \n``\nend\n``` plain', [createEntity('messageEntityPre', 6, 24, { language: '' })], 'plain pre with \n`\n and \n``\nend plain');
168
- });
169
- (0, vitest_1.it)('should handle links and text mentions', () => {
170
- test('plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) plain', [
171
- createEntity('messageEntityTextUrl', 25, 6, {
172
- url: 'https://google.com',
173
- }),
174
- createEntity('messageEntityMentionName', 39, 11, {
175
- userId: 36265675,
176
- }),
177
- ], 'plain https://google.com google @durov Pavel Durov plain');
178
- test('[user](tg://user?id=1234567&hash=aabbccddaabbccdd)', [
179
- createEntity('inputMessageEntityMentionName', 0, 4, {
180
- userId: {
181
- _: 'inputUser',
182
- userId: 1234567,
183
- accessHash: long_1.default.fromString('aabbccddaabbccdd', 16),
184
- },
185
- }),
186
- ], 'user');
187
- });
188
- (0, vitest_1.it)('should handle language in pre', () => {
189
- test('plain ```javascript\nconsole.log("Hello, world!")\n``` ```\nsome code\n``` plain', [
190
- createEntity('messageEntityPre', 6, 28, {
191
- language: 'javascript',
192
- }),
193
- createEntity('messageEntityPre', 35, 9, { language: '' }),
194
- ], 'plain console.log("Hello, world!") some code plain');
195
- });
196
- (0, vitest_1.it)('should support entities on the edges', () => {
197
- test('**Hello**, **world**', [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)], 'Hello, world');
198
- });
199
- (0, vitest_1.it)('should return empty array if there are no entities', () => {
200
- test('Hello, world', [], 'Hello, world');
201
- });
202
- (0, vitest_1.it)('should support overlapping entities', () => {
203
- test('__Welcome **to the__ gym** zone!', [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)], 'Welcome to the gym zone!');
204
- // resulting order will depend on the order in which the closing ** or __ are passed,
205
- // thus we use separate tests
206
- test('plain **bold __bold-italic --bold-italic-underline**__ underline-- plain', [
207
- createEntity('messageEntityBold', 6, 38),
208
- createEntity('messageEntityItalic', 11, 33),
209
- createEntity('messageEntityUnderline', 23, 31),
210
- ], 'plain bold bold-italic bold-italic-underline underline plain');
211
- test('plain **bold __bold-italic --bold-italic-underline__** underline-- plain', [
212
- createEntity('messageEntityItalic', 11, 33),
213
- createEntity('messageEntityBold', 6, 38),
214
- createEntity('messageEntityUnderline', 23, 31),
215
- ], 'plain bold bold-italic bold-italic-underline underline plain');
216
- test('plain **bold __bold-italic --bold-italic-underline** italic-underline__ underline-- plain', [
217
- createEntity('messageEntityBold', 6, 38),
218
- createEntity('messageEntityItalic', 11, 50),
219
- createEntity('messageEntityUnderline', 23, 48),
220
- ], 'plain bold bold-italic bold-italic-underline italic-underline underline plain');
221
- });
222
- (0, vitest_1.it)('should support entities followed by each other', () => {
223
- test(['plain **Hello,**__ world__ plain', 'plain **Hello,__** world__ plain'], [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)], 'plain Hello, world plain');
224
- });
225
- (0, vitest_1.it)('should support nested entities', () => {
226
- test('__Welcome to the **gym zone**!__', [createEntity('messageEntityBold', 15, 8), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
227
- test('plain [__google__](https://google.com) plain', [
228
- createEntity('messageEntityItalic', 6, 6),
229
- createEntity('messageEntityTextUrl', 6, 6, {
230
- url: 'https://google.com',
231
- }),
232
- ], 'plain google plain');
233
- test('plain [plain __google__ plain](https://google.com) plain', [
234
- createEntity('messageEntityItalic', 12, 6),
235
- createEntity('messageEntityTextUrl', 6, 18, {
236
- url: 'https://google.com',
237
- }),
238
- ], 'plain plain google plain plain');
239
- });
240
- (0, vitest_1.it)('should support nested entities with the same edges', () => {
241
- // again, order of the entities depends on which closing tag goes first.
242
- test('__Welcome to the **gym zone!**__', [createEntity('messageEntityBold', 15, 9), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
243
- test('__Welcome to the **gym zone!__**', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)], 'Welcome to the gym zone!');
244
- test('**Welcome to the __gym zone!__**', [createEntity('messageEntityItalic', 15, 9), createEntity('messageEntityBold', 0, 24)], 'Welcome to the gym zone!');
245
- test('**Welcome to the __gym zone!**__', [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)], 'Welcome to the gym zone!');
246
- test(['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'], [createEntity('messageEntityBold', 0, 7), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
247
- test(['__**Welcome to the gym zone!**__', '**__Welcome to the gym zone!**__'], [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
248
- test(['__**Welcome to the gym zone!__**', '**__Welcome to the gym zone!__**'], [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)], 'Welcome to the gym zone!');
249
- });
250
- (0, vitest_1.it)('should properly handle emojis', () => {
251
- test("__best flower__: **🌸**. __don't__ you even doubt it.", [
252
- createEntity('messageEntityItalic', 0, 11),
253
- createEntity('messageEntityBold', 13, 2),
254
- createEntity('messageEntityItalic', 17, 5),
255
- ], "best flower: 🌸. don't you even doubt it.");
256
- });
257
- (0, vitest_1.it)('should handle escaped reserved symbols', () => {
258
- test('/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'.replace(/\//g, '\\'), [createEntity('messageEntityItalic', 9, 8)], '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\ \\\\');
259
- test('/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\//g, '\\'), [createEntity('messageEntityItalic', 9, 8), createEntity('messageEntityItalic', 18, 4)], '* ** *** _ __ ___ - -- ---');
260
- });
261
- (0, vitest_1.it)('should ignore empty urls', () => {
262
- test('[link]() [link]', [], 'link [link]');
263
- });
264
- (0, vitest_1.describe)('malformed input', () => {
265
- const testThrows = (input) => (0, vitest_1.expect)(() => (0, index_js_1.md)(input)).throws(Error);
266
- (0, vitest_1.it)('should throw an error on malformed links', () => {
267
- testThrows('plain [link](https://google.com but unclosed');
268
- });
269
- (0, vitest_1.it)('should throw an error on malformed pres', () => {
270
- testThrows('plain ```pre without linebreaks```');
271
- testThrows('plain ``` pre without linebreaks but with spaces instead ```');
272
- });
273
- (0, vitest_1.it)('should throw an error on unterminated entity', () => {
274
- testThrows('plain **bold but unclosed');
275
- testThrows('plain **bold and __also italic but unclosed');
276
- });
277
- });
278
- });
279
- (0, vitest_1.describe)('template', () => {
280
- const test = (text, expectedEntities, expectedText) => {
281
- (0, vitest_1.expect)(text.text).eql(expectedText);
282
- (0, vitest_1.expect)(text.entities ?? []).eql(expectedEntities);
283
- };
284
- (0, vitest_1.it)('should add plain strings as is', () => {
285
- test((0, index_js_1.md) `${'**plain**'}`, [], '**plain**');
286
- });
287
- (0, vitest_1.it)('should skip falsy values', () => {
288
- test((0, index_js_1.md) `some text ${null} more text ${false}`, [], 'some text more text ');
289
- });
290
- (0, vitest_1.it)('should properly dedent', () => {
291
- test((0, index_js_1.md) `
292
- some text
293
- **bold**
294
- more text
295
- `, [createEntity('messageEntityBold', 10, 4)], 'some text\nbold\nmore text');
296
- });
297
- (0, vitest_1.it)('should process entities', () => {
298
- const inner = (0, index_js_1.md) `**bold**`;
299
- test((0, index_js_1.md) `some text ${inner} some more text`, [createEntity('messageEntityBold', 10, 4)], 'some text bold some more text');
300
- test((0, index_js_1.md) `some text ${inner} some more ${inner} text`, [createEntity('messageEntityBold', 10, 4), createEntity('messageEntityBold', 25, 4)], 'some text bold some more bold text');
301
- });
302
- (0, vitest_1.it)('should process entities on edges', () => {
303
- test((0, index_js_1.md) `${(0, index_js_1.md) `**bold**`} and ${(0, index_js_1.md) `__italic__`}`, [createEntity('messageEntityBold', 0, 4), createEntity('messageEntityItalic', 9, 6)], 'bold and italic');
304
- });
305
- (0, vitest_1.it)('should process nested entities', () => {
306
- test((0, index_js_1.md) `**bold ${(0, index_js_1.md) `__bold italic__`} more bold**`, [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)], 'bold bold italic more bold');
307
- test((0, index_js_1.md) `**bold ${(0, index_js_1.md) `__bold italic__ --and some underline--`} more bold**`, [
308
- createEntity('messageEntityItalic', 5, 11),
309
- createEntity('messageEntityUnderline', 17, 18),
310
- createEntity('messageEntityBold', 0, 45),
311
- ], 'bold bold italic and some underline more bold');
312
- test((0, index_js_1.md) `**${(0, index_js_1.md) `__bold italic --underline--__`}**`, [
313
- createEntity('messageEntityUnderline', 12, 9),
314
- createEntity('messageEntityItalic', 0, 21),
315
- createEntity('messageEntityBold', 0, 21),
316
- ], 'bold italic underline');
317
- });
318
- (0, vitest_1.it)('should process MessageEntity', () => {
319
- test((0, index_js_1.md) `**bold ${new client_1.MessageEntity(createEntity('messageEntityItalic', 0, 11), 'bold italic')} more bold**`, [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)], 'bold bold italic more bold');
320
- });
321
- });
322
- });
323
- //# sourceMappingURL=markdown-parser.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown-parser.test.js","sourceRoot":"","sources":["../../src/markdown-parser.test.ts"],"names":[],"mappings":";;;;;AAAA,gDAAuB;AACvB,mCAA6C;AAE7C,2CAAoE;AAEpE,2DAA2D;AAC3D,yCAAsC;AAEtC,MAAM,YAAY,GAAG,CACjB,IAAO,EACP,MAAc,EACd,MAAc,EACd,UAAoF,EAChE,EAAE;IACtB,OAAO;QACH,CAAC,EAAE,IAAI;QACP,MAAM;QACN,MAAM;QACN,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;KACA,CAAA,CAAC,qCAAqC;AACnE,CAAC,CAAA;AAED,IAAA,iBAAQ,EAAC,6BAA6B,EAAE,GAAG,EAAE;IACzC,IAAA,iBAAQ,EAAC,SAAS,EAAE,GAAG,EAAE;QACrB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,QAAgC,EAAE,QAA2B,EAAQ,EAAE;YAC/F,MAAM,MAAM,GAAG,aAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;YAE9C,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBACzB,IAAA,eAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;aACtC;iBAAM;gBACH,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;aAC9B;QACL,CAAC,CAAA;QAED,IAAA,WAAE,EAAC,8DAA8D,EAAE,GAAG,EAAE;YACpE,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;YAChB,IAAI,CAAC,WAAW,EAAE,EAAE,EAAE,WAAW,CAAC,CAAA;QACtC,CA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E,aAAa,CAAC,cAAc,EACvG,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,YAAY,CAAC,mBAAmB,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EACtF,4BAA4B,CAC/B,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA","sourcesContent":["import Long from 'long'\nimport { describe, expect, it } from 'vitest'\n\nimport { MessageEntity, TextWithEntities, tl } from '@mtcute/client'\n\n// md is special cased in prettier, we don't want that here\nimport { md as md_ } from './index.js'\n\nconst createEntity = <T extends tl.TypeMessageEntity['_']>(\n type: T,\n offset: number,\n length: number,\n additional?: Omit<tl.FindByName<tl.TypeMessageEntity, T>, '_' | 'offset' | 'length'>,\n): tl.TypeMessageEntity => {\n return {\n _: type,\n offset,\n length,\n ...(additional ?? {}),\n } as tl.TypeMessageEntity // idc really, its not that important\n}\n\ndescribe('MarkdownMessageEntityParser', () => {\n describe('unparse', () => {\n const test = (text: string, entities: tl.TypeMessageEntity[], expected: string | string[]): void => {\n const result = md_.unparse({ text, entities })\n\n if (Array.isArray(expected)) {\n expect(expected).to.include(result)\n } else {\n expect(result).eq(expected)\n }\n }\n\n it('should return the same text if there are no entities or text', () => {\n test('', [], '')\n test('some text', [], 'some text')\n })\n\n it('should handle bold, italic, underline, strikethrough and spoiler', () => {\n test(\n 'plain bold italic underline strikethrough spoiler plain',\n [\n createEntity('messageEntityBold', 6, 4),\n createEntity('messageEntityItalic', 11, 6),\n createEntity('messageEntityUnderline', 18, 9),\n createEntity('messageEntityStrike', 28, 13),\n createEntity('messageEntitySpoiler', 42, 7),\n ],\n 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain',\n )\n })\n\n it('should handle code and pre', () => {\n test(\n 'plain code pre __ignored__ plain',\n [\n createEntity('messageEntityCode', 6, 4),\n createEntity('messageEntityPre', 11, 3),\n createEntity('messageEntityCode', 15, 11),\n ],\n 'plain `code` ```\\npre\\n``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n )\n })\n\n it('should handle links and text mentions', () => {\n test(\n 'plain https://google.com google @durov Pavel Durov mail@mail.ru plain',\n [\n createEntity('messageEntityTextUrl', 25, 6, {\n url: 'https://google.com',\n }),\n createEntity('messageEntityMention', 32, 6),\n createEntity('messageEntityMentionName', 39, 11, {\n userId: 36265675,\n }),\n createEntity('messageEntityEmail', 51, 12),\n ],\n 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) mail@mail.ru plain',\n )\n })\n\n it('should handle language in pre', () => {\n test(\n 'plain console.log(\"Hello, world!\") some code plain',\n [\n createEntity('messageEntityPre', 6, 28, {\n language: 'javascript',\n }),\n createEntity('messageEntityPre', 35, 9, { language: '' }),\n ],\n 'plain ```javascript\\nconsole.log(\"Hello, world!\")\\n``` ```\\nsome code\\n``` plain',\n )\n })\n\n it('should support entities on the edges', () => {\n test(\n 'Hello, world',\n [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)],\n '**Hello**, **world**',\n )\n })\n\n it('should clamp out-of-range entities', () => {\n test(\n 'Hello, world',\n [createEntity('messageEntityBold', -2, 7), createEntity('messageEntityBold', 7, 10)],\n '**Hello**, **world**',\n )\n })\n\n it('should ignore entities outside the length', () => {\n test('Hello, world', [createEntity('messageEntityBold', 50, 5)], 'Hello, world')\n })\n\n it('should support entities followed by each other', () => {\n test(\n 'plain Hello, world plain',\n [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)],\n [\n 'plain **Hello,**__ world__ plain',\n // not the most obvious order, but who cares :D\n // we support this syntax in parse()\n 'plain **Hello,__** world__ plain',\n ],\n )\n })\n\n it('should support nested entities', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 8)],\n '__Welcome to the **gym zone**!__',\n )\n })\n\n it('should support nested entities with the same edges', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)],\n ['__Welcome to the **gym zone!**__', '__Welcome to the **gym zone!__**'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)],\n ['**Welcome to the __gym zone!__**', '**Welcome to the __gym zone!**__'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 7)],\n ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)],\n [\n '__**Welcome to the gym zone!**__',\n '__**Welcome to the gym zone!__**',\n '**__Welcome to the gym zone!**__',\n '**__Welcome to the gym zone!__**',\n ],\n )\n })\n\n it('should support overlapping entities', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)],\n '__Welcome **to the__ gym** zone!',\n )\n test(\n 'plain bold bold!italic bold!italic!underline underline plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n [\n 'plain **bold __bold!italic --bold!italic!underline**__ underline-- plain',\n 'plain **bold __bold!italic --bold!italic!underline__** underline-- plain',\n ],\n )\n test(\n 'plain bold bold!italic bold!italic!underline italic!underline underline plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 50),\n createEntity('messageEntityUnderline', 23, 48),\n ],\n 'plain **bold __bold!italic --bold!italic!underline** italic!underline__ underline-- plain',\n )\n })\n\n it('should properly handle emojis', () => {\n test(\n \"best flower: 🌸. don't you even doubt it.\",\n [\n createEntity('messageEntityItalic', 0, 11),\n createEntity('messageEntityBold', 13, 2),\n createEntity('messageEntityItalic', 17, 5),\n ],\n \"__best flower__: **🌸**. __don't__ you even doubt it.\",\n )\n })\n\n it('should escape reserved symbols', () => {\n test(\n '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\\\ \\\\\\\\',\n [createEntity('messageEntityItalic', 9, 8)],\n // holy shit\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'\n // so we don't have to escape every single backslash lol\n .replace(/\\//g, '\\\\'),\n )\n test(\n '* ** *** _ __ ___ - -- ---',\n [\n // here we test that the order of the entities does not matter\n createEntity('messageEntityItalic', 18, 4),\n createEntity('messageEntityItalic', 9, 8),\n ],\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\\//g, '\\\\'),\n )\n })\n })\n\n describe('parse', () => {\n const test = (\n texts: string | string[],\n expectedEntities: tl.TypeMessageEntity[],\n expectedText: string,\n ): void => {\n if (!Array.isArray(texts)) texts = [texts]\n\n for (const text of texts) {\n const res = md_(text)\n expect(res.text).eql(expectedText)\n expect(res.entities ?? []).eql(expectedEntities)\n }\n }\n\n it('should handle bold, italic, underline, spoiler and strikethrough', () => {\n test(\n 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain',\n [\n createEntity('messageEntityBold', 6, 4),\n createEntity('messageEntityItalic', 11, 6),\n createEntity('messageEntityUnderline', 18, 9),\n createEntity('messageEntityStrike', 28, 13),\n createEntity('messageEntitySpoiler', 42, 7),\n ],\n 'plain bold italic underline strikethrough spoiler plain',\n )\n })\n\n it('should handle code and pre', () => {\n test(\n [\n 'plain `code` ```\\npre\\n``` `__ignored__` plain',\n 'plain `code` ```\\npre\\n``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n 'plain `code` ```\\npre``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n ],\n [\n createEntity('messageEntityCode', 6, 4),\n createEntity('messageEntityPre', 11, 3, { language: '' }),\n createEntity('messageEntityCode', 15, 11),\n ],\n 'plain code pre __ignored__ plain',\n )\n\n test(\n 'plain ```\\npre with ` and ``\\n``` plain',\n [createEntity('messageEntityPre', 6, 17, { language: '' })],\n 'plain pre with ` and `` plain',\n )\n\n test(\n 'plain ```\\npre with \\n`\\n and \\n``\\nend\\n``` plain',\n [createEntity('messageEntityPre', 6, 24, { language: '' })],\n 'plain pre with \\n`\\n and \\n``\\nend plain',\n )\n })\n\n it('should handle links and text mentions', () => {\n test(\n 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) plain',\n [\n createEntity('messageEntityTextUrl', 25, 6, {\n url: 'https://google.com',\n }),\n createEntity('messageEntityMentionName', 39, 11, {\n userId: 36265675,\n }),\n ],\n 'plain https://google.com google @durov Pavel Durov plain',\n )\n\n test(\n '[user](tg://user?id=1234567&hash=aabbccddaabbccdd)',\n [\n createEntity('inputMessageEntityMentionName', 0, 4, {\n userId: {\n _: 'inputUser',\n userId: 1234567,\n accessHash: Long.fromString('aabbccddaabbccdd', 16),\n },\n }),\n ],\n 'user',\n )\n })\n\n it('should handle language in pre', () => {\n test(\n 'plain ```javascript\\nconsole.log(\"Hello, world!\")\\n``` ```\\nsome code\\n``` plain',\n [\n createEntity('messageEntityPre', 6, 28, {\n language: 'javascript',\n }),\n createEntity('messageEntityPre', 35, 9, { language: '' }),\n ],\n 'plain console.log(\"Hello, world!\") some code plain',\n )\n })\n\n it('should support entities on the edges', () => {\n test(\n '**Hello**, **world**',\n [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)],\n 'Hello, world',\n )\n })\n\n it('should return empty array if there are no entities', () => {\n test('Hello, world', [], 'Hello, world')\n })\n\n it('should support overlapping entities', () => {\n test(\n '__Welcome **to the__ gym** zone!',\n [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)],\n 'Welcome to the gym zone!',\n )\n\n // resulting order will depend on the order in which the closing ** or __ are passed,\n // thus we use separate tests\n test(\n 'plain **bold __bold-italic --bold-italic-underline**__ underline-- plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n 'plain bold bold-italic bold-italic-underline underline plain',\n )\n test(\n 'plain **bold __bold-italic --bold-italic-underline__** underline-- plain',\n [\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n 'plain bold bold-italic bold-italic-underline underline plain',\n )\n\n test(\n 'plain **bold __bold-italic --bold-italic-underline** italic-underline__ underline-- plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 50),\n createEntity('messageEntityUnderline', 23, 48),\n ],\n 'plain bold bold-italic bold-italic-underline italic-underline underline plain',\n )\n })\n\n it('should support entities followed by each other', () => {\n test(\n ['plain **Hello,**__ world__ plain', 'plain **Hello,__** world__ plain'],\n [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)],\n 'plain Hello, world plain',\n )\n })\n\n it('should support nested entities', () => {\n test(\n '__Welcome to the **gym zone**!__',\n [createEntity('messageEntityBold', 15, 8), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n\n test(\n 'plain [__google__](https://google.com) plain',\n [\n createEntity('messageEntityItalic', 6, 6),\n createEntity('messageEntityTextUrl', 6, 6, {\n url: 'https://google.com',\n }),\n ],\n 'plain google plain',\n )\n test(\n 'plain [plain __google__ plain](https://google.com) plain',\n [\n createEntity('messageEntityItalic', 12, 6),\n createEntity('messageEntityTextUrl', 6, 18, {\n url: 'https://google.com',\n }),\n ],\n 'plain plain google plain plain',\n )\n })\n\n it('should support nested entities with the same edges', () => {\n // again, order of the entities depends on which closing tag goes first.\n test(\n '__Welcome to the **gym zone!**__',\n [createEntity('messageEntityBold', 15, 9), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n '__Welcome to the **gym zone!__**',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)],\n 'Welcome to the gym zone!',\n )\n\n test(\n '**Welcome to the __gym zone!__**',\n [createEntity('messageEntityItalic', 15, 9), createEntity('messageEntityBold', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n '**Welcome to the __gym zone!**__',\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)],\n 'Welcome to the gym zone!',\n )\n\n test(\n ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'],\n [createEntity('messageEntityBold', 0, 7), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n\n test(\n ['__**Welcome to the gym zone!**__', '**__Welcome to the gym zone!**__'],\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n ['__**Welcome to the gym zone!__**', '**__Welcome to the gym zone!__**'],\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)],\n 'Welcome to the gym zone!',\n )\n })\n\n it('should properly handle emojis', () => {\n test(\n \"__best flower__: **🌸**. __don't__ you even doubt it.\",\n [\n createEntity('messageEntityItalic', 0, 11),\n createEntity('messageEntityBold', 13, 2),\n createEntity('messageEntityItalic', 17, 5),\n ],\n \"best flower: 🌸. don't you even doubt it.\",\n )\n })\n\n it('should handle escaped reserved symbols', () => {\n test(\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'.replace(\n /\\//g,\n '\\\\',\n ),\n [createEntity('messageEntityItalic', 9, 8)],\n '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\\\ \\\\\\\\',\n )\n test(\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\\//g, '\\\\'),\n [createEntity('messageEntityItalic', 9, 8), createEntity('messageEntityItalic', 18, 4)],\n '* ** *** _ __ ___ - -- ---',\n )\n })\n\n it('should ignore empty urls', () => {\n test('[link]() [link]', [], 'link [link]')\n })\n\n describe('malformed input', () => {\n const testThrows = (input: string) => expect(() => md_(input)).throws(Error)\n\n it('should throw an error on malformed links', () => {\n testThrows('plain [link](https://google.com but unclosed')\n })\n\n it('should throw an error on malformed pres', () => {\n testThrows('plain ```pre without linebreaks```')\n testThrows('plain ``` pre without linebreaks but with spaces instead ```')\n })\n\n it('should throw an error on unterminated entity', () => {\n testThrows('plain **bold but unclosed')\n testThrows('plain **bold and __also italic but unclosed')\n })\n })\n })\n\n describe('template', () => {\n const test = (text: TextWithEntities, expectedEntities: tl.TypeMessageEntity[], expectedText: string): void => {\n expect(text.text).eql(expectedText)\n expect(text.entities ?? []).eql(expectedEntities)\n }\n\n it('should add plain strings as is', () => {\n test(md_`${'**plain**'}`, [], '**plain**')\n })\n\n it('should skip falsy values', () => {\n test(md_`some text ${null} more text ${false}`, [], 'some text more text ')\n })\n\n it('should properly dedent', () => {\n test(\n md_`\n some text\n **bold**\n more text\n `,\n [createEntity('messageEntityBold', 10, 4)],\n 'some text\\nbold\\nmore text',\n )\n })\n\n it('should process entities', () => {\n const inner = md_`**bold**`\n\n test(\n md_`some text ${inner} some more text`,\n [createEntity('messageEntityBold', 10, 4)],\n 'some text bold some more text',\n )\n test(\n md_`some text ${inner} some more ${inner} text`,\n [createEntity('messageEntityBold', 10, 4), createEntity('messageEntityBold', 25, 4)],\n 'some text bold some more bold text',\n )\n })\n\n it('should process entities on edges', () => {\n test(\n md_`${md_`**bold**`} and ${md_`__italic__`}`,\n [createEntity('messageEntityBold', 0, 4), createEntity('messageEntityItalic', 9, 6)],\n 'bold and italic',\n )\n })\n\n it('should process nested entities', () => {\n test(\n md_`**bold ${md_`__bold italic__`} more bold**`,\n [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)],\n 'bold bold italic more bold',\n )\n test(\n md_`**bold ${md_`__bold italic__ --and some underline--`} more bold**`,\n [\n createEntity('messageEntityItalic', 5, 11),\n createEntity('messageEntityUnderline', 17, 18),\n createEntity('messageEntityBold', 0, 45),\n ],\n 'bold bold italic and some underline more bold',\n )\n test(\n md_`**${md_`__bold italic --underline--__`}**`,\n [\n createEntity('messageEntityUnderline', 12, 9),\n createEntity('messageEntityItalic', 0, 21),\n createEntity('messageEntityBold', 0, 21),\n ],\n 'bold italic underline',\n )\n })\n\n it('should process MessageEntity', () => {\n test(\n md_`**bold ${new MessageEntity(createEntity('messageEntityItalic', 0, 11), 'bold italic')} more bold**`,\n [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)],\n 'bold bold italic more bold',\n )\n })\n })\n})\n"]}
@@ -1 +0,0 @@
1
- export {};
@@ -1,318 +0,0 @@
1
- import Long from 'long';
2
- import { describe, expect, it } from 'vitest';
3
- import { MessageEntity } from '@mtcute/client';
4
- // md is special cased in prettier, we don't want that here
5
- import { md as md_ } from './index.js';
6
- const createEntity = (type, offset, length, additional) => {
7
- return {
8
- _: type,
9
- offset,
10
- length,
11
- ...(additional ?? {}),
12
- }; // idc really, its not that important
13
- };
14
- describe('MarkdownMessageEntityParser', () => {
15
- describe('unparse', () => {
16
- const test = (text, entities, expected) => {
17
- const result = md_.unparse({ text, entities });
18
- if (Array.isArray(expected)) {
19
- expect(expected).to.include(result);
20
- }
21
- else {
22
- expect(result).eq(expected);
23
- }
24
- };
25
- it('should return the same text if there are no entities or text', () => {
26
- test('', [], '');
27
- test('some text', [], 'some text');
28
- });
29
- it('should handle bold, italic, underline, strikethrough and spoiler', () => {
30
- test('plain bold italic underline strikethrough spoiler plain', [
31
- createEntity('messageEntityBold', 6, 4),
32
- createEntity('messageEntityItalic', 11, 6),
33
- createEntity('messageEntityUnderline', 18, 9),
34
- createEntity('messageEntityStrike', 28, 13),
35
- createEntity('messageEntitySpoiler', 42, 7),
36
- ], 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain');
37
- });
38
- it('should handle code and pre', () => {
39
- test('plain code pre __ignored__ plain', [
40
- createEntity('messageEntityCode', 6, 4),
41
- createEntity('messageEntityPre', 11, 3),
42
- createEntity('messageEntityCode', 15, 11),
43
- ], 'plain `code` ```\npre\n``` `\\_\\_ignored\\_\\_` plain');
44
- });
45
- it('should handle links and text mentions', () => {
46
- test('plain https://google.com google @durov Pavel Durov mail@mail.ru plain', [
47
- createEntity('messageEntityTextUrl', 25, 6, {
48
- url: 'https://google.com',
49
- }),
50
- createEntity('messageEntityMention', 32, 6),
51
- createEntity('messageEntityMentionName', 39, 11, {
52
- userId: 36265675,
53
- }),
54
- createEntity('messageEntityEmail', 51, 12),
55
- ], 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) mail@mail.ru plain');
56
- });
57
- it('should handle language in pre', () => {
58
- test('plain console.log("Hello, world!") some code plain', [
59
- createEntity('messageEntityPre', 6, 28, {
60
- language: 'javascript',
61
- }),
62
- createEntity('messageEntityPre', 35, 9, { language: '' }),
63
- ], 'plain ```javascript\nconsole.log("Hello, world!")\n``` ```\nsome code\n``` plain');
64
- });
65
- it('should support entities on the edges', () => {
66
- test('Hello, world', [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)], '**Hello**, **world**');
67
- });
68
- it('should clamp out-of-range entities', () => {
69
- test('Hello, world', [createEntity('messageEntityBold', -2, 7), createEntity('messageEntityBold', 7, 10)], '**Hello**, **world**');
70
- });
71
- it('should ignore entities outside the length', () => {
72
- test('Hello, world', [createEntity('messageEntityBold', 50, 5)], 'Hello, world');
73
- });
74
- it('should support entities followed by each other', () => {
75
- test('plain Hello, world plain', [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)], [
76
- 'plain **Hello,**__ world__ plain',
77
- // not the most obvious order, but who cares :D
78
- // we support this syntax in parse()
79
- 'plain **Hello,__** world__ plain',
80
- ]);
81
- });
82
- it('should support nested entities', () => {
83
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 8)], '__Welcome to the **gym zone**!__');
84
- });
85
- it('should support nested entities with the same edges', () => {
86
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)], ['__Welcome to the **gym zone!**__', '__Welcome to the **gym zone!__**']);
87
- test('Welcome to the gym zone!', [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)], ['**Welcome to the __gym zone!__**', '**Welcome to the __gym zone!**__']);
88
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 7)], ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__']);
89
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)], [
90
- '__**Welcome to the gym zone!**__',
91
- '__**Welcome to the gym zone!__**',
92
- '**__Welcome to the gym zone!**__',
93
- '**__Welcome to the gym zone!__**',
94
- ]);
95
- });
96
- it('should support overlapping entities', () => {
97
- test('Welcome to the gym zone!', [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)], '__Welcome **to the__ gym** zone!');
98
- test('plain bold bold!italic bold!italic!underline underline plain', [
99
- createEntity('messageEntityBold', 6, 38),
100
- createEntity('messageEntityItalic', 11, 33),
101
- createEntity('messageEntityUnderline', 23, 31),
102
- ], [
103
- 'plain **bold __bold!italic --bold!italic!underline**__ underline-- plain',
104
- 'plain **bold __bold!italic --bold!italic!underline__** underline-- plain',
105
- ]);
106
- test('plain bold bold!italic bold!italic!underline italic!underline underline plain', [
107
- createEntity('messageEntityBold', 6, 38),
108
- createEntity('messageEntityItalic', 11, 50),
109
- createEntity('messageEntityUnderline', 23, 48),
110
- ], 'plain **bold __bold!italic --bold!italic!underline** italic!underline__ underline-- plain');
111
- });
112
- it('should properly handle emojis', () => {
113
- test("best flower: 🌸. don't you even doubt it.", [
114
- createEntity('messageEntityItalic', 0, 11),
115
- createEntity('messageEntityBold', 13, 2),
116
- createEntity('messageEntityItalic', 17, 5),
117
- ], "__best flower__: **🌸**. __don't__ you even doubt it.");
118
- });
119
- it('should escape reserved symbols', () => {
120
- test('* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\ \\\\', [createEntity('messageEntityItalic', 9, 8)],
121
- // holy shit
122
- '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'
123
- // so we don't have to escape every single backslash lol
124
- .replace(/\//g, '\\'));
125
- test('* ** *** _ __ ___ - -- ---', [
126
- // here we test that the order of the entities does not matter
127
- createEntity('messageEntityItalic', 18, 4),
128
- createEntity('messageEntityItalic', 9, 8),
129
- ], '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\//g, '\\'));
130
- });
131
- });
132
- describe('parse', () => {
133
- const test = (texts, expectedEntities, expectedText) => {
134
- if (!Array.isArray(texts))
135
- texts = [texts];
136
- for (const text of texts) {
137
- const res = md_(text);
138
- expect(res.text).eql(expectedText);
139
- expect(res.entities ?? []).eql(expectedEntities);
140
- }
141
- };
142
- it('should handle bold, italic, underline, spoiler and strikethrough', () => {
143
- test('plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain', [
144
- createEntity('messageEntityBold', 6, 4),
145
- createEntity('messageEntityItalic', 11, 6),
146
- createEntity('messageEntityUnderline', 18, 9),
147
- createEntity('messageEntityStrike', 28, 13),
148
- createEntity('messageEntitySpoiler', 42, 7),
149
- ], 'plain bold italic underline strikethrough spoiler plain');
150
- });
151
- it('should handle code and pre', () => {
152
- test([
153
- 'plain `code` ```\npre\n``` `__ignored__` plain',
154
- 'plain `code` ```\npre\n``` `\\_\\_ignored\\_\\_` plain',
155
- 'plain `code` ```\npre``` `\\_\\_ignored\\_\\_` plain',
156
- ], [
157
- createEntity('messageEntityCode', 6, 4),
158
- createEntity('messageEntityPre', 11, 3, { language: '' }),
159
- createEntity('messageEntityCode', 15, 11),
160
- ], 'plain code pre __ignored__ plain');
161
- test('plain ```\npre with ` and ``\n``` plain', [createEntity('messageEntityPre', 6, 17, { language: '' })], 'plain pre with ` and `` plain');
162
- test('plain ```\npre with \n`\n and \n``\nend\n``` plain', [createEntity('messageEntityPre', 6, 24, { language: '' })], 'plain pre with \n`\n and \n``\nend plain');
163
- });
164
- it('should handle links and text mentions', () => {
165
- test('plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) plain', [
166
- createEntity('messageEntityTextUrl', 25, 6, {
167
- url: 'https://google.com',
168
- }),
169
- createEntity('messageEntityMentionName', 39, 11, {
170
- userId: 36265675,
171
- }),
172
- ], 'plain https://google.com google @durov Pavel Durov plain');
173
- test('[user](tg://user?id=1234567&hash=aabbccddaabbccdd)', [
174
- createEntity('inputMessageEntityMentionName', 0, 4, {
175
- userId: {
176
- _: 'inputUser',
177
- userId: 1234567,
178
- accessHash: Long.fromString('aabbccddaabbccdd', 16),
179
- },
180
- }),
181
- ], 'user');
182
- });
183
- it('should handle language in pre', () => {
184
- test('plain ```javascript\nconsole.log("Hello, world!")\n``` ```\nsome code\n``` plain', [
185
- createEntity('messageEntityPre', 6, 28, {
186
- language: 'javascript',
187
- }),
188
- createEntity('messageEntityPre', 35, 9, { language: '' }),
189
- ], 'plain console.log("Hello, world!") some code plain');
190
- });
191
- it('should support entities on the edges', () => {
192
- test('**Hello**, **world**', [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)], 'Hello, world');
193
- });
194
- it('should return empty array if there are no entities', () => {
195
- test('Hello, world', [], 'Hello, world');
196
- });
197
- it('should support overlapping entities', () => {
198
- test('__Welcome **to the__ gym** zone!', [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)], 'Welcome to the gym zone!');
199
- // resulting order will depend on the order in which the closing ** or __ are passed,
200
- // thus we use separate tests
201
- test('plain **bold __bold-italic --bold-italic-underline**__ underline-- plain', [
202
- createEntity('messageEntityBold', 6, 38),
203
- createEntity('messageEntityItalic', 11, 33),
204
- createEntity('messageEntityUnderline', 23, 31),
205
- ], 'plain bold bold-italic bold-italic-underline underline plain');
206
- test('plain **bold __bold-italic --bold-italic-underline__** underline-- plain', [
207
- createEntity('messageEntityItalic', 11, 33),
208
- createEntity('messageEntityBold', 6, 38),
209
- createEntity('messageEntityUnderline', 23, 31),
210
- ], 'plain bold bold-italic bold-italic-underline underline plain');
211
- test('plain **bold __bold-italic --bold-italic-underline** italic-underline__ underline-- plain', [
212
- createEntity('messageEntityBold', 6, 38),
213
- createEntity('messageEntityItalic', 11, 50),
214
- createEntity('messageEntityUnderline', 23, 48),
215
- ], 'plain bold bold-italic bold-italic-underline italic-underline underline plain');
216
- });
217
- it('should support entities followed by each other', () => {
218
- test(['plain **Hello,**__ world__ plain', 'plain **Hello,__** world__ plain'], [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)], 'plain Hello, world plain');
219
- });
220
- it('should support nested entities', () => {
221
- test('__Welcome to the **gym zone**!__', [createEntity('messageEntityBold', 15, 8), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
222
- test('plain [__google__](https://google.com) plain', [
223
- createEntity('messageEntityItalic', 6, 6),
224
- createEntity('messageEntityTextUrl', 6, 6, {
225
- url: 'https://google.com',
226
- }),
227
- ], 'plain google plain');
228
- test('plain [plain __google__ plain](https://google.com) plain', [
229
- createEntity('messageEntityItalic', 12, 6),
230
- createEntity('messageEntityTextUrl', 6, 18, {
231
- url: 'https://google.com',
232
- }),
233
- ], 'plain plain google plain plain');
234
- });
235
- it('should support nested entities with the same edges', () => {
236
- // again, order of the entities depends on which closing tag goes first.
237
- test('__Welcome to the **gym zone!**__', [createEntity('messageEntityBold', 15, 9), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
238
- test('__Welcome to the **gym zone!__**', [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)], 'Welcome to the gym zone!');
239
- test('**Welcome to the __gym zone!__**', [createEntity('messageEntityItalic', 15, 9), createEntity('messageEntityBold', 0, 24)], 'Welcome to the gym zone!');
240
- test('**Welcome to the __gym zone!**__', [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)], 'Welcome to the gym zone!');
241
- test(['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'], [createEntity('messageEntityBold', 0, 7), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
242
- test(['__**Welcome to the gym zone!**__', '**__Welcome to the gym zone!**__'], [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 0, 24)], 'Welcome to the gym zone!');
243
- test(['__**Welcome to the gym zone!__**', '**__Welcome to the gym zone!__**'], [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)], 'Welcome to the gym zone!');
244
- });
245
- it('should properly handle emojis', () => {
246
- test("__best flower__: **🌸**. __don't__ you even doubt it.", [
247
- createEntity('messageEntityItalic', 0, 11),
248
- createEntity('messageEntityBold', 13, 2),
249
- createEntity('messageEntityItalic', 17, 5),
250
- ], "best flower: 🌸. don't you even doubt it.");
251
- });
252
- it('should handle escaped reserved symbols', () => {
253
- test('/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'.replace(/\//g, '\\'), [createEntity('messageEntityItalic', 9, 8)], '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\ \\\\');
254
- test('/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\//g, '\\'), [createEntity('messageEntityItalic', 9, 8), createEntity('messageEntityItalic', 18, 4)], '* ** *** _ __ ___ - -- ---');
255
- });
256
- it('should ignore empty urls', () => {
257
- test('[link]() [link]', [], 'link [link]');
258
- });
259
- describe('malformed input', () => {
260
- const testThrows = (input) => expect(() => md_(input)).throws(Error);
261
- it('should throw an error on malformed links', () => {
262
- testThrows('plain [link](https://google.com but unclosed');
263
- });
264
- it('should throw an error on malformed pres', () => {
265
- testThrows('plain ```pre without linebreaks```');
266
- testThrows('plain ``` pre without linebreaks but with spaces instead ```');
267
- });
268
- it('should throw an error on unterminated entity', () => {
269
- testThrows('plain **bold but unclosed');
270
- testThrows('plain **bold and __also italic but unclosed');
271
- });
272
- });
273
- });
274
- describe('template', () => {
275
- const test = (text, expectedEntities, expectedText) => {
276
- expect(text.text).eql(expectedText);
277
- expect(text.entities ?? []).eql(expectedEntities);
278
- };
279
- it('should add plain strings as is', () => {
280
- test(md_ `${'**plain**'}`, [], '**plain**');
281
- });
282
- it('should skip falsy values', () => {
283
- test(md_ `some text ${null} more text ${false}`, [], 'some text more text ');
284
- });
285
- it('should properly dedent', () => {
286
- test(md_ `
287
- some text
288
- **bold**
289
- more text
290
- `, [createEntity('messageEntityBold', 10, 4)], 'some text\nbold\nmore text');
291
- });
292
- it('should process entities', () => {
293
- const inner = md_ `**bold**`;
294
- test(md_ `some text ${inner} some more text`, [createEntity('messageEntityBold', 10, 4)], 'some text bold some more text');
295
- test(md_ `some text ${inner} some more ${inner} text`, [createEntity('messageEntityBold', 10, 4), createEntity('messageEntityBold', 25, 4)], 'some text bold some more bold text');
296
- });
297
- it('should process entities on edges', () => {
298
- test(md_ `${md_ `**bold**`} and ${md_ `__italic__`}`, [createEntity('messageEntityBold', 0, 4), createEntity('messageEntityItalic', 9, 6)], 'bold and italic');
299
- });
300
- it('should process nested entities', () => {
301
- test(md_ `**bold ${md_ `__bold italic__`} more bold**`, [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)], 'bold bold italic more bold');
302
- test(md_ `**bold ${md_ `__bold italic__ --and some underline--`} more bold**`, [
303
- createEntity('messageEntityItalic', 5, 11),
304
- createEntity('messageEntityUnderline', 17, 18),
305
- createEntity('messageEntityBold', 0, 45),
306
- ], 'bold bold italic and some underline more bold');
307
- test(md_ `**${md_ `__bold italic --underline--__`}**`, [
308
- createEntity('messageEntityUnderline', 12, 9),
309
- createEntity('messageEntityItalic', 0, 21),
310
- createEntity('messageEntityBold', 0, 21),
311
- ], 'bold italic underline');
312
- });
313
- it('should process MessageEntity', () => {
314
- test(md_ `**bold ${new MessageEntity(createEntity('messageEntityItalic', 0, 11), 'bold italic')} more bold**`, [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)], 'bold bold italic more bold');
315
- });
316
- });
317
- });
318
- //# sourceMappingURL=markdown-parser.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown-parser.test.js","sourceRoot":"","sources":["../../src/markdown-parser.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAwB,MAAM,gBAAgB,CAAA;AAEpE,2DAA2D;AAC3D,OAAO,EAAE,EAAE,IAAI,GAAG,EAAE,MAAM,YAAY,CAAA;AAEtC,MAAM,YAAY,GAAG,CACjB,IAAO,EACP,MAAc,EACd,MAAc,EACd,UAAoF,EAChE,EAAE;IACtB,OAAO;QACH,CAAC,EAAE,IAAI;QACP,MAAM;QACN,MAAM;QACN,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;KACA,CAAA,CAAC,qCAAqC;AACnE,CAAC,CAAA;AAED,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IACzC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACrB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,QAAgC,EAAE,QAA2B,EAAQ,EAAE;YAC/F,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;YAE9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AE,CAAC,EAAE,EAAE,CAAC,EAAE,aAAa,CAAC,cAAc,EACvG,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,YAAY,CAAC,mBAAmB,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EACtF,4BAA4B,CAC/B,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA","sourcesContent":["import Long from 'long'\nimport { describe, expect, it } from 'vitest'\n\nimport { MessageEntity, TextWithEntities, tl } from '@mtcute/client'\n\n// md is special cased in prettier, we don't want that here\nimport { md as md_ } from './index.js'\n\nconst createEntity = <T extends tl.TypeMessageEntity['_']>(\n type: T,\n offset: number,\n length: number,\n additional?: Omit<tl.FindByName<tl.TypeMessageEntity, T>, '_' | 'offset' | 'length'>,\n): tl.TypeMessageEntity => {\n return {\n _: type,\n offset,\n length,\n ...(additional ?? {}),\n } as tl.TypeMessageEntity // idc really, its not that important\n}\n\ndescribe('MarkdownMessageEntityParser', () => {\n describe('unparse', () => {\n const test = (text: string, entities: tl.TypeMessageEntity[], expected: string | string[]): void => {\n const result = md_.unparse({ text, entities })\n\n if (Array.isArray(expected)) {\n expect(expected).to.include(result)\n } else {\n expect(result).eq(expected)\n }\n }\n\n it('should return the same text if there are no entities or text', () => {\n test('', [], '')\n test('some text', [], 'some text')\n })\n\n it('should handle bold, italic, underline, strikethrough and spoiler', () => {\n test(\n 'plain bold italic underline strikethrough spoiler plain',\n [\n createEntity('messageEntityBold', 6, 4),\n createEntity('messageEntityItalic', 11, 6),\n createEntity('messageEntityUnderline', 18, 9),\n createEntity('messageEntityStrike', 28, 13),\n createEntity('messageEntitySpoiler', 42, 7),\n ],\n 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain',\n )\n })\n\n it('should handle code and pre', () => {\n test(\n 'plain code pre __ignored__ plain',\n [\n createEntity('messageEntityCode', 6, 4),\n createEntity('messageEntityPre', 11, 3),\n createEntity('messageEntityCode', 15, 11),\n ],\n 'plain `code` ```\\npre\\n``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n )\n })\n\n it('should handle links and text mentions', () => {\n test(\n 'plain https://google.com google @durov Pavel Durov mail@mail.ru plain',\n [\n createEntity('messageEntityTextUrl', 25, 6, {\n url: 'https://google.com',\n }),\n createEntity('messageEntityMention', 32, 6),\n createEntity('messageEntityMentionName', 39, 11, {\n userId: 36265675,\n }),\n createEntity('messageEntityEmail', 51, 12),\n ],\n 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) mail@mail.ru plain',\n )\n })\n\n it('should handle language in pre', () => {\n test(\n 'plain console.log(\"Hello, world!\") some code plain',\n [\n createEntity('messageEntityPre', 6, 28, {\n language: 'javascript',\n }),\n createEntity('messageEntityPre', 35, 9, { language: '' }),\n ],\n 'plain ```javascript\\nconsole.log(\"Hello, world!\")\\n``` ```\\nsome code\\n``` plain',\n )\n })\n\n it('should support entities on the edges', () => {\n test(\n 'Hello, world',\n [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)],\n '**Hello**, **world**',\n )\n })\n\n it('should clamp out-of-range entities', () => {\n test(\n 'Hello, world',\n [createEntity('messageEntityBold', -2, 7), createEntity('messageEntityBold', 7, 10)],\n '**Hello**, **world**',\n )\n })\n\n it('should ignore entities outside the length', () => {\n test('Hello, world', [createEntity('messageEntityBold', 50, 5)], 'Hello, world')\n })\n\n it('should support entities followed by each other', () => {\n test(\n 'plain Hello, world plain',\n [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)],\n [\n 'plain **Hello,**__ world__ plain',\n // not the most obvious order, but who cares :D\n // we support this syntax in parse()\n 'plain **Hello,__** world__ plain',\n ],\n )\n })\n\n it('should support nested entities', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 8)],\n '__Welcome to the **gym zone**!__',\n )\n })\n\n it('should support nested entities with the same edges', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)],\n ['__Welcome to the **gym zone!**__', '__Welcome to the **gym zone!__**'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)],\n ['**Welcome to the __gym zone!__**', '**Welcome to the __gym zone!**__'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 7)],\n ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'],\n )\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)],\n [\n '__**Welcome to the gym zone!**__',\n '__**Welcome to the gym zone!__**',\n '**__Welcome to the gym zone!**__',\n '**__Welcome to the gym zone!__**',\n ],\n )\n })\n\n it('should support overlapping entities', () => {\n test(\n 'Welcome to the gym zone!',\n [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)],\n '__Welcome **to the__ gym** zone!',\n )\n test(\n 'plain bold bold!italic bold!italic!underline underline plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n [\n 'plain **bold __bold!italic --bold!italic!underline**__ underline-- plain',\n 'plain **bold __bold!italic --bold!italic!underline__** underline-- plain',\n ],\n )\n test(\n 'plain bold bold!italic bold!italic!underline italic!underline underline plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 50),\n createEntity('messageEntityUnderline', 23, 48),\n ],\n 'plain **bold __bold!italic --bold!italic!underline** italic!underline__ underline-- plain',\n )\n })\n\n it('should properly handle emojis', () => {\n test(\n \"best flower: 🌸. don't you even doubt it.\",\n [\n createEntity('messageEntityItalic', 0, 11),\n createEntity('messageEntityBold', 13, 2),\n createEntity('messageEntityItalic', 17, 5),\n ],\n \"__best flower__: **🌸**. __don't__ you even doubt it.\",\n )\n })\n\n it('should escape reserved symbols', () => {\n test(\n '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\\\ \\\\\\\\',\n [createEntity('messageEntityItalic', 9, 8)],\n // holy shit\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'\n // so we don't have to escape every single backslash lol\n .replace(/\\//g, '\\\\'),\n )\n test(\n '* ** *** _ __ ___ - -- ---',\n [\n // here we test that the order of the entities does not matter\n createEntity('messageEntityItalic', 18, 4),\n createEntity('messageEntityItalic', 9, 8),\n ],\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\\//g, '\\\\'),\n )\n })\n })\n\n describe('parse', () => {\n const test = (\n texts: string | string[],\n expectedEntities: tl.TypeMessageEntity[],\n expectedText: string,\n ): void => {\n if (!Array.isArray(texts)) texts = [texts]\n\n for (const text of texts) {\n const res = md_(text)\n expect(res.text).eql(expectedText)\n expect(res.entities ?? []).eql(expectedEntities)\n }\n }\n\n it('should handle bold, italic, underline, spoiler and strikethrough', () => {\n test(\n 'plain **bold** __italic__ --underline-- ~~strikethrough~~ ||spoiler|| plain',\n [\n createEntity('messageEntityBold', 6, 4),\n createEntity('messageEntityItalic', 11, 6),\n createEntity('messageEntityUnderline', 18, 9),\n createEntity('messageEntityStrike', 28, 13),\n createEntity('messageEntitySpoiler', 42, 7),\n ],\n 'plain bold italic underline strikethrough spoiler plain',\n )\n })\n\n it('should handle code and pre', () => {\n test(\n [\n 'plain `code` ```\\npre\\n``` `__ignored__` plain',\n 'plain `code` ```\\npre\\n``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n 'plain `code` ```\\npre``` `\\\\_\\\\_ignored\\\\_\\\\_` plain',\n ],\n [\n createEntity('messageEntityCode', 6, 4),\n createEntity('messageEntityPre', 11, 3, { language: '' }),\n createEntity('messageEntityCode', 15, 11),\n ],\n 'plain code pre __ignored__ plain',\n )\n\n test(\n 'plain ```\\npre with ` and ``\\n``` plain',\n [createEntity('messageEntityPre', 6, 17, { language: '' })],\n 'plain pre with ` and `` plain',\n )\n\n test(\n 'plain ```\\npre with \\n`\\n and \\n``\\nend\\n``` plain',\n [createEntity('messageEntityPre', 6, 24, { language: '' })],\n 'plain pre with \\n`\\n and \\n``\\nend plain',\n )\n })\n\n it('should handle links and text mentions', () => {\n test(\n 'plain https://google.com [google](https://google.com) @durov [Pavel Durov](tg://user?id=36265675) plain',\n [\n createEntity('messageEntityTextUrl', 25, 6, {\n url: 'https://google.com',\n }),\n createEntity('messageEntityMentionName', 39, 11, {\n userId: 36265675,\n }),\n ],\n 'plain https://google.com google @durov Pavel Durov plain',\n )\n\n test(\n '[user](tg://user?id=1234567&hash=aabbccddaabbccdd)',\n [\n createEntity('inputMessageEntityMentionName', 0, 4, {\n userId: {\n _: 'inputUser',\n userId: 1234567,\n accessHash: Long.fromString('aabbccddaabbccdd', 16),\n },\n }),\n ],\n 'user',\n )\n })\n\n it('should handle language in pre', () => {\n test(\n 'plain ```javascript\\nconsole.log(\"Hello, world!\")\\n``` ```\\nsome code\\n``` plain',\n [\n createEntity('messageEntityPre', 6, 28, {\n language: 'javascript',\n }),\n createEntity('messageEntityPre', 35, 9, { language: '' }),\n ],\n 'plain console.log(\"Hello, world!\") some code plain',\n )\n })\n\n it('should support entities on the edges', () => {\n test(\n '**Hello**, **world**',\n [createEntity('messageEntityBold', 0, 5), createEntity('messageEntityBold', 7, 5)],\n 'Hello, world',\n )\n })\n\n it('should return empty array if there are no entities', () => {\n test('Hello, world', [], 'Hello, world')\n })\n\n it('should support overlapping entities', () => {\n test(\n '__Welcome **to the__ gym** zone!',\n [createEntity('messageEntityItalic', 0, 14), createEntity('messageEntityBold', 8, 10)],\n 'Welcome to the gym zone!',\n )\n\n // resulting order will depend on the order in which the closing ** or __ are passed,\n // thus we use separate tests\n test(\n 'plain **bold __bold-italic --bold-italic-underline**__ underline-- plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n 'plain bold bold-italic bold-italic-underline underline plain',\n )\n test(\n 'plain **bold __bold-italic --bold-italic-underline__** underline-- plain',\n [\n createEntity('messageEntityItalic', 11, 33),\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityUnderline', 23, 31),\n ],\n 'plain bold bold-italic bold-italic-underline underline plain',\n )\n\n test(\n 'plain **bold __bold-italic --bold-italic-underline** italic-underline__ underline-- plain',\n [\n createEntity('messageEntityBold', 6, 38),\n createEntity('messageEntityItalic', 11, 50),\n createEntity('messageEntityUnderline', 23, 48),\n ],\n 'plain bold bold-italic bold-italic-underline italic-underline underline plain',\n )\n })\n\n it('should support entities followed by each other', () => {\n test(\n ['plain **Hello,**__ world__ plain', 'plain **Hello,__** world__ plain'],\n [createEntity('messageEntityBold', 6, 6), createEntity('messageEntityItalic', 12, 6)],\n 'plain Hello, world plain',\n )\n })\n\n it('should support nested entities', () => {\n test(\n '__Welcome to the **gym zone**!__',\n [createEntity('messageEntityBold', 15, 8), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n\n test(\n 'plain [__google__](https://google.com) plain',\n [\n createEntity('messageEntityItalic', 6, 6),\n createEntity('messageEntityTextUrl', 6, 6, {\n url: 'https://google.com',\n }),\n ],\n 'plain google plain',\n )\n test(\n 'plain [plain __google__ plain](https://google.com) plain',\n [\n createEntity('messageEntityItalic', 12, 6),\n createEntity('messageEntityTextUrl', 6, 18, {\n url: 'https://google.com',\n }),\n ],\n 'plain plain google plain plain',\n )\n })\n\n it('should support nested entities with the same edges', () => {\n // again, order of the entities depends on which closing tag goes first.\n test(\n '__Welcome to the **gym zone!**__',\n [createEntity('messageEntityBold', 15, 9), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n '__Welcome to the **gym zone!__**',\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 15, 9)],\n 'Welcome to the gym zone!',\n )\n\n test(\n '**Welcome to the __gym zone!__**',\n [createEntity('messageEntityItalic', 15, 9), createEntity('messageEntityBold', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n '**Welcome to the __gym zone!**__',\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 15, 9)],\n 'Welcome to the gym zone!',\n )\n\n test(\n ['__**Welcome** to the gym zone!__', '**__Welcome** to the gym zone!__'],\n [createEntity('messageEntityBold', 0, 7), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n\n test(\n ['__**Welcome to the gym zone!**__', '**__Welcome to the gym zone!**__'],\n [createEntity('messageEntityBold', 0, 24), createEntity('messageEntityItalic', 0, 24)],\n 'Welcome to the gym zone!',\n )\n test(\n ['__**Welcome to the gym zone!__**', '**__Welcome to the gym zone!__**'],\n [createEntity('messageEntityItalic', 0, 24), createEntity('messageEntityBold', 0, 24)],\n 'Welcome to the gym zone!',\n )\n })\n\n it('should properly handle emojis', () => {\n test(\n \"__best flower__: **🌸**. __don't__ you even doubt it.\",\n [\n createEntity('messageEntityItalic', 0, 11),\n createEntity('messageEntityBold', 13, 2),\n createEntity('messageEntityItalic', 17, 5),\n ],\n \"best flower: 🌸. don't you even doubt it.\",\n )\n })\n\n it('should handle escaped reserved symbols', () => {\n test(\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ /- /-/- /-/-/- /~ /~/~ /~/~/~ /[ /[/[ /` /`/` /`/`/` /`/`/`/` // ////'.replace(\n /\\//g,\n '\\\\',\n ),\n [createEntity('messageEntityItalic', 9, 8)],\n '* ** *** _ __ ___ - -- --- ~ ~~ ~~~ [ [[ ` `` ``` ```` \\\\ \\\\\\\\',\n )\n test(\n '/* /*/* /*/*/* __/_ /_/_ /_/_/___ __/- /-/-__ /-/-/-'.replace(/\\//g, '\\\\'),\n [createEntity('messageEntityItalic', 9, 8), createEntity('messageEntityItalic', 18, 4)],\n '* ** *** _ __ ___ - -- ---',\n )\n })\n\n it('should ignore empty urls', () => {\n test('[link]() [link]', [], 'link [link]')\n })\n\n describe('malformed input', () => {\n const testThrows = (input: string) => expect(() => md_(input)).throws(Error)\n\n it('should throw an error on malformed links', () => {\n testThrows('plain [link](https://google.com but unclosed')\n })\n\n it('should throw an error on malformed pres', () => {\n testThrows('plain ```pre without linebreaks```')\n testThrows('plain ``` pre without linebreaks but with spaces instead ```')\n })\n\n it('should throw an error on unterminated entity', () => {\n testThrows('plain **bold but unclosed')\n testThrows('plain **bold and __also italic but unclosed')\n })\n })\n })\n\n describe('template', () => {\n const test = (text: TextWithEntities, expectedEntities: tl.TypeMessageEntity[], expectedText: string): void => {\n expect(text.text).eql(expectedText)\n expect(text.entities ?? []).eql(expectedEntities)\n }\n\n it('should add plain strings as is', () => {\n test(md_`${'**plain**'}`, [], '**plain**')\n })\n\n it('should skip falsy values', () => {\n test(md_`some text ${null} more text ${false}`, [], 'some text more text ')\n })\n\n it('should properly dedent', () => {\n test(\n md_`\n some text\n **bold**\n more text\n `,\n [createEntity('messageEntityBold', 10, 4)],\n 'some text\\nbold\\nmore text',\n )\n })\n\n it('should process entities', () => {\n const inner = md_`**bold**`\n\n test(\n md_`some text ${inner} some more text`,\n [createEntity('messageEntityBold', 10, 4)],\n 'some text bold some more text',\n )\n test(\n md_`some text ${inner} some more ${inner} text`,\n [createEntity('messageEntityBold', 10, 4), createEntity('messageEntityBold', 25, 4)],\n 'some text bold some more bold text',\n )\n })\n\n it('should process entities on edges', () => {\n test(\n md_`${md_`**bold**`} and ${md_`__italic__`}`,\n [createEntity('messageEntityBold', 0, 4), createEntity('messageEntityItalic', 9, 6)],\n 'bold and italic',\n )\n })\n\n it('should process nested entities', () => {\n test(\n md_`**bold ${md_`__bold italic__`} more bold**`,\n [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)],\n 'bold bold italic more bold',\n )\n test(\n md_`**bold ${md_`__bold italic__ --and some underline--`} more bold**`,\n [\n createEntity('messageEntityItalic', 5, 11),\n createEntity('messageEntityUnderline', 17, 18),\n createEntity('messageEntityBold', 0, 45),\n ],\n 'bold bold italic and some underline more bold',\n )\n test(\n md_`**${md_`__bold italic --underline--__`}**`,\n [\n createEntity('messageEntityUnderline', 12, 9),\n createEntity('messageEntityItalic', 0, 21),\n createEntity('messageEntityBold', 0, 21),\n ],\n 'bold italic underline',\n )\n })\n\n it('should process MessageEntity', () => {\n test(\n md_`**bold ${new MessageEntity(createEntity('messageEntityItalic', 0, 11), 'bold italic')} more bold**`,\n [createEntity('messageEntityItalic', 5, 11), createEntity('messageEntityBold', 0, 26)],\n 'bold bold italic more bold',\n )\n })\n })\n})\n"]}