diff --git a/package.json b/package.json index 5f5a9212..fe108b44 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,6 @@ "jsdoc": "3.5.x" }, "scripts": { - "gen-jsdoc": "./node_modules/.bin/jsdoc src/ --private --recurse --package package.json --readme README.md --destination jsdoc" + "gen-jsdoc": "./node_modules/.bin/jsdoc src/ --recurse --package package.json --readme README.md --destination jsdoc" } } diff --git a/src/formatter.js b/src/formatter.js index 8fff9210..4de10831 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -26,11 +26,35 @@ String.prototype.insert = function(at, str) { return this.slice(0, at) + str + this.slice(at) } +/** + * Add a simple HTML tag to the given tag list. + * + * @param {Object[]} tags The tag list. + * @param {Object} entity The Telegram format entity. + * @param {number} entity.offset The index where the format entity starts. + * @param {number} entity.length The length of the format entity. + * @param {string} tag The HTML tag to add. + * @param {number} priority The tag priority to use when sorting tags at the same index. + * @private + */ function addSimpleTag(tags, entity, tag, priority = 0) { tags.push([entity.offset, `<${tag}>`, -priority]) tags.push([entity.offset + entity.length, ``, priority]) } + +/** + * Add a HTML tag to the given tag list. + * + * @param {Object[]} tags The tag list. + * @param {Object} entity The Telegram format entity. + * @param {number} entity.offset The index where the format entity starts. + * @param {number} entity.length The length of the format entity. + * @param {string} tag The HTML tag to add. + * @param {string} attrs The HTML attributes to add to the tag. + * @param {number} priority The tag priority to use when sorting tags at the same index. + * @private + */ function addTag(tags, entity, tag, attrs, priority = 0) { tags.push([entity.offset, `<${tag} ${attrs}>`, -priority]) tags.push([entity.offset + entity.length, ``, priority]) @@ -168,9 +192,9 @@ RegExp.any = function(...regexes) { return new RegExp(`(?:${components.join(")|(?:")})`) } -const regexMonster = RegExp.any(//"g", - boldText, italicText, codeblocks, codeblocksWithSyntaxHighlight, - inlineCode, emailAddresses, mentions, hyperlinks) +const regexMonster = RegExp.any(boldText, italicText, codeblocks, + codeblocksWithSyntaxHighlight, inlineCode, emailAddresses, + mentions, hyperlinks) const NUMBER_OF_REGEXES_EATEN_BY_MONSTER = 8 function regexMonsterMatchParser(match) { diff --git a/src/telegram-puppet.js b/src/telegram-puppet.js index d333b65b..46631e57 100644 --- a/src/telegram-puppet.js +++ b/src/telegram-puppet.js @@ -17,8 +17,15 @@ const telegram = require("telegram-mtproto") const fileType = require("file-type") const pkg = require("../package.json") const TelegramPeer = require("./telegram-peer") -/* + + +/** + * @module telegram-puppet + */ + +/** * Mapping from Telegram file types to MIME types and extensions. + * @private */ function metaFromFileType(type) { const extension = type.substr("storage.file".length).toLowerCase() @@ -54,6 +61,13 @@ function metaFromFileType(type) { return { mimetype, extension, matrixtype } } +/** + * Mapping from MIME type to Matrix file type. Used when determining MIME type and extension using magic numbers. + * + * @param {string} mime The MIME type. + * @returns {string} The corresponding Matrix file type. + * @private + */ function matrixFromMime(mime) { if (mime.startsWith("audio/")) { return "m.audio"