From mboxrd@z Thu Jan 1 00:00:00 1970 From: meditans@gmail.com Subject: Inline code syntax highlighting Date: Sun, 21 Feb 2016 15:11:34 +0000 Message-ID: <94eb2c071b6cc4b5b7052c4921a6@google.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=94eb2c071b6cc4b5a1052c4921a3 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXVfc-0006cs-Gv for emacs-orgmode@gnu.org; Sun, 21 Feb 2016 10:11:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXVfb-0007Gi-Al for emacs-orgmode@gnu.org; Sun, 21 Feb 2016 10:11:36 -0500 Received: from mail-yw0-x248.google.com ([2607:f8b0:4002:c05::248]:35109) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXVfb-0007GT-2a for emacs-orgmode@gnu.org; Sun, 21 Feb 2016 10:11:35 -0500 Received: by mail-yw0-x248.google.com with SMTP id b66so197867266ywf.2 for ; Sun, 21 Feb 2016 07:11:34 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --94eb2c071b6cc4b5a1052c4921a3 Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes 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 %s . 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: stuff with a newline before , 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 --94eb2c071b6cc4b5a1052c4921a3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

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 notation= al 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 =3D...=3D t=
o code marked with src_haskell[:exports code]{...}"
  (replace-regexp "~\=
\([^~]+?\\)~" "src_haskell[:exports code]{\\1}"))

(add-hook 'org-export-before-process=
ing-hook 'convert-code)

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

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

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

3 Creating = a custom exporter

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

(defun my-haskell-code (code contents info)
  "Changes the code marked with =3D...=3D t=
o code marked with src_haskell[:exports code]{...}"
  (format "%s" (org-element-norma=
lize-string (org-export-format-code-=
default code info))))

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

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

Best regards

Carlo

Carlo

--94eb2c071b6cc4b5a1052c4921a3--