teesloane / firn

Org Mode Static Site Generator
Eclipse Public License 1.0
324 stars 24 forks source link

export special blocks #68

Closed holtzermann17 closed 3 years ago

holtzermann17 commented 3 years ago

In regular Org mode, it’s possible to define your own blocks which are then exported to a div with the given block name, e.g.,

#+begin_monoblock
This is some text.
#+end_monoblock

turns into

<div class="monoblock" id="org6f3fd59">
<p>
This is some text.
</p>

</div>

The relevant code is in org-html-special-block in ox-html.el. With Firn, it seems these blocks aren’t currently exported, but they're confirmed to be recognized in the Orgize JSON export. Could they be enabled here?

holtzermann17 commented 3 years ago

Note, as a further special request:

For my use case, I'd actually want to export the blocks to span rather than div, although the standard Org Mode exporter, ox-html.el, would always export to div. I wonder what how this extra level of customization might be arranged?

teesloane commented 3 years ago

Gotcha, thanks for the update. I think handling for special-blocks should be simple. It will be like the example ox-hugo, but will render the blocktype as a class rather than an id. (although, it seems like there is an opportunity for a fair bit of "expansability" with allowing people to determine how different blocks be parsed at runtime; I will have to think about it for a future release).

Do you mind sharing why it should be a span? Could you not use a div and style the class of it to resemble a span?

holtzermann17 commented 3 years ago

Ah, you're right, it can all be changed with CSS!

As you already know [but I didn't! -JC] the difference between a <div> and a <span> is just that one defaults to display:block; and the other to display:inline;. To make one act as the other, just set the display style to the other type. (source)

holtzermann17 commented 3 years ago

This brief update is beyond the scope of Firn but in my attempt to mock up a preliminary solution by hand, I couldn't get the special block to display properly with display:inline;

https://gist.github.com/holtzermann17/c907d070cff649e7c9c5665aa7cf325e

holtzermann17 commented 3 years ago

OK, I figured out why it isn't working:

'display', 'position', and 'float' — interact as follows: ... if 'float' has a value other than 'none', the box is floated and 'display' is set according to the table below: Specified value Computed value
inline, table-row-group, table-column, table-column-group, table-header-group, table-footer-group, table-row, table-cell, table-caption, inline-block block

https://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo

With the upshot that my naive suggestion to use span may be the only way to go in this case!

holtzermann17 commented 3 years ago

Just to mention:

#+BEGIN_LATEX
\begin{align} \mathcal{F}(a) &=
\frac{1}{2\pi i}\oint_\gamma \frac{f(z)}{z - a}\,dz\\
\int_D (\nabla\cdot \mathcal{F})\,dV &=\int_{\partial D}\mathcal{F}\cdot n\, dS \end{align}
#+END_LATEX

and such-like represent a special case of the above. This doesn't fully solve the "LaTeX environment" part of #56 (because it doesn't say what to do with the align environment) but maybe it can be useful for something. E.g., with a translation rule that could become:

$$\begin{align} \mathcal{F}(a) &=
\frac{1}{2\pi i}\oint_\gamma \frac{f(z)}{z - a}\,dz\\
\int_D (\nabla\cdot \mathcal{F})\,dV &=\int_{\partial D}\mathcal{F}\cdot n\, dS \end{align}$$

at which point MathJaX would know what to do with it. (The author could have just written the latter expression directly, but maybe there are reasons to mark things up differently at times.)