koztv-blog-tools 1.2.5 → 1.2.7
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/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +47 -2
- package/dist/index.mjs +47 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -374,6 +374,42 @@ var import_sessions = require("telegram/sessions");
|
|
|
374
374
|
var fs = __toESM(require("fs"));
|
|
375
375
|
var path = __toESM(require("path"));
|
|
376
376
|
var readline = __toESM(require("readline"));
|
|
377
|
+
function entitiesToMarkdown(text, entities) {
|
|
378
|
+
if (!entities || entities.length === 0) return text;
|
|
379
|
+
const sorted = [...entities].sort((a, b) => b.offset - a.offset);
|
|
380
|
+
let result = text;
|
|
381
|
+
for (const entity of sorted) {
|
|
382
|
+
const start = entity.offset;
|
|
383
|
+
const end = entity.offset + entity.length;
|
|
384
|
+
const content = result.substring(start, end);
|
|
385
|
+
let replacement = content;
|
|
386
|
+
if (entity instanceof import_telegram.Api.MessageEntityBold) {
|
|
387
|
+
replacement = `**${content}**`;
|
|
388
|
+
} else if (entity instanceof import_telegram.Api.MessageEntityItalic) {
|
|
389
|
+
replacement = `*${content}*`;
|
|
390
|
+
} else if (entity instanceof import_telegram.Api.MessageEntityCode) {
|
|
391
|
+
replacement = `\`${content}\``;
|
|
392
|
+
} else if (entity instanceof import_telegram.Api.MessageEntityPre) {
|
|
393
|
+
replacement = `\`\`\`
|
|
394
|
+
${content}
|
|
395
|
+
\`\`\``;
|
|
396
|
+
} else if (entity instanceof import_telegram.Api.MessageEntityStrike) {
|
|
397
|
+
replacement = `~~${content}~~`;
|
|
398
|
+
} else if (entity instanceof import_telegram.Api.MessageEntityUnderline) {
|
|
399
|
+
replacement = `**${content}**`;
|
|
400
|
+
} else if (entity instanceof import_telegram.Api.MessageEntityTextUrl) {
|
|
401
|
+
replacement = `[${content}](${entity.url})`;
|
|
402
|
+
} else if (entity instanceof import_telegram.Api.MessageEntityUrl) {
|
|
403
|
+
replacement = content;
|
|
404
|
+
} else if (entity instanceof import_telegram.Api.MessageEntityMention) {
|
|
405
|
+
replacement = content;
|
|
406
|
+
} else if (entity instanceof import_telegram.Api.MessageEntityHashtag) {
|
|
407
|
+
replacement = content;
|
|
408
|
+
}
|
|
409
|
+
result = result.substring(0, start) + replacement + result.substring(end);
|
|
410
|
+
}
|
|
411
|
+
return result;
|
|
412
|
+
}
|
|
377
413
|
async function defaultReadline(prompt) {
|
|
378
414
|
const rl = readline.createInterface({
|
|
379
415
|
input: process.stdin,
|
|
@@ -537,8 +573,12 @@ async function exportTelegramChannel(options) {
|
|
|
537
573
|
}
|
|
538
574
|
}
|
|
539
575
|
}
|
|
540
|
-
const content = message.message || "";
|
|
576
|
+
const content = entitiesToMarkdown(message.message || "", message.entities);
|
|
541
577
|
const link = channelMeta.username ? `https://t.me/${channelMeta.username}/${msgId}` : "";
|
|
578
|
+
let replyToMsgId;
|
|
579
|
+
if (message.replyTo && "replyToMsgId" in message.replyTo) {
|
|
580
|
+
replyToMsgId = message.replyTo.replyToMsgId;
|
|
581
|
+
}
|
|
542
582
|
const post = {
|
|
543
583
|
msgId,
|
|
544
584
|
date: new Date(message.date * 1e3),
|
|
@@ -549,7 +589,8 @@ async function exportTelegramChannel(options) {
|
|
|
549
589
|
forwards: message.forwards,
|
|
550
590
|
link,
|
|
551
591
|
channelUsername: channelMeta.username,
|
|
552
|
-
channelTitle: channelMeta.title
|
|
592
|
+
channelTitle: channelMeta.title,
|
|
593
|
+
replyToMsgId
|
|
553
594
|
};
|
|
554
595
|
posts.push(post);
|
|
555
596
|
const markdown = formatPostMarkdown(post);
|
|
@@ -582,6 +623,10 @@ views: ${post.views}`;
|
|
|
582
623
|
if (post.forwards !== void 0) {
|
|
583
624
|
frontmatter += `
|
|
584
625
|
forwards: ${post.forwards}`;
|
|
626
|
+
}
|
|
627
|
+
if (post.replyToMsgId !== void 0) {
|
|
628
|
+
frontmatter += `
|
|
629
|
+
reply_to_msg_id: ${post.replyToMsgId}`;
|
|
585
630
|
}
|
|
586
631
|
frontmatter += "\n---\n\n";
|
|
587
632
|
let body = post.content || "";
|
package/dist/index.mjs
CHANGED
|
@@ -317,6 +317,42 @@ import { StringSession } from "telegram/sessions";
|
|
|
317
317
|
import * as fs from "fs";
|
|
318
318
|
import * as path from "path";
|
|
319
319
|
import * as readline from "readline";
|
|
320
|
+
function entitiesToMarkdown(text, entities) {
|
|
321
|
+
if (!entities || entities.length === 0) return text;
|
|
322
|
+
const sorted = [...entities].sort((a, b) => b.offset - a.offset);
|
|
323
|
+
let result = text;
|
|
324
|
+
for (const entity of sorted) {
|
|
325
|
+
const start = entity.offset;
|
|
326
|
+
const end = entity.offset + entity.length;
|
|
327
|
+
const content = result.substring(start, end);
|
|
328
|
+
let replacement = content;
|
|
329
|
+
if (entity instanceof Api.MessageEntityBold) {
|
|
330
|
+
replacement = `**${content}**`;
|
|
331
|
+
} else if (entity instanceof Api.MessageEntityItalic) {
|
|
332
|
+
replacement = `*${content}*`;
|
|
333
|
+
} else if (entity instanceof Api.MessageEntityCode) {
|
|
334
|
+
replacement = `\`${content}\``;
|
|
335
|
+
} else if (entity instanceof Api.MessageEntityPre) {
|
|
336
|
+
replacement = `\`\`\`
|
|
337
|
+
${content}
|
|
338
|
+
\`\`\``;
|
|
339
|
+
} else if (entity instanceof Api.MessageEntityStrike) {
|
|
340
|
+
replacement = `~~${content}~~`;
|
|
341
|
+
} else if (entity instanceof Api.MessageEntityUnderline) {
|
|
342
|
+
replacement = `**${content}**`;
|
|
343
|
+
} else if (entity instanceof Api.MessageEntityTextUrl) {
|
|
344
|
+
replacement = `[${content}](${entity.url})`;
|
|
345
|
+
} else if (entity instanceof Api.MessageEntityUrl) {
|
|
346
|
+
replacement = content;
|
|
347
|
+
} else if (entity instanceof Api.MessageEntityMention) {
|
|
348
|
+
replacement = content;
|
|
349
|
+
} else if (entity instanceof Api.MessageEntityHashtag) {
|
|
350
|
+
replacement = content;
|
|
351
|
+
}
|
|
352
|
+
result = result.substring(0, start) + replacement + result.substring(end);
|
|
353
|
+
}
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
320
356
|
async function defaultReadline(prompt) {
|
|
321
357
|
const rl = readline.createInterface({
|
|
322
358
|
input: process.stdin,
|
|
@@ -480,8 +516,12 @@ async function exportTelegramChannel(options) {
|
|
|
480
516
|
}
|
|
481
517
|
}
|
|
482
518
|
}
|
|
483
|
-
const content = message.message || "";
|
|
519
|
+
const content = entitiesToMarkdown(message.message || "", message.entities);
|
|
484
520
|
const link = channelMeta.username ? `https://t.me/${channelMeta.username}/${msgId}` : "";
|
|
521
|
+
let replyToMsgId;
|
|
522
|
+
if (message.replyTo && "replyToMsgId" in message.replyTo) {
|
|
523
|
+
replyToMsgId = message.replyTo.replyToMsgId;
|
|
524
|
+
}
|
|
485
525
|
const post = {
|
|
486
526
|
msgId,
|
|
487
527
|
date: new Date(message.date * 1e3),
|
|
@@ -492,7 +532,8 @@ async function exportTelegramChannel(options) {
|
|
|
492
532
|
forwards: message.forwards,
|
|
493
533
|
link,
|
|
494
534
|
channelUsername: channelMeta.username,
|
|
495
|
-
channelTitle: channelMeta.title
|
|
535
|
+
channelTitle: channelMeta.title,
|
|
536
|
+
replyToMsgId
|
|
496
537
|
};
|
|
497
538
|
posts.push(post);
|
|
498
539
|
const markdown = formatPostMarkdown(post);
|
|
@@ -525,6 +566,10 @@ views: ${post.views}`;
|
|
|
525
566
|
if (post.forwards !== void 0) {
|
|
526
567
|
frontmatter += `
|
|
527
568
|
forwards: ${post.forwards}`;
|
|
569
|
+
}
|
|
570
|
+
if (post.replyToMsgId !== void 0) {
|
|
571
|
+
frontmatter += `
|
|
572
|
+
reply_to_msg_id: ${post.replyToMsgId}`;
|
|
528
573
|
}
|
|
529
574
|
frontmatter += "\n---\n\n";
|
|
530
575
|
let body = post.content || "";
|