-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Format razor files #35
Comments
I've been doing a lot of Blazor recently both at work and in my personal projects and would love to see csharpier support Razor files. I think it would be perfectly acceptable to just format the long |
I think full support for razor files would be a ton of work. The RazorTemplateEngine turns a view into a csharp file with all the HTML in strings. That doesn't help at all with deciding how to format the HTML. I haven't found any way to parse a razor file in a way that lends itself to being formatted. Although I just found an class named HtmlMarkupParser that may be what I was missing. Although all of its documentation warns about how it isn't meant to be used directly. But your idea of formatting the @code blocks may be possible without a ton of effort. Assuming I can pull out just the code block and parse it with Roslyn then csharpier would be able to format it. I'll see how feasible that is. Thanks for the suggestion! |
Yeah I don't think parsing the HTML or the c# code in the HTML would be super necessary - it might even be undesirable since you're mixing two formatting paradigms. The |
The idea of supporting a basic version of blazor/razor is pretty motivating to me, but I haven't had a ton of extra time to devote to csharpier lately. Mondays are my usual day to work on it, but I am feeling sick today and having a hard time focusing. Contributions are always welcome, so feel free to take a crack at it. Where I ended up - regex is one option to try to find the code blocks, but is probably pretty error prone. I think we'd still want to use a parser, we can always leave the html portions as is and just use it to find the code blocks. I did find https://stackoverflow.com/questions/50781429/how-to-create-visual-studio-extension-for-cshtml-files which is an example of parsing razor to a syntax tree, but then realized it is for the .net framework. |
I did manage to parse a razor file, but getting to the c# code blocks requires reflection. A lot of the types needed are internal. This branch has a hacked together POC - https://github.com/belav/csharpier/compare/basic-razor |
The POC almost looks too simple...I hope it's good. Can't wait for this for razor files. |
This could help with parsing razor files - https://github.com/huntercfreeman/BlazorStudio/blob/auto-complete/Blazor.Text.Editor.Analysis.Razor.ClassLib/TextEditorRazorLexer.cs |
Any ETA on this? Our team's productivity would greatly benefit from having .razor files autoformatted. |
@belav You've probably seen it already, but there's a prettier plugin for |
@Snailedlt unfortunately I don't know that I'll be getting to this any time soon, other issues keep taking priority and I haven't had as much time to dedicate to CSharpier as of late. Every time I end up in a razor file at work I am reminded how much I'd love for CSharpier to support this. |
As Microsoft doesn't even provided a robust razor formatting solution with VS, CSharpier would be paving a new road. So respect for even starting to look into it. |
Hi @belav, texting here since I saw no other means of contacting, would a sponsorship help develop this feature? Thanks in advance! |
Hey @lukedays I appreciate the offer, but at this point the biggest problem is my lack of time to dedicate to the project. I also worry that formatting razor may be a significant effort and don't even have a good starting place for it so would hate to promise anything. |
I also need something like this because the official MS C# extension for VS Code formats my razor files so ugly. :'( |
It's not working when I put
in settings.json user settings of VSCode for |
Ideally csharpier would be able to format razor files. It appears that razor files are parsed and converted to c#. See
https://github.com/davidebbo/RoslynRazorViewEngine/blob/master/RoslynRazorViewEngine/RoslynRazorViewEngine.cs#L127
How does prettier deal with html files, react files, etc?
Should the razor formatter be a prettier plugin instead? How would it parse/format the c# code in a razor file?
The text was updated successfully, but these errors were encountered: