telegram-md2html 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -303,10 +303,15 @@ If you find this library useful, please consider:
303
303
  - Browser compatibility
304
304
  - Custom processor support
305
305
 
306
+ ### v1.0.2
307
+ - **Improved output formatting**: Removed extra newlines around code blocks and quotes
308
+ - Cleaner HTML output without unnecessary whitespace
309
+ - Better preservation of original markdown formatting
310
+
306
311
  ## Author
307
312
 
308
313
  **Soumyadeep Das**
309
- - GitHub: [@Soumyadeep765](https://github.com/Soumyadeep765)
314
+ - GitHub: [@Soumyadeep765](https://github.com/Soumyadeep765/telegram-md2html)
310
315
  - Email: soumyadeepdas765@gmail.com
311
316
 
312
317
  ## Acknowledgments
@@ -14,6 +14,8 @@ export declare class MarkdownConverter {
14
14
  private convertRecursive;
15
15
  /**
16
16
  * Wrap token content in HTML tags
17
+ * FIXED: Removed extra newlines that were being added around code blocks and quotes
18
+ * Previously added \n before and after, now returns clean tags without extra whitespace
17
19
  */
18
20
  private wrapToken;
19
21
  /**
@@ -22,6 +24,7 @@ export declare class MarkdownConverter {
22
24
  private preprocessBlockquotes;
23
25
  /**
24
26
  * Process blockquote markers
27
+ * FIXED: Removed extra newlines from the replacement strings
25
28
  */
26
29
  private processBlockquoteMarkers;
27
30
  private defaultLinkProcessor;
package/dist/index.cjs CHANGED
@@ -293,6 +293,8 @@ class MarkdownConverter {
293
293
  }
294
294
  /**
295
295
  * Wrap token content in HTML tags
296
+ * FIXED: Removed extra newlines that were being added around code blocks and quotes
297
+ * Previously added \n before and after, now returns clean tags without extra whitespace
296
298
  */
297
299
  wrapToken(type, content, language) {
298
300
  switch (type) {
@@ -316,7 +318,8 @@ class MarkdownConverter {
316
318
  }
317
319
  const escapedCode = this.options.escapeHtml ? escapeHtml(content) : content;
318
320
  const langAttr = language ? ` class="language-${language}"` : '';
319
- return `\n<pre><code${langAttr}>${escapedCode}</code></pre>\n`;
321
+ // FIXED: Removed \n before and after - now returns just the tag
322
+ return `<pre><code${langAttr}>${escapedCode}</code></pre>`;
320
323
  case 'link':
321
324
  const url = language || '';
322
325
  if (this.hasCustomLinkProcessor) {
@@ -326,9 +329,11 @@ class MarkdownConverter {
326
329
  const escapedText = this.options.escapeHtml ? escapeHtml(content) : content;
327
330
  return `<a href="${escapedUrl}">${escapedText}</a>`;
328
331
  case 'quote':
329
- return `\n<blockquote>${content.trim()}</blockquote>\n`;
332
+ // FIXED: Removed \n before and after - now returns just the tag
333
+ return `<blockquote>${content.trim()}</blockquote>`;
330
334
  case 'expandable_quote':
331
- return `\n<blockquote expandable>${content.trim()}</blockquote>\n`;
335
+ // FIXED: Removed \n before and after - now returns just the tag
336
+ return `<blockquote expandable>${content.trim()}</blockquote>`;
332
337
  default:
333
338
  return content;
334
339
  }
@@ -360,6 +365,7 @@ class MarkdownConverter {
360
365
  }
361
366
  /**
362
367
  * Process blockquote markers
368
+ * FIXED: Removed extra newlines from the replacement strings
363
369
  */
364
370
  processBlockquoteMarkers(text) {
365
371
  let result = text;
@@ -367,13 +373,15 @@ class MarkdownConverter {
367
373
  const expandableQuoteRegex = /\[EXPANDABLE_QUOTE\](.*?)(?=\n|$)/g;
368
374
  result = result.replace(expandableQuoteRegex, (match, content) => {
369
375
  const processedContent = this.convertRecursive(content);
370
- return `\n<blockquote expandable>${processedContent.trim()}</blockquote>\n`;
376
+ // FIXED: Removed \n before and after
377
+ return `<blockquote expandable>${processedContent.trim()}</blockquote>`;
371
378
  });
372
379
  // Replace regular quote markers (process content recursively)
373
380
  const quoteRegex = /\[QUOTE\](.*?)(?=\n|$)/g;
374
381
  result = result.replace(quoteRegex, (match, content) => {
375
382
  const processedContent = this.convertRecursive(content);
376
- return `\n<blockquote>${processedContent.trim()}</blockquote>\n`;
383
+ // FIXED: Removed \n before and after
384
+ return `<blockquote>${processedContent.trim()}</blockquote>`;
377
385
  });
378
386
  return result;
379
387
  }
@@ -385,7 +393,8 @@ class MarkdownConverter {
385
393
  defaultCodeBlockProcessor(code, language) {
386
394
  const escapedCode = this.options.escapeHtml ? escapeHtml(code) : code;
387
395
  const langAttr = language ? ` class="language-${language}"` : '';
388
- return `\n<pre><code${langAttr}>${escapedCode}</code></pre>\n`;
396
+ // FIXED: Removed \n before and after in default processor too
397
+ return `<pre><code${langAttr}>${escapedCode}</code></pre>`;
389
398
  }
390
399
  }
391
400
 
package/dist/index.esm.js CHANGED
@@ -289,6 +289,8 @@ class MarkdownConverter {
289
289
  }
290
290
  /**
291
291
  * Wrap token content in HTML tags
292
+ * FIXED: Removed extra newlines that were being added around code blocks and quotes
293
+ * Previously added \n before and after, now returns clean tags without extra whitespace
292
294
  */
293
295
  wrapToken(type, content, language) {
294
296
  switch (type) {
@@ -312,7 +314,8 @@ class MarkdownConverter {
312
314
  }
313
315
  const escapedCode = this.options.escapeHtml ? escapeHtml(content) : content;
314
316
  const langAttr = language ? ` class="language-${language}"` : '';
315
- return `\n<pre><code${langAttr}>${escapedCode}</code></pre>\n`;
317
+ // FIXED: Removed \n before and after - now returns just the tag
318
+ return `<pre><code${langAttr}>${escapedCode}</code></pre>`;
316
319
  case 'link':
317
320
  const url = language || '';
318
321
  if (this.hasCustomLinkProcessor) {
@@ -322,9 +325,11 @@ class MarkdownConverter {
322
325
  const escapedText = this.options.escapeHtml ? escapeHtml(content) : content;
323
326
  return `<a href="${escapedUrl}">${escapedText}</a>`;
324
327
  case 'quote':
325
- return `\n<blockquote>${content.trim()}</blockquote>\n`;
328
+ // FIXED: Removed \n before and after - now returns just the tag
329
+ return `<blockquote>${content.trim()}</blockquote>`;
326
330
  case 'expandable_quote':
327
- return `\n<blockquote expandable>${content.trim()}</blockquote>\n`;
331
+ // FIXED: Removed \n before and after - now returns just the tag
332
+ return `<blockquote expandable>${content.trim()}</blockquote>`;
328
333
  default:
329
334
  return content;
330
335
  }
@@ -356,6 +361,7 @@ class MarkdownConverter {
356
361
  }
357
362
  /**
358
363
  * Process blockquote markers
364
+ * FIXED: Removed extra newlines from the replacement strings
359
365
  */
360
366
  processBlockquoteMarkers(text) {
361
367
  let result = text;
@@ -363,13 +369,15 @@ class MarkdownConverter {
363
369
  const expandableQuoteRegex = /\[EXPANDABLE_QUOTE\](.*?)(?=\n|$)/g;
364
370
  result = result.replace(expandableQuoteRegex, (match, content) => {
365
371
  const processedContent = this.convertRecursive(content);
366
- return `\n<blockquote expandable>${processedContent.trim()}</blockquote>\n`;
372
+ // FIXED: Removed \n before and after
373
+ return `<blockquote expandable>${processedContent.trim()}</blockquote>`;
367
374
  });
368
375
  // Replace regular quote markers (process content recursively)
369
376
  const quoteRegex = /\[QUOTE\](.*?)(?=\n|$)/g;
370
377
  result = result.replace(quoteRegex, (match, content) => {
371
378
  const processedContent = this.convertRecursive(content);
372
- return `\n<blockquote>${processedContent.trim()}</blockquote>\n`;
379
+ // FIXED: Removed \n before and after
380
+ return `<blockquote>${processedContent.trim()}</blockquote>`;
373
381
  });
374
382
  return result;
375
383
  }
@@ -381,7 +389,8 @@ class MarkdownConverter {
381
389
  defaultCodeBlockProcessor(code, language) {
382
390
  const escapedCode = this.options.escapeHtml ? escapeHtml(code) : code;
383
391
  const langAttr = language ? ` class="language-${language}"` : '';
384
- return `\n<pre><code${langAttr}>${escapedCode}</code></pre>\n`;
392
+ // FIXED: Removed \n before and after in default processor too
393
+ return `<pre><code${langAttr}>${escapedCode}</code></pre>`;
385
394
  }
386
395
  }
387
396
 
package/dist/index.mjs CHANGED
@@ -289,6 +289,8 @@ class MarkdownConverter {
289
289
  }
290
290
  /**
291
291
  * Wrap token content in HTML tags
292
+ * FIXED: Removed extra newlines that were being added around code blocks and quotes
293
+ * Previously added \n before and after, now returns clean tags without extra whitespace
292
294
  */
293
295
  wrapToken(type, content, language) {
294
296
  switch (type) {
@@ -312,7 +314,8 @@ class MarkdownConverter {
312
314
  }
313
315
  const escapedCode = this.options.escapeHtml ? escapeHtml(content) : content;
314
316
  const langAttr = language ? ` class="language-${language}"` : '';
315
- return `\n<pre><code${langAttr}>${escapedCode}</code></pre>\n`;
317
+ // FIXED: Removed \n before and after - now returns just the tag
318
+ return `<pre><code${langAttr}>${escapedCode}</code></pre>`;
316
319
  case 'link':
317
320
  const url = language || '';
318
321
  if (this.hasCustomLinkProcessor) {
@@ -322,9 +325,11 @@ class MarkdownConverter {
322
325
  const escapedText = this.options.escapeHtml ? escapeHtml(content) : content;
323
326
  return `<a href="${escapedUrl}">${escapedText}</a>`;
324
327
  case 'quote':
325
- return `\n<blockquote>${content.trim()}</blockquote>\n`;
328
+ // FIXED: Removed \n before and after - now returns just the tag
329
+ return `<blockquote>${content.trim()}</blockquote>`;
326
330
  case 'expandable_quote':
327
- return `\n<blockquote expandable>${content.trim()}</blockquote>\n`;
331
+ // FIXED: Removed \n before and after - now returns just the tag
332
+ return `<blockquote expandable>${content.trim()}</blockquote>`;
328
333
  default:
329
334
  return content;
330
335
  }
@@ -356,6 +361,7 @@ class MarkdownConverter {
356
361
  }
357
362
  /**
358
363
  * Process blockquote markers
364
+ * FIXED: Removed extra newlines from the replacement strings
359
365
  */
360
366
  processBlockquoteMarkers(text) {
361
367
  let result = text;
@@ -363,13 +369,15 @@ class MarkdownConverter {
363
369
  const expandableQuoteRegex = /\[EXPANDABLE_QUOTE\](.*?)(?=\n|$)/g;
364
370
  result = result.replace(expandableQuoteRegex, (match, content) => {
365
371
  const processedContent = this.convertRecursive(content);
366
- return `\n<blockquote expandable>${processedContent.trim()}</blockquote>\n`;
372
+ // FIXED: Removed \n before and after
373
+ return `<blockquote expandable>${processedContent.trim()}</blockquote>`;
367
374
  });
368
375
  // Replace regular quote markers (process content recursively)
369
376
  const quoteRegex = /\[QUOTE\](.*?)(?=\n|$)/g;
370
377
  result = result.replace(quoteRegex, (match, content) => {
371
378
  const processedContent = this.convertRecursive(content);
372
- return `\n<blockquote>${processedContent.trim()}</blockquote>\n`;
379
+ // FIXED: Removed \n before and after
380
+ return `<blockquote>${processedContent.trim()}</blockquote>`;
373
381
  });
374
382
  return result;
375
383
  }
@@ -381,7 +389,8 @@ class MarkdownConverter {
381
389
  defaultCodeBlockProcessor(code, language) {
382
390
  const escapedCode = this.options.escapeHtml ? escapeHtml(code) : code;
383
391
  const langAttr = language ? ` class="language-${language}"` : '';
384
- return `\n<pre><code${langAttr}>${escapedCode}</code></pre>\n`;
392
+ // FIXED: Removed \n before and after in default processor too
393
+ return `<pre><code${langAttr}>${escapedCode}</code></pre>`;
385
394
  }
386
395
  }
387
396
 
package/dist/index.umd.js CHANGED
@@ -295,6 +295,8 @@
295
295
  }
296
296
  /**
297
297
  * Wrap token content in HTML tags
298
+ * FIXED: Removed extra newlines that were being added around code blocks and quotes
299
+ * Previously added \n before and after, now returns clean tags without extra whitespace
298
300
  */
299
301
  wrapToken(type, content, language) {
300
302
  switch (type) {
@@ -318,7 +320,8 @@
318
320
  }
319
321
  const escapedCode = this.options.escapeHtml ? escapeHtml(content) : content;
320
322
  const langAttr = language ? ` class="language-${language}"` : '';
321
- return `\n<pre><code${langAttr}>${escapedCode}</code></pre>\n`;
323
+ // FIXED: Removed \n before and after - now returns just the tag
324
+ return `<pre><code${langAttr}>${escapedCode}</code></pre>`;
322
325
  case 'link':
323
326
  const url = language || '';
324
327
  if (this.hasCustomLinkProcessor) {
@@ -328,9 +331,11 @@
328
331
  const escapedText = this.options.escapeHtml ? escapeHtml(content) : content;
329
332
  return `<a href="${escapedUrl}">${escapedText}</a>`;
330
333
  case 'quote':
331
- return `\n<blockquote>${content.trim()}</blockquote>\n`;
334
+ // FIXED: Removed \n before and after - now returns just the tag
335
+ return `<blockquote>${content.trim()}</blockquote>`;
332
336
  case 'expandable_quote':
333
- return `\n<blockquote expandable>${content.trim()}</blockquote>\n`;
337
+ // FIXED: Removed \n before and after - now returns just the tag
338
+ return `<blockquote expandable>${content.trim()}</blockquote>`;
334
339
  default:
335
340
  return content;
336
341
  }
@@ -362,6 +367,7 @@
362
367
  }
363
368
  /**
364
369
  * Process blockquote markers
370
+ * FIXED: Removed extra newlines from the replacement strings
365
371
  */
366
372
  processBlockquoteMarkers(text) {
367
373
  let result = text;
@@ -369,13 +375,15 @@
369
375
  const expandableQuoteRegex = /\[EXPANDABLE_QUOTE\](.*?)(?=\n|$)/g;
370
376
  result = result.replace(expandableQuoteRegex, (match, content) => {
371
377
  const processedContent = this.convertRecursive(content);
372
- return `\n<blockquote expandable>${processedContent.trim()}</blockquote>\n`;
378
+ // FIXED: Removed \n before and after
379
+ return `<blockquote expandable>${processedContent.trim()}</blockquote>`;
373
380
  });
374
381
  // Replace regular quote markers (process content recursively)
375
382
  const quoteRegex = /\[QUOTE\](.*?)(?=\n|$)/g;
376
383
  result = result.replace(quoteRegex, (match, content) => {
377
384
  const processedContent = this.convertRecursive(content);
378
- return `\n<blockquote>${processedContent.trim()}</blockquote>\n`;
385
+ // FIXED: Removed \n before and after
386
+ return `<blockquote>${processedContent.trim()}</blockquote>`;
379
387
  });
380
388
  return result;
381
389
  }
@@ -387,7 +395,8 @@
387
395
  defaultCodeBlockProcessor(code, language) {
388
396
  const escapedCode = this.options.escapeHtml ? escapeHtml(code) : code;
389
397
  const langAttr = language ? ` class="language-${language}"` : '';
390
- return `\n<pre><code${langAttr}>${escapedCode}</code></pre>\n`;
398
+ // FIXED: Removed \n before and after in default processor too
399
+ return `<pre><code${langAttr}>${escapedCode}</code></pre>`;
391
400
  }
392
401
  }
393
402
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telegram-md2html",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A smart converter for Telegram-style Markdown to Telegram-compatible HTML",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",