Recently, I wanted an easy way to highlight elixir code, and I wanted to use @tmbb’s excellent Makeup library to do so, but it was annoying to get some nice visual output so I decided to create a Phoenix LiveView-powered website to help others with the same issue. Simply paste in your elixir code into the text box and it will immediately be highlighted:
EDIT: Looks like my browser handles white-space style in different way than yours.
For me all values except initial, normal and nowrap adds extra newline-like CSS behaviour. Also initial, normal, nowrap and pre-line have CSS behaviour which looks like it remove spaces at start of line.
This is not a Bug in this application. It actually exposes a bug in the Elixir lexer, which is that the \r character from windows line endings isn’t matched by the lexer. When used on windows, Elixir seems to conver \n\r into \n, but when used somewhere else it doesn’t. The problem is probably that @Eiji (and me) are sending strings from Windows which are parsed with Elixir running on a Unix system. That way, the \r character is flagged as an error (which generates the extra span tags - very annoying).
The fix seems pretty obvious, the problem is that I’m not sure on how to test it in a portable way.
@axelson I just wanted to say that I wholeheartedly approve of this demo xD I’ve meant to write something like it for a while, but I never made the time for it.
I wonder if there could be a way for the user to tag code as “looking wrong”, which would cause an email to be sent somewhere (or maybe a bot that creates a GitHub issue in the lexer’s repo?) I can see this being abused though… Maybe if it were protected by a captcha?
Even though you’re using linux, it seems like your browser is sending windows-style strings through the websocket… Is that some kind of web standard in which JS treats all strings as being windows-style? I have to look into it
I’m not sure such a fix would be a good idea. I think the Elixir lexer should be handing this input correctly, that is, it should recognize the \n\r sequence as whitespace. Unless there is something in the Elixir “standard” that says that the compiler is not meant to accept strings with windows-style endings… Is there?
As a side-note I wish there was a way to for phx-throttle to work similarly to lodash’s throttle with leading=true and trailing=true: https://lodash.com/docs/4.17.15#throttle but that should really be a separate forum topic.