Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighting other languages inside of HEREDOC's #64

Open
balupton opened this issue Jul 27, 2023 · 9 comments
Open

Highlighting other languages inside of HEREDOC's #64

balupton opened this issue Jul 27, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@balupton
Copy link

The code with a problem is:

https://github.com/discourse/discourse_docker/blob/313f86feffe996349ec83877ccc57f6e12849446/launcher#L348-L368

#!/usr/bin/env bash

read -r -d '' env_ruby << 'RUBY'
    require 'yaml'

    input=STDIN.readlines.join
    # default to UTF-8 for the dbs sake
    env = {'LANG' => 'en_US.UTF-8'}
    input.split('_FILE_SEPERATOR_').each do |yml|
       yml.strip!
       begin
         env.merge!(YAML.load(yml)['env'] || {})
       rescue Psych::SyntaxError => e
        puts e
        puts "*ERROR."
       rescue => e
        puts yml
        p e
       end
    end
    env.each{|k,v| puts "*ERROR." if v.is_a?(Hash)}
    puts env.map{|k,v| "-e\n#{k}=#{v}" }.join("\n")
RUBY

It looks like:

image

It should look like:

https://github.com/discourse/discourse_docker/blob/313f86feffe996349ec83877ccc57f6e12849446/launcher#L348-L368

image

Suggestion

Instead of simply using EOF one should be able to use a language identifier, such as RUBY, JAVASCRIPT, TYPESCRIPT, etc, to highlighting the contents inside the heredoc as the language.

For myself that will provide a much better experience for pieces of code like:
https://github.com/bevry/dorothy/blob/b467c8e2ecedadb5cbc41c1c778b420a91c60454/commands/brew-installed#L119-L162

Which is typescript code being sent to deno

@jeff-hykin jeff-hykin added the enhancement New feature or request label Jul 28, 2023
@jeff-hykin
Copy link
Owner

I agree it would be nice, I do a lot of heredocs like this. I've also embedded nested languages like this in other syntaxes. It's not the easiest thing to do right, but I'll see what I can do, it might take me a bit to get around to implementing it. It must be done for every language manually.

Also it's always nice to meet another Deno developer 👋

@balupton
Copy link
Author

Good to hear, take your time.

PS. If you can, you should activate GitHub Sponsors, I try to sponsor everything I use at $1/month (under the belief that if everyone does so too, then paying it forward would also pay the bills).

@balupton
Copy link
Author

While it isn't much, I've posted a $20USD bounty for this:
https://app.bountysource.com/issues/123759829-syntax-highlighting-of-heredoc-statements

@macwarriorwow
Copy link

What editor are you using ?

@balupton
Copy link
Author

vscode

@makeasnek
Copy link

makeasnek commented Aug 25, 2023

Please do not use bountysource. Many devs have had trouble getting paid there. You can check out this lemmy community as an alternative https://lemmy.ml/c/bugbounties

For statements from devs who have been unable to cash out from bountysource see:
https://github.com/bountysource/core/issues

@balupton
Copy link
Author

balupton commented Aug 25, 2023

@makeasnek thanks for the heads up, I've submitted disputes to paypal — any thoughts on https://www.gitcoin.co and https://fundrequest.io/requests?phase=open - never heard of lemmy before.

/ref bountysource/core#1586

@makeasnek
Copy link

Lemmy is like reddit but it's OSS and federated. Gitcoin no longer does bounties, only "hackathons" unfortunately. I haven't used fundrequest but looks interesting.

@jeff-hykin
Copy link
Owner

Some progress; the example now has a string.quoted.heredoc.no-indent.RUBY tag instead of just string.quoted.heredoc.no-indent. And this works for any language/delimiter.

So, now, anyone can make a VS Code extension that targets, for example string.quoted.heredoc.no-indent.RUBY and have that section be highlighted with the grammar of their choice (ex: the ruby grammar).

@jeff-hykin jeff-hykin changed the title Syntax highlighting of HEREDOC statements Highlighting other languages inside of HEREDOC's Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants