telegramdesktop / tdesktop

Telegram Desktop messaging app
https://desktop.telegram.org/
Other
25.88k stars 5.13k forks source link

Automatically Syntax-Highlight received Code #250

Closed leolabs closed 10 months ago

leolabs commented 9 years ago

It would be great if we were able to send code snippets via Telegram in a way that is nicely readable by the receiver. I'm chatting a lot with other developers and often, I feel the need for such a feature.

Related issue on the Telegram bug tracker: https://bugs.telegram.org/c/824

Piterden commented 7 years ago

Not our problem :)

Whom do you mean, @arenaq ? I think, it is general problem. At the first it is the problem of Pavel Durov. But I agreed, this is offtop for here.

arenaq commented 7 years ago

@Piterden I meant ppl that won't be affected by Telegram blocked in Russia. Was more like a joke, really.

gogl92 commented 7 years ago

Maybe something like this could be easier to implement instead of trying to do code detection slackcode

Piterden commented 7 years ago

Slack has the worst implementation of highlighting I ever seen. The best implementation is here, on GitHub.

ygbr commented 7 years ago

Still better than nothing, which is what we currently have on Telegram

Piterden commented 7 years ago

Does Telegram support any type of modal dialog?

rockymontana commented 7 years ago

Yes. It does. :-) image

EDIT: Sorry, I didn't have any larger file.

Piterden commented 7 years ago

Btw, guys. I had avoid that problem with the ST3 and its Export HTML plugin. I even have highlighting with my own colors. Gallery.vue.html.zip You need to unpack and open it in browser then.

PS Especially for paranoiacs, it looks like: image

rockymontana commented 7 years ago
    You shouldn’t share files like that.Why don’t you just create a repo and show the source instead? Otherwise noone have a clue what they’re downloading and opening.

    Get Outlook for iOS

On Wed, Aug 30, 2017 at 3:22 AM +0200, "Denis Efremov" notifications@github.com wrote:

Btw, guys. I had avoid that problem with the ST3 and its Export HTML plugin. I even have highlighting with my own colors.

Gallery.vue.html.zip

You need to unpack and open it in browser then.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Piterden commented 7 years ago

@rockymontana Bro, you shouldn't leave comments like this ^ :rofl:

stek29 commented 7 years ago

That's completely unrelated to TDesktop and to syntax highlighting.

UPD: deleting @gogl92's comment to avoid misinformation and confusion.

Piterden commented 7 years ago

My tg don't have this ^

Piterden commented 6 years ago

https://github.com/Piterden/syntax-highlighter-bot https://t.me/cris_highlight_bot

Piterden commented 6 years ago

image

JulianAtlas commented 6 years ago

Code highlighting, and extend the 51 character limit per line please!

lolgab commented 6 years ago

```languageName code ``` syntax like markdown would be perfect... No need to detect the language (which is not only difficult but error prone)..

for example: ```java public class MyClass {   public static void main(String[] args) {     System.out.println("Hello world");   } } ``` should give

public class MyClass {
  public static void main(String[] args) {
    System.out.println("Hello world");
  }
}

and ```python def mysum(x, y):    return x + y ``` should give

def mysum(x, y):
   return x + y
shavidzet commented 6 years ago

Is any news about code highlighting? Does someone work on this feature?

@Piterden it looks your bot doesn't work as it should be

Piterden commented 6 years ago

@ShavidzeT, ya it should be rewritten, I had stopped it now.

PS play while in chess...

shavidzet commented 6 years ago

@Piterden I see that it's useful feature for telegram, if you looking for maintainers, I can help. I'll ping you on your email.

AndydeCleyre commented 6 years ago

As a workaround, I made https://t.me/colorcodebot . It's susceptible to #522 problems.

Piterden commented 6 years ago

Nice bot, @AndydeCleyre, but I personally hate solarized :joy_cat:

Do you have sources for that your bot? Maybe add there a theme selection functionality from my one?

Piterden commented 6 years ago

You know, we could also add there a question about a preferred file format. @AndydeCleyre

kirsan31 commented 6 years ago

Sorry guys your work are great, but imho, this bots are nearly useless :( Code as img already a big compromise, and more easily done via screenshot. Code as html is good, but telegram can't render it => what profit from bot, as many sites offer same functionality? I made some research on this question a time ago, and think that best solution it's implement a html render in telegram. But looking into code, I understand that for me it's hard to achieve, even for personal use :(

AndydeCleyre commented 6 years ago

@kirsan31 I'm hoping for an in-app solution as well. The benefits of the bot for me:

Piterden commented 6 years ago

Guys, we need the instant view of highlighted code!!!

The bot can share statically the prepared for an instant view HTML files.

gogl92 commented 6 years ago

I always wanted the idea of having a in-app browser inside tdesktop, I made this concepts http://telegra.ph/Telegram-Desktop-In-App-Browser-09-04

kirsan31 commented 6 years ago

@AndydeCleyre Agreed.

quick viewing, especially when associating local html files with a simple renderer

Especially directly in Telegram ;) Back to your bot, theme selection functionality from @Piterden will be great (don't like black theme in c# :) )!

@Piterden

Guys, we need the instant view of highlighted code!!! The bot can share statically the prepared for an instant view HTML files.

If it's possible, I think this is the right direction. But we have no instant view support in tdesktop #3492, and as I understand, instant view is not in html :(

AndydeCleyre commented 6 years ago

@kirsan31 I invite you to take further colorcodebot discussion to its own issues page, and let me know which of these you would appreciate included: theme previews

Piterden commented 6 years ago

@AndydeCleyre did you see this stuff? https://github.com/revolunet/sublimetext-html-export

IMHO it has better render, than your...

therecluse26 commented 6 years ago

Puhleaaase add github-like code highlighting. That would be amazing.

kirsan31 commented 6 years ago

If anyone interested, my workaround for this problem:

Preview: ![example](https://github.com/kirsan31/tdesktop/raw/master/docs/assets/html.gif?raw=true)
shavidzet commented 6 years ago

@kirsan31 your approach looks better but we still need markdown support 😄

olleharstedt commented 6 years ago

Bump.

Piterden commented 6 years ago

@kirsan31 so does your approach need html key for c++ code?

kirsan31 commented 6 years ago

@Piterden I like your idea with html file creating by bot. So I thinked, if I can create and send such file on the fly in telegram (if I have html markup in clipboard)... In my mod you need to type ```html and then paste your html code. Yes, it's not so good approach, but we are using it along with sending files from bots.

AndydeCleyre commented 6 years ago

@olleharstedt can I ask if you've tried my bot? https://t.me/colorcodebot

Note that as a convenience, you can invoke it inline to bring up a direct chat button

adrianopol commented 6 years ago

Totally disagree with this feature. Telegram is for chatting and sharing media, it is not a developer-specific tool. For code sharing use Slack, Mattermost, or whatever.

  1. Any unnecessary complexity implies increased RAM consumption, more bugs in code, slower interface rendering.
  2. All platform client implementations are not very suitable for sharing code due to a very limited line length (up to only 50 symbols).
  3. If the code (regardless of language) needs highlighting to be understood, it's the ugly code and needs to be rewritten. :)
arenaq commented 6 years ago

@adrianopol disagree with you completely.

How is being a developer relevant for Telegram usage? Developers are users too and they want to chat and share as well as others. When I chat with my friends who happens to be developers as well, I don't want to invite then to different platform just because I want to send them a small code snippet.

By the way, how do you know what is Telegram for? By the same logic you could have argued, before introducing Telegram calls, that it was meant only for texting and therefore ppl should go to Skype, Discord, or whatever. Are you saying that you won't accept any change at all?

  1. Theoretically, yes. In practice, it is insignificant to features like mentioned calls. I would even argue that it would not consumed any more RAM than before. Maybe you meant CPU or HDD, but RAM would not suffer at all (if any, we are talking about few kB for a few seconds). For comparison, already mentioned calls feature requires tens of MBs of RAM.
  2. Not sure, where did you take that number. The line on my platform shows 71 chars. But, you argue that the implementation are not suitable. I would argue that since there is a demand it means that people are using it already, they just want syntax highlight (which have nothing to do with line breaks).
  3. Are you saying that syntax highlighting is useless and that IDE's are only supporting it cause of ugly code? It is not about "if" it will be understood, but how. I believe that if you would be looking at it for a while, you would figure it out eventually, but wouldn't it be nice to get that right away? As well as if all messages would be mirrored upside down, it would still be understood, but it would not be as pleasant reading, right?
gogl92 commented 6 years ago

@adrianopol I think that we do not need "Automatically Syntax-Highlight" we need a "Syntax-Highlight Snippet" that when you need you can Highlight the code in a message.

Piterden commented 6 years ago
  1. If the code (regardless of language) needs highlighting to be understood, it's the ugly code and needs to be rewritten. :)

Why do you highlight your chat then? image

Oh you have ugly chat and it needs to be rewritten!

Also I propose you to not use the monospace font, because a good code must be readable even in Arial.

arenaq commented 6 years ago

@adrianopol I believe it is just misleading title. If you read what author of this topic wrote, it seems to me that it is very similar to what you are proposing.

It would be great if we were able to send code snippets via Telegram in a way that is nicely readable by the receiver. I'm chatting a lot with other developers and often, I feel the need for such a feature.

adrianopol commented 6 years ago

@arenaq,

How is being a developer relevant for Telegram usage?

Because this feature is useless for everyone except SW developers. I am not about discarding any improvements or features at all. My message was about a niche feature. Suppose photographers asking for a .psd file previewer, mathematicians asking for LaTeX support, and so on.

Support for calls is a marketing feature, and it is meaningful for all users, so this is not a valid comparison.

Any software product is always a compromise between [a number of features expected by users] and [a number of bugs, fast UI reaction, and a good interrelation between existing features].

The key point is that small code snippets are enough readable without highlighting, and the large ones suffer from size limitation, making them absolutely unreadable (regardless of any highlighting).

it seems to me that it is very similar to what you are proposing

Well, talking about a separate media type (like images, videos) with its own viewer is a more reasonable way, I suppose. But most examples and suggestions are about inline support.

Piterden commented 6 years ago

Try my bot @adrianopol @cris_highlight_bot

Compare these two ways.

horizontalWords () {
  const words = []
  let row = 1

  for (row; row <= this.width; row++) {
    const rowBlankCells = this.blanks
      .filter((cell) => Number(cell.split(':')[1]) === row)
      .map((cell) => Number(cell.split(':')[0]))

    if (rowBlankCells.length > 0) {
      let i = 1
      const cols = new Array(this.height).fill(0).map((col) => i++)

      if (cols) {
        `:${cols.join('::')}:`
          .split(new RegExp(`:${rowBlankCells.join(':|:')}:`))
          .filter((word) => {
            const match = word.match(/:\d+:/g)

            return match ? match.length > 1 : false
          })
          .forEach((word) => {
            const match = word.match(/:\d+:/g)
            const length = match ? match.length : 0

            words.push({
              x: Number(word.match(/^:(\d+)/)[1]),
              y: row,
              type: 'horizontal',
              length,
              question: '',
            })
          })
      }
    } else {
      words.push({
        x: 1,
        y: row,
        type: 'horizontal',
        length: this.width,
        question: '',
      })
    }
  }

  return words
},

image

arenaq commented 6 years ago

@adrianopol

Because this feature is useless for everyone except SW developers.

Support for calls is a marketing feature, and it is meaningful for all users

I do not believe it is (to both).

Suppose photographers asking for a .psd file previewer, mathematicians asking for LaTeX support, and so on.

I wouldn't mind. If there will be reasonable demand for it and wouldn't affect other users, why not?

Yes, you are right, it is a compromise, but this is a tiny feature that would not impact performance. In regards of bugs, UI reaction time - this really is negligible, since there are many optimized libraries that can do that.

I would understand the argument about too many options in UI for other users, but since this would be sort of hidden feature, not even that would apply.

And I do believe that in case of snippets, size does not matter. Should be highlighted even when it's just one line :)

PS: I am not talking about parsing all the messages that user type and looking for code, but rather introduce a new syntax for formatting (as now with "`" character, as markdown has for example)

Piterden commented 6 years ago

Just like here on GitHub would be nice. @arenaq

```c++
#include <iostream>
using namespace std;

int main()
{    
    int number;

    cout << "Enter an integer: ";
    cin >> number;

    cout << "You entered " << number;    
    return 0;
}
#include <iostream>
using namespace std;

int main()
{    
    int number;

    cout << "Enter an integer: ";
    cin >> number;

    cout << "You entered " << number;    
    return 0;
}

It is enough easy

arenaq commented 6 years ago

@Piterden yep, that's exactly what I had in mind 👍

simonneutert commented 4 years ago

yes, please 👍

danwalmsley commented 4 years ago

Im from a group of devs and we have left gitter for telegram... this is the only feature we miss.

Please implement :)

s-barannikov commented 4 years ago

Any updates?

RusseII commented 4 years ago

image

https://core.telegram.org/bots/api#markdownv2-style

The telegram bot docs has an example of this with python, but it does NOTHING different.