elixir-makeup / makeup

Syntax highlighter for Elixir inspired by Pygments
BSD 2-Clause "Simplified" License
198 stars 33 forks source link

Output other than HTML? #3

Open NobbZ opened 7 years ago

NobbZ commented 7 years ago

Is there currently a way to put out something else than HTML? Or is there at least an easy to hook into @behaviour to write “output filters”?

I'd be very interested in trying to provide some LaTeX printer if it is currently missing.

tmbb commented 7 years ago

It is undocumented but yes, there is. Formatters aren't behaviours yet, but I'll turn them into formal behaviours in the future.

Basically, a formatter converts a flat list of tokens into a string. For the HTML formatter, that string is HTML. You can write a formatter that converts the tokens into LaTeX with no problem.

My main problem here is a design one: I'm still not sure of whether there should be a very unified interface to all formaters, or if each formatter should work in a unique way.

tmbb commented 7 years ago

Actually, a behaviour might be overkill. I'm planning on formally making the token format part of the public API, and use the metadata for possible extensions, so you should be able to weite your own formatter just by processing these tokens (which are very simple).

tmbb commented 6 years ago

@NobbZ, let's open the discussion around whether the formatter should be a behaviour or not.

The HTML formatter currently supports two output functions, one that outluts iolists and anothe that outputs binaries. This output format should be common to all formatters that produce textual output (as opposed to calls to a stateful graphics API for example).

Do you think I should formalize this as a behaviour?

OvermindDL1 commented 6 years ago

Well a binary is an iolist but not vice-versa, so iolists should be the output (especially since you can then just convert it to a binary anyway if necessary, or feed it straight to a network socket or so).

But otherwise unless the system itself needs the formatters and not the other way around, a behaviour itself is not needed, just a good API for accessing the tokens.

tmbb commented 6 years ago

Well a binary is an iolist but not vice-versa, so iolists should be the output

The function that outouts a binary just renders the iolist returned by the other function into a binary.

a behaviour itself is not needed, just a good API for accessing the tokens.

A token is just a {atom(), Map.t(), iodata()}. There isn't really much of an API xD

OvermindDL1 commented 6 years ago

The function that outouts a binary just renders the iolist returned by the other function into a binary.

You don't always want that though as keeping it as an iolist can often be faster, so it is a good base. :-)

tmbb commented 6 years ago

They's why there are TWO funcions: one if you want an iolist and another one if tou want a binary