JSPM

@monixlite/markup2html

1.1.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 21
    • Score
      100M100P100Q42745F
    • License ISC

    Library for translating various text markups into HTML

    Package Exports

    • @monixlite/markup2html
    • @monixlite/markup2html/src/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@monixlite/markup2html) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @monixlite/markup2html

    Конвертер различных разметок (MarkdownV1, MarkdownV2 и др.) в HTML.
    Поддерживает разнообразные стили форматирования, используемые в Telegram и других системах.


    Установка

    npm install @monixlite/markup2html

    Использование

    const m2html = require('@monixlite/markup2html');
    
    const markdown = '*bold text* _italic text_';
    const html = m2html.format('markdownv2', markdown);
    
    console.log(html); // <b>bold text</b> <i>italic text</i>
    
    // ИЛИ
    
    const markdown = '*bold text* _italic text_';
    const html = m2html.Markdown(markdown);
    
    console.log(html); // <b>bold text</b> <i>italic text</i>

    Описание

    @monixlite/markup2html — это модуль Node.js для преобразования разметки, например Telegram MarkdownV2, в валидный HTML с соответствующими тегами и стилями.

    Он корректно обрабатывает такие элементы форматирования, как:

    • Жирный текст (*bold*)
    • Курсив (_italic_)
    • Подчёркивание (__underline__)
    • Зачёркнутый (~strikethrough~)
    • ||Спойлер|| (||spoiler||)
    • Вложенное и комбинированное форматирование
    • Ссылки, упоминания пользователей, эмодзи
    • Инлайн и блочные фиксированные ширины кода
    • Цитаты и расширяемые цитаты

    Пример разметки (Markdown)

    *bold \*text*  
    _italic \*text_  
    __underline__  
    ~strikethrough~  
    ||spoiler||  
    *bold _italic bold ~italic bold strikethrough ||italic bold strikethrough spoiler||~ __underline italic bold___ bold*  
    [inline URL](http://www.example.com/)

    Конвертируется в (HTML)

    <b>bold</b>
    <i>italic</i>
    <u>underline</u>
    <s>strikethrough</s>
    <span class="tg-spoiler">spoiler</span>
    <b>bold <i>italic bold <s>italic bold strikethrough <span class="tg-spoiler">italic bold strikethrough spoiler</span></s> <u>underline italic bold</u></i> bold</b>  
    <a href="http://www.example.com/">inline URL</a>  

    API

    .format(style: string, content: string): string

    Преобразует content из указанного style (например, 'markdownv2') в HTML.

    • style — название стиля (без учёта регистра)
    • content — строка с исходной разметкой

    Возвращает строку с HTML.


    .escape(content: string): string

    Экранирует специальные символы для безопасного вывода:

    _ * [ ] ( ) ~ ` > # + - = | { } . !


    Лицензия

    MIT