{"id":13772729,"url":"https://github.com/dcdunkan/syntax-highlighter-bot","last_synced_at":"2025-05-01T08:35:29.893Z","repository":{"id":37865921,"uuid":"482048230","full_name":"dcdunkan/syntax-highlighter-bot","owner":"dcdunkan","description":"A customizable syntax highlighter bot for Telegram.","archived":false,"fork":false,"pushed_at":"2023-09-26T21:26:01.000Z","size":3359,"stargazers_count":26,"open_issues_count":1,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-02-15T07:32:50.131Z","etag":null,"topics":["bot","deno","deta","grammyjs","highlightjs","puppeteer","syntax-highlighting","telegram-bot"],"latest_commit_sha":null,"homepage":"https://telegram.me/syntaxybot","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcdunkan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-04-15T18:22:18.000Z","updated_at":"2023-12-19T22:14:28.000Z","dependencies_parsed_at":"2023-09-27T02:42:04.637Z","dependency_job_id":null,"html_url":"https://github.com/dcdunkan/syntax-highlighter-bot","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Fsyntax-highlighter-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Fsyntax-highlighter-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Fsyntax-highlighter-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcdunkan%2Fsyntax-highlighter-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcdunkan","download_url":"https://codeload.github.com/dcdunkan/syntax-highlighter-bot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251848363,"owners_count":21653681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","deno","deta","grammyjs","highlightjs","puppeteer","syntax-highlighting","telegram-bot"],"created_at":"2024-08-03T17:01:07.282Z","updated_at":"2025-05-01T08:35:29.812Z","avatar_url":"https://github.com/dcdunkan.png","language":"TypeScript","readme":"# Syntax Highlighter Bot\n\n\u003e Source code of [@syntaxybot](https://telegram.me/syntaxybot).\n\nInspired by\n[Piterden/syntax-highlighter-bot](https://github.com/Piterden/syntax-highlighter-bot).\n\nMinimal syntax highlighting bot for Telegram. Use it in private chats or add to\ngroup chats. Send text inside three backticks, or any message containing `pre`\nor multiline `code` entities, and the bot will reply you with syntax highlighted\nimages of that piece of code. Useful in Development groups.\n\n**Try the running bot here:\n[Syntax Highlighter Bot](https://telegram.me/syntaxybot) 🚀**\n\nWritten in [TypeScript](https://typescriptlang.org) and\n[grammY](https://grammy.dev/) and runs on [Deno](https://deno.land/).\n\n- [Built Using](#built-using)\n- [Features (and usage)](#features)\n- [Setup › Running Locally](#running-locally)\n- [Setup › Deploy to Deno Deploy](#deploy-to-deno-deploy)\n- [Setup › Environment Variables](#environment-variables)\n\n## Built Using\n\nThanks to these tools and libraries.\n\n1. [highlight.js][hljs] — Syntax highlighting for the Web. Behind-the-scenes of\n   this bot.\n2. [svg2png-wasm](https://github.com/ssssota/svg2png-wasm) — SVG to PNG\n   converter JS library made with WASM + resvg (no native dependencies). Used\n   for generating PNG images from custom made SVG.\n3. [grammY](https://grammy.dev) — The Telegram Bot Framework.\n4. [Deta.sh Base](https://deta.sh) — Free and unlimited Cloud Database service.\n\n\u003e puppeteer had a great place in the history of most of the syntax highlighter\n\u003e bots including this one. So, thank you. (Since v0.5.0 we don't use it\n\u003e anymore).\n\u003e\n\u003e ~~[Puppeteer](https://pptr.dev) — Puppeteer is a library which provides a\n\u003e high-level API to control Chrome, Chromium, or Firefox Nightly over the\n\u003e DevTools Protocol. Also a core part of this bot, used for generating syntax\n\u003e highlighted images.~~\n\u003e\n\u003e You can still access the puppeteer edition from the\n\u003e [puppeteer branch](https://github.com/dcdunkan/syntax-highlighter-bot/tree/puppeteer)\n\u003e and host it if you want to - (not maintained)\n\n## Features\n\n### Syntax Highlighting\n\n**Syntax Highlighting** for almost 200 languages with automatic language\ndetection - power of [highlight.js][hljs]!\n\n\u003ca id=\"language-detection\" href=\"#language-detection\"\u003e\u003c/a\u003e **Language\nDetection**: Tries to detect and use the detected language for more accurate\nresults.\n\n- `bot.ts \u003ccode\u003e` - Detects \u003csamp\u003ets\u003c/samp\u003e.\n- `ts \u003ccode\u003e` - Detects \u003csamp\u003ets\u003c/samp\u003e.\n- `\u003ccode\u003e` - Auto detection by [highlight.js][hljs].\n\nNOTE: The `\u003ccode\u003e` ~~should be a \u003csamp\u003epre\u003c/samp\u003e formatted code block~~ could\nbe a \u003csamp\u003epre\u003c/samp\u003e entity formatted code block, or a multiline\n\u003csamp\u003ecode\u003c/samp\u003e entity.\n\n### 🎨 Customization\n\n\u003ca id=\"custom-theming\" href=\"#custom-theming\"\u003e\u003c/a\u003e **Custom theming** for the\nimages. Use the \u003csamp\u003e/theme\u003c/samp\u003e command to set any theme from\n[this list](https://telegra.ph/Themes---Syntax-Highlighter-Bot-04-14). See\nthemes in action [here](https://highlightjs.org/static/demo/).\n\n\u003ca id=\"multiple-fonts\" href=\"#multiple-fonts\"\u003e\u003c/a\u003e **Multiple fonts** support.\nSee the \u003csamp\u003e/font\u003c/samp\u003e command in chat for the list of available fonts. Add\na font that you like by putting them in the [assets/fonts/](assets/fonts/) and\nopening a PR.\n\n\u003ca id=\"as-documents\" href=\"#as-documents\"\u003e\u003c/a\u003e **Send images as documents**.\nSometimes long code might make the image blurry due to the default Telegram\nimage compression. Sending them as documents fixes the issue. Use either\n\u003csamp\u003e/as_doc\u003c/samp\u003e or\n\u003csamp\u003e/as_document\u003c/samp\u003e command.\n\n### Better User Experience\n\n\u003ca id=\"forced-highlighting\" href=\"#forced-highlighting\"\u003e\u003c/a\u003e **Forced\nHighlighting**: Replying\n\u003csamp\u003e/highlight\u003c/samp\u003e or\n\u003csamp\u003e/hl\u003c/samp\u003e to a message containing text or caption, will\n\n- check for `pre` and `code` (multiline) entities and if there is any, only\n  highlights those as it normally do. Useful if the original message was edited\n  later.\n- If no `pre` or `code` (multiline) entities were found, highlights the whole\n  message. Useful if you forgot to format them before sending.\n\n\u003ch4 id=\"forced-highlighting-optional-args\" href=\"#forced-highlighting-optional-args\"\u003eOptional Arguments\u003c/h4\u003e\n\nYou can optionally pass arguments separated by commas or white spaces. The\naccepted arguments are integers corresponding to the position of the\n`pre`/`code` entity in the message. Starting from 1. See the example below.\n\nPassing `w` or `no-wrap`, or `nw` will highlight the text without wrapping it.\nThe image will scale to the maximum content length. It is useful when\nhighlighting some terminal logs, etc.\n\n\u003e Introduced in \u003ckbd\u003ev0.4.0\u003c/kbd\u003e\n\nYou can also pass any of `0`, `full`, `f` to get the whole message highlighted.\n(why?: If you ever need to highlight the full message which contains\n`pre`/`code` entities).\n\nTake this message as an example:\n\n```\nLorem ipsum \u003ccode (inline)\u003e dolor sit amet.\n\n\u003ccode (multi line)\u003e\n\nNunc in ligula vehicula quam efficitur vehicula at lacinia erat.\n\n\u003cpre\u003e\n```\n\nNow, replying,\n\n\u003e **NOTE**: \u003csamp\u003e/hl\u003c/samp\u003e is the same as\n\u003e \u003csamp\u003e/highlight\u003c/samp\u003e. It's just a short form.\n\n- `/hl` will highlight `\u003ccode (multi line)\u003e` and `\u003cpre\u003e` (Default).\n- `/hl 1` will only highlight the `\u003ccode (inline)\u003e`.\n- `/hl 2` will only highlight the `\u003ccode (multi line)\u003e`.\n- `/hl 3` will only highlight the `\u003cpre\u003e`.\n- `/hl 1 3` will highlight both `\u003ccode (inline)\u003e` and `\u003cpre\u003e`.\n- `/hl 0` or `/hl f` or `/hl full` will highlight the whole message.\n\n**NOTE**: `/hl 0 1` only highlights the full message; not both full message and\n1st `pre`/`code` entity.\n\n\u003ca id=\"toggle-auto-shl\" href=\"#toggle-auto-shl\"\u003e\u003c/a\u003e **Toggle Automatic Syntax\nHighlighting**: You can disable auto syntax highlighting by using the\n\u003csamp\u003e/toggle_auto_hl\u003c/samp\u003e command. (Use the same command to re-enable it).\nYou don't always need the bot to highlight even the small codeblocks. So, when\nyou need the highlighting, you can force it to highlight the message/code\nblocks. Checkout the [\"Forced Highlighting\"](#forced-highlighting) feature.\n\n\u003e Introduced in \u003ckbd\u003ev0.3.0\u003c/kbd\u003e • See\n\u003e [grammyjs#57178](https://t.me/grammyjs/57178).\n\n\u003ca id=\"stats\" href=\"#stats\"\u003e\u003c/a\u003e **Stats**: Not a very useful feature, I know.\nUse\n\u003csamp\u003e/stats\u003c/samp\u003e command to find how many times the bot has sent syntax\nhighlighted images for you.\n\n### \"Maybe\" features that I'd like to add if possible.\n\n- [ ] Highlight only if the code block contains more than \u003cb\u003e\u003csamp\u003ex\u003c/samp\u003e\n      number of characters\u003c/b\u003e. It would be a mess if someone use three\n      backticks instead of one backtick, even for a single monospace word.\n\n- [ ] \u003cb\u003eAutomatically toggle \"Send as Document\" mode\u003c/b\u003e if there is more than\n      \u003csamp\u003ex\u003c/samp\u003e number of characters.\n\n- [x] \u003cb\u003eNo puppeteer.\u003c/b\u003e Highlighting without using puppeteer. (The most\n      wanted feature). This was done in \u003ckbd\u003ev0.5.0\u003c/kbd\u003e by using an\n      implementation which creates a SVG and transform it into PNG... blah blah.\n\n- [x] \u003cb\u003eForced \u003csamp\u003e/highlight\u003c/samp\u003eing\u003c/b\u003e by replying to a message - if the\n      message contains pre code blocks, highlight them in the usual way. If not,\n      highlight the whole message.\n\n## Setup\n\n### Running Locally\n\nMake sure you have installed [Deno CLI](https://deno.land/).\n\nClone the repository.\n\n```bash\ngit clone https://github.com/dcdunkan/syntax-highlighter-bot.git\n```\n\nGo to to the cloned repository folder. Create a `.env` file and set\n[environment variables](#environment-variables) like in\n[example.env](example.env).\n\nRun the bot using the command below.\n\n```bash\ndeno run --allow-net --allow-env --allow-read local.ts\n```\n\n**Required permissions**\n\n- \u003csamp\u003e--allow-net\u003c/samp\u003e - To communicate with Telegram servers and receive\n  updates.\n- \u003csamp\u003e--allow-env\u003c/samp\u003e - To access environment variables.\n- \u003csamp\u003e--allow-read\u003c/samp\u003e - To read [translations](locales),\n  [styles](assets/styles/), [fonts](assets/fonts/) and\n  \u003csamp\u003e.env\u003c/samp\u003e file.\n\nIf everything is done correct, you should see \"(Username) started\" in your\nconsole.\n\n### Deploy to Deno Deploy\n\nThe working bot, [@syntaxybot](https://telegram.me/syntaxybot) is currently\ndeployed on [Deno Deploy](https://deno.com/deploy) free account. It's pretty\neasy to setup.\n\nClick\n[here](https://dash.deno.com/new?url=https://raw.githubusercontent.com/dcdunkan/syntax-highlighter-bot/main/main.ts\u0026env=BOT_TOKEN,DETA_KEY)\nto deploy to Deno Deploy.\n\n\u003e If you're having issues with deploying using the above link, try forking this\n\u003e repository and deploying from [Deno Deploy Dashboard](https://dash.deno.com/)\n\u003e by connecting to the forked repository.\n\nAfter deploying you will get a link to your application, in the format\n`https://\u003cappname\u003e.deno.dev`.\n\nOpen browser and go to the link down below.\n\n- Replace the `\u003cBOT_TOKEN\u003e` with your `BOT_TOKEN`.\n- Replace `\u003cAPP_URL\u003e` with the link to your application.\n\n```\nhttps://api.telegram.org/bot\u003cBOT_TOKEN\u003e/setWebhook?url=\u003cAPP_URL\u003e/\u003cBOT_TOKEN\u003e\u0026drop_pending_updates=true\n```\n\nThis will set the bot's webhook to the deployed application, so Telegram will\nsend updates there and it will be able to handle them there.\n\n## Environment Variables\n\n| Variable    | Required? | Description                                                                      |\n| ----------- | --------- | -------------------------------------------------------------------------------- |\n| `BOT_TOKEN` | **Yes.**  | The API token of the Bot. Chat with https://t.me/BotFather to get one.           |\n| `DETA_KEY`  | **Yes.**  | Project Key of Deta.sh Project. Sign up and create a project at https://deta.sh. |\n\n## Translating\n\nIf you like to translate this bot into your language, please follow\n[the English translation file](locales/en.ftl). This project uses\n[Fluent](https://projectfluent.org) for localization.\n\n## Contributing\n\nFeel free to contribute! And if you are having issues or if you want suggest\nsomething, please open an issue here:\n[dcdunkan/syntax-highlighter-bot/issues](https://github.com/dcdunkan/syntax-highlighter-bot/issues).\nOr, open a [PQ](https://telegram.me/grammyjs/34358)!\n\n### \u003ch3 align=\"center\"\u003e2 [🦕](LICENSE) 22\u003c/h3\u003e\n\n[hljs]: https://highlightjs.org\n","funding_links":[],"categories":["Bots"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcdunkan%2Fsyntax-highlighter-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcdunkan%2Fsyntax-highlighter-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcdunkan%2Fsyntax-highlighter-bot/lists"}