diff --git a/umd/tinode.dev.js b/umd/tinode.dev.js index 27946b7c..150167d8 100644 --- a/umd/tinode.dev.js +++ b/umd/tinode.dev.js @@ -704,7 +704,7 @@ function _init_lp2() { _classPrivateMethodGet(this, _boffStop, _boffStop2).call(this); this.connect(null, force); }; - this.disconnect = () => { + this.disconnect = _ => { _classPrivateFieldSet(this, _boffClosed, true); _classPrivateMethodGet(this, _boffStop, _boffStop2).call(this); if (_sender) { @@ -730,7 +730,7 @@ function _init_lp2() { throw new Error("Long poller failed to connect"); } }; - this.isConnected = () => { + this.isConnected = _ => { return _poller && true; }; } @@ -755,7 +755,7 @@ function _init_ws2() { conn.onerror = err => { reject(err); }; - conn.onopen = evt => { + conn.onopen = _ => { if (this.autoreconnect) { _classPrivateMethodGet(this, _boffStop, _boffStop2).call(this); } @@ -764,7 +764,7 @@ function _init_ws2() { } resolve(); }; - conn.onclose = evt => { + conn.onclose = _ => { _classPrivateFieldSet(this, _socket, null); if (this.onDisconnect) { const code = _classPrivateFieldGet(this, _boffClosed) ? NETWORK_USER : NETWORK_ERROR; @@ -786,7 +786,7 @@ function _init_ws2() { _classPrivateMethodGet(this, _boffStop, _boffStop2).call(this); this.connect(null, force); }; - this.disconnect = () => { + this.disconnect = _ => { _classPrivateFieldSet(this, _boffClosed, true); _classPrivateMethodGet(this, _boffStop, _boffStop2).call(this); if (!_classPrivateFieldGet(this, _socket)) { @@ -802,7 +802,7 @@ function _init_ws2() { throw new Error("Websocket is not connected"); } }; - this.isConnected = () => { + this.isConnected = _ => { return _classPrivateFieldGet(this, _socket) && _classPrivateFieldGet(this, _socket).readyState == _classPrivateFieldGet(this, _socket).OPEN; }; } @@ -1426,77 +1426,95 @@ const ENTITY_TYPES = [ re: /\B#([\p{L}\p{N}][._\p{L}\p{N}]*[\p{L}\p{N}])/ug }]; -const HTML_TAGS = { +const FORMAT_TAGS = { AU: { - name: 'audio', + html_tag: 'audio', + md_tag: undefined, isVoid: false }, BN: { - name: 'button', + html_tag: 'button', + md_tag: undefined, isVoid: false }, BR: { - name: 'br', + html_tag: 'br', + md_tag: '\n', isVoid: true }, CO: { - name: 'tt', + html_tag: 'tt', + md_tag: '`', isVoid: false }, DL: { - name: 'del', + html_tag: 'del', + md_tag: '~', isVoid: false }, EM: { - name: 'i', + html_tag: 'i', + md_tag: '_', isVoid: false }, EX: { - name: '', + html_tag: '', + md_tag: undefined, isVoid: true }, FM: { - name: 'div', + html_tag: 'div', + md_tag: undefined, isVoid: false }, HD: { - name: '', + html_tag: '', + md_tag: undefined, isVoid: false }, HL: { - name: 'span', + html_tag: 'span', + md_tag: undefined, isVoid: false }, HT: { - name: 'a', + html_tag: 'a', + md_tag: undefined, isVoid: false }, IM: { - name: 'img', + html_tag: 'img', + md_tag: undefined, isVoid: false }, LN: { - name: 'a', + html_tag: 'a', + md_tag: undefined, isVoid: false }, MN: { - name: 'a', + html_tag: 'a', + md_tag: undefined, isVoid: false }, RW: { - name: 'div', + html_tag: 'div', + md_tag: undefined, isVoid: false }, QQ: { - name: 'div', + html_tag: 'div', + md_tag: undefined, isVoid: false }, ST: { - name: 'b', + html_tag: 'b', + md_tag: '*', isVoid: false }, VC: { - name: 'div', + html_tag: 'div', + md_tag: undefined, isVoid: false } }; @@ -2040,7 +2058,7 @@ Drafty.attachFile = function (content, attachmentDesc) { attachmentDesc.urlPromise.then(url => { ex.data.ref = url; ex.data._processing = undefined; - }, err => { + }, _ => { ex.data._processing = undefined; }); } @@ -2145,7 +2163,7 @@ Drafty.appendLineBreak = function (content) { return content; }; Drafty.UNSAFE_toHTML = function (doc) { - let tree = draftyToTree(doc); + const tree = draftyToTree(doc); const htmlFormatter = function (type, data, values) { const tag = DECORATORS[type]; let result = values ? values.join('') : ''; @@ -2254,6 +2272,23 @@ Drafty.isPlainText = function (content) { return typeof content == 'string' || !(content.fmt || content.ent); }; +Drafty.toMarkdown = function (content) { + let tree = draftyToTree(content); + const mdFormatter = function (type, _, values) { + const def = FORMAT_TAGS[type]; + let result = values ? values.join('') : ''; + if (def) { + if (def.isVoid) { + result = def.md_tag || ''; + } else if (def.md_tag) { + result = def.md_tag + result + def.md_tag; + } + } + return result; + }; + return treeBottomUp(tree, mdFormatter, 0); +}; + Drafty.isValid = function (content) { if (!content) { return false; @@ -2366,7 +2401,7 @@ Drafty.getEntityMimeType = function (entData) { }; Drafty.tagName = function (style) { - return HTML_TAGS[style] && HTML_TAGS[style].name; + return FORMAT_TAGS[style] && FORMAT_TAGS[style].html_tag; }; Drafty.attrValue = function (style, data) { @@ -2651,7 +2686,7 @@ function spansToTree(parent, text, start, end, spans) { break; } else if (inner.start < span.end) { if (inner.end <= span.end) { - const tag = HTML_TAGS[inner.tp] || {}; + const tag = FORMAT_TAGS[inner.tp] || {}; if (inner.start < inner.end || tag.isVoid) { subspans.push(inner); } @@ -3325,24 +3360,24 @@ function _get_subs_ims2() { * ... *