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

Improve formatting of ${...} #1108

Closed
kwalrath opened this issue Aug 28, 2018 · 6 comments
Closed

Improve formatting of ${...} #1108

kwalrath opened this issue Aug 28, 2018 · 6 comments
Labels
co.help-wanted Community opportunity to help documentation e2-days Can complete in < 5 days of normal, not dedicated, work infra.design Relates to the design of docs.Dart.dev infra.structure Relates to the tools that create dart.dev p3-low Valid but not urgent concern. Resolve when possible. Encourage upvote to surface.

Comments

@kwalrath
Copy link
Contributor

@mkustermann pointed out that code inside of ${...} is formatted like the rest of the string. It'd be good to format it like real code. E.g. in www.dartlang.org/articles/dart-vm/io#file-system-access, the print statement in the first code snippet looks something like this:

image

That await code (if outside of the string) would look like this:

image

This is probably a prettify issue, but it'd be really nice to fix it.

@kwalrath kwalrath added infra.structure Relates to the tools that create dart.dev p3-low Valid but not urgent concern. Resolve when possible. Encourage upvote to surface. co.help-wanted Community opportunity to help documentation infra.design Relates to the design of docs.Dart.dev e2-days Can complete in < 5 days of normal, not dedicated, work labels Jan 31, 2019
@smolck
Copy link
Contributor

smolck commented Oct 4, 2019

Maybe this could be fixed by adding some regex to src/_assets/js/vendor/code-prettify/lang-dart.js?

For example, this regex[1][2] matches things like $foo or ${<Dart code>}:

\$((\w+)|\{([^{}]+)\})

Could we add similar regex somewhere in lang-dart.js to detect string interpolation and highlight it like normal code?

[1]: Adapted from here: https://github.com/Dart-Code/Dart-Code/blob/06eaf66e9613b16e1401dd267c5597dff1524239/syntaxes/dart.json#L328.
[2]: I know almost zero regex, but it seems to work here: https://regexr.com/4m72j

@kwalrath
Copy link
Contributor Author

kwalrath commented Oct 4, 2019

I believe this would require a PR to https://github.com/google/code-prettify, but I could test the fix locally first.

@chalin how does this solution sound to you?

@chalin
Copy link
Contributor

chalin commented Oct 4, 2019

@smolck - the Dart Code reference is a good find!

@kwalrath - I agree that any updates should be submitted as a PR over https://github.com/google/code-prettify.

I see that googlearchive/code-prettify#592 hasn't been merged yet. Could we ping someone to ensure that progress is made?

Oh, we've already made local changes to vendor files -- e.g., #1624! Not what I prefer (since local changes like these run the risk of being overwritten), but it's good that I'm aware of it now.

  • ⚠️ We probably should have also added a comment to the top of vendor/code-prettify/lang-dart.js to warn the reader/maintainer that the file contains a (hopefully temporary) patch.

@smolck
Copy link
Contributor

smolck commented Oct 8, 2019

@kwalrath @chalin Is submitting a PR to code-prettify for this (assuming it works) the route we want to go?

@kwalrath
Copy link
Contributor Author

kwalrath commented Oct 8, 2019

@kwalrath @chalin Is submitting a PR to code-prettify for this (assuming it works) the route we want to go?

I think we'd want PRs both here and at code-prettify.

@parlough
Copy link
Member

parlough commented Nov 7, 2022

It looks like Rouge does this a little better, so going to close this in favor of #3846.

The final though goal though is to move to a Dart analyzer based system as tracked in #4163.

@parlough parlough closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
co.help-wanted Community opportunity to help documentation e2-days Can complete in < 5 days of normal, not dedicated, work infra.design Relates to the design of docs.Dart.dev infra.structure Relates to the tools that create dart.dev p3-low Valid but not urgent concern. Resolve when possible. Encourage upvote to surface.
Projects
None yet
Development

No branches or pull requests

4 participants