ream88

ream88

Use mix format for arbitrary HTML files

I really like the formatter, was one of the best additions to the Elixir code base ever, and with the support for .heex files, it became my defacto standard formatter. My question now as I tinkered with raw HTML, is there a way to formatted raw (valid) HTML? Running mix format test.html just does nothing. I guess this happens as the formatter does not know about heex files without the proper plugin Phoenix.LiveView.HTMLFormatter, but introducing the plugin also requires me to have a mix project :disappointed_face:

Any suggestions?

First Post!

hubertlepicki

hubertlepicki

did you try renaming the filename to test.heex, running the formatter and then renaming it back to test.html ?

Most Liked

wojtekmach

wojtekmach

Hex Core Team

Formatters follow this contract mix format — Mix v1.20.2

I think you can write a custom formatter that mostly delegates to the Phoenix one (untested):

defmodule HTMLFormatter do
  @behaviour Mix.Tasks.Format

  @impl true
  def features(_options) do
    [sigils: [:H], extensions: [".heex", ".html"]]
  end

  @impl true
  defdelegate format(source, options), to: Phoenix.LiveView.HTMLFormatter
end

edit: oh, if you’d rather not need to have a Mix project, then it might be pretty tricky.

Last Post!

dimitarvp

dimitarvp

Maybe a single .exs file and Mix.install?

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement