Hi all,

I'm writing some Haskell code in a .org blog post which I will export to HTML using org-publish . I'd like to inline some haskell code in the text, and I can do that either using the marker ~...~ or the explicit block src_haskell[exports: code]{...} . I'd like to have the notational convenience of the former while retaining the syntax highlighting the latter provides. Here it is what I tried:


1 Tweaking the variable org-html-text-markup-alist


in particular the code correspondence, which by default is <code>%s</code> . This, while easy, doesn't get me syntax highlighting, and so it's not sufficiently good for my purposes.


2 Using org-export-before-processing-hook


to do some preprocessing, like:


(defun convert-code (backend)
"Changes the code marked with =...= to code marked with src_haskell[:exports code]{...}"
  (replace-regexp "~\\([^~]+?\\)~" "src_haskell[:exports code]{\\1}"))

(add-hook 'org-export-before-processing-hook 'convert-code)


Unfortunately, this use of regexp feels hacky, messes up the formatting when I try to have some haskell code as the text for a link (for the presence of ] ), and gets exported as:


<code class="src src-haskell"><span style="color: #ba2f59; font-weight: bold;">stuff</span>
</code>


with a newline before </code> , which is read as an (unwanted) space in HTML.


3 Creating a custom exporter


This should work, but I got stuck working on it (I just began learning elisp). Here is a starting point, I'd appreciate some help:


(defun my-haskell-code (code contents info)
"Changes the code marked with =...= to code marked with src_haskell[:exports code]{...}" (format "%s" (org-element-normalize-string (org-export-format-code-default code info))))

(org-export-define-derived-backend 'my-hask 'html
  :translate-alist '((code . my-haskell-code)))


In conclusion, do you have any tips on how to get syntax highlighting for ~...~ blocks?

Best regards

Carlo


Carlo


Reply via email to