emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: meditans@gmail.com
To: emacs-orgmode@gnu.org
Subject: Inline code syntax highlighting
Date: Sun, 21 Feb 2016 15:11:34 +0000	[thread overview]
Message-ID: <94eb2c071b6cc4b5b7052c4921a6@google.com> (raw)

[-- 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 --]

             reply	other threads:[~2016-02-21 15:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-21 15:11 meditans [this message]
2016-02-22  8:32 ` Inline code syntax highlighting Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94eb2c071b6cc4b5b7052c4921a6@google.com \
    --to=meditans@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).