all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Inline code syntax highlighting
@ 2016-02-21 15:11 meditans
  2016-02-22  8:32 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: meditans @ 2016-02-21 15:11 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1988 bytes --]

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



[-- Attachment #2: Type: text/html, Size: 5160 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-22  8:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-21 15:11 Inline code syntax highlighting meditans
2016-02-22  8:32 ` Nicolas Goaziou

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.