How to Use OrgCSS for Org-Exported HTML

Jan 6, 2024 | Programming

Welcome to the world of OrgCSS! This guide will help you navigate the intricacies of applying stylesheets to your Org mode exported HTML documents effectively. With easy-to-follow instructions, troubleshooting tips, and coding analogies, let’s get started!

Table of Contents

Usage

To apply the OrgCSS stylesheet to your Org documents, simply add the following setup to your org file:

##+HTML_HEAD: 

With this line included, your exported HTML will adopt the styles defined in the OrgCSS stylesheet, enhancing the presentation of your content.

Caveats

As Org mode frequently updates, the structure of the exported source code can change dramatically. Hence, I added version tags (since Org mode v9.1.4) to indicate the corresponding Org mode version to avoid conflicts.

Code Highlight

When you export your Org files to HTML, you have three options for code highlighting, controlled by the variable org-html-htmlize-output-type.

  • Inline CSS:
    (setq org-html-htmlize-output-type 'inline-css)

    This is the default setting. While it colors the code according to your current Emacs theme, it can lead to issues if your web page theme does not match, making the exported code hard to read.

  • No Highlighting:
    (setq org-html-htmlize-output-type nil)

    This disables highlighting via htmlize. You may consider using a JavaScript library like highlight.js. However, it may not support every language and requires some extra coding.

  • CSS Classes:
    (setq org-html-htmlize-output-type 'css)

    This option is my preferred choice. It assigns classes to code components, allowing for custom styling through your stylesheet. To generate CSS class names, use M-x org-html-htmlize-generate-css in your current Emacs session. Remember to avoid default styles with (setq org-html-head-include-default-style nil).

Troubleshooting

Here are some common issues you may encounter:

  • Styles not applying? Ensure that your path to the CSS file is correct in your org file’s setup.
  • Code not highlighted properly? Adjust the org-html-htmlize-output-type setting according to the above options. For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
  • HTML structure is inconsistent? Verify that you have added the version tags and are using a compatible version of Org mode.

For further reading, the CSS classes used by ox-html are documented here.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox