kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
867 stars 130 forks source link

Block in monospace; not code? #684

Closed amca01 closed 1 year ago

amca01 commented 1 year ago

This is such a simple request that I'm almost ashamed to be asking it. (Only almost ashamed, though ... ) Anyway, I have some text I'd like to set off from its surroundings. Its nature is better to be in monospace. I don't want it to be formatted as a code block, because I want to keep the colour palette (dark background) for code only. (Unless there's a way of using another colour palette for a specific example). I've set codefences = true in my config.toml file, but either ox-hugo or hugo doesn't respect the three backticks. The final html file just includes the three backticks as though they were text, and the text itself is still in the prevailing font.

I've tried using #+attr_html, and similar. For example, here's an attempt which didn't work:

#+BEGIN_EXPORT HTML
<style>
.mono text {
  font-family: monospace;
}
</style>
#+END_EXPORT
#+ATTR_HTML: :class mono
This is the text that I want to in monospace font.

I'm not sure if I should be doing this in CSS, or HTML, or a mixture. Anyway, no doubt this is trivially simple - when you know how!

kaushalmodi commented 1 year ago

Does this help?

#+begin_example
This is the text that I want to in monospace font.
#+end_example
kaushalmodi commented 1 year ago

Alternatively, you can do

#+BEGIN_EXPORT HTML
<style>
.mono text {
  font-family: monospace;
}
</style>
#+END_EXPORT
#+begin_mono
This is the text that I want to in monospace font.
#+end_mono

See https://ox-hugo.scripter.co/doc/org-special-blocks/#special-blocks--div-tags for reference.

amca01 commented 1 year ago

Thanks for both of those. However, the first just shows the text in the same dark palette of my source code: there's no visual difference between this and starting with #+begin_src and ending with #+end_src.

The second one has no effect for me.

amca01 commented 1 year ago

Here's what worked for me:

#+BEGIN_EXPORT HTML
<div style = "background-color:#AED6F1"><samp>
This is the stuff I want to have in monospace font.</samp></div>
#+END_EXPORT 

The <samp> is an HTML5 tag for representing sample output; a repacement for the now discontinued <tt> tag. And there are also <kbd>, <code> and of course <pre>.

kaushalmodi commented 1 year ago

Hello, I am closing this issue as it is resolved.