From 1f6954ce8f313139385110f68c18c17adb2723f8 Mon Sep 17 00:00:00 2001
From: Ulf Wiger <ulf@feuerlabs.com>
Date: Fri, 24 May 2013 16:28:58 +0200
Subject: [PATCH] support syntax highlighting in code blocks (see README)

---
 README.md           | 28 ++++++++++++++++++++++++++++
 doc/README.md       | 28 ++++++++++++++++++++++++++++
 doc/overview.edoc   | 21 +++++++++++++++++++++
 src/edown_xmerl.erl |  6 +++++-
 4 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index ed181d3..c22f926 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,34 @@ Example:
 
 The conversion function will fetch the current branch name from git,
 and fail if it cannot do so.
+Github customizations
+=====================
+`pre` tags are converted into github "fenced" code blocks, i.e.
+
+```
+```...'''
+```
+
+. If language-specific syntax highlighting is desired,
+this can be achieved by adding a 'lang' attribute, e.g.
+
+```
+<pre lang="erlang">
+incr(X) ->
+  %% This should be formatted with Erlang syntax highlighting
+  X + 1.
+</pre>
+```
+
+which should format like this:
+
+```erlang
+
+incr(X) ->
+  %% This should be formatted with Erlang syntax highlighting
+  X + 1.
+
+```
 
 Rebar customizations
 ====================
diff --git a/doc/README.md b/doc/README.md
index f14e1a2..5900de1 100644
--- a/doc/README.md
+++ b/doc/README.md
@@ -44,6 +44,34 @@ Example:
 
 The conversion function will fetch the current branch name from git,
 and fail if it cannot do so.
+Github customizations
+=====================
+`pre` tags are converted into github "fenced" code blocks, i.e.
+
+```
+```...'''
+```
+
+. If language-specific syntax highlighting is desired,
+this can be achieved by adding a 'lang' attribute, e.g.
+
+```
+<pre lang="erlang">
+incr(X) ->
+  %% This should be formatted with Erlang syntax highlighting
+  X + 1.
+</pre>
+```
+
+which should format like this:
+
+```erlang
+
+incr(X) ->
+  %% This should be formatted with Erlang syntax highlighting
+  X + 1.
+
+```
 
 Rebar customizations
 ====================
diff --git a/doc/overview.edoc b/doc/overview.edoc
index c9869e6..70737b0 100644
--- a/doc/overview.edoc
+++ b/doc/overview.edoc
@@ -40,6 +40,27 @@ Example:
 The conversion function will fetch the current branch name from git,
 and fail if it cannot do so.
 
+Github customizations
+=====================
+`pre' tags are converted into github "fenced" code blocks, i.e.
+<pre>&#96;&#96;&#96;...'''</pre>. If language-specific syntax highlighting is desired,
+this can be achieved by adding a 'lang' attribute, e.g.
+
+<pre>&lt;pre lang="erlang"&gt;
+incr(X) ->
+  %% This should be formatted with Erlang syntax highlighting
+  X + 1.
+&lt;/pre&gt;</pre>
+
+which should format like this:
+
+<pre lang="erlang">
+incr(X) ->
+  %% This should be formatted with Erlang syntax highlighting
+  X + 1.
+</pre>
+
+
 Rebar customizations
 ====================
 A set of escripts can be found under
diff --git a/src/edown_xmerl.erl b/src/edown_xmerl.erl
index 181eb48..2a8abe2 100644
--- a/src/edown_xmerl.erl
+++ b/src/edown_xmerl.erl
@@ -230,7 +230,11 @@ md_elem(Tag, Data, Attrs, Parents, E) ->
             %% would have written it and markdown rendering will take
             %% care of entity escaping so that a code block describing
             %% XML or HTML will get rendered properly.
-            ["\n```\n", Data, "\n```\n"];
+	    Lang = case lists:keyfind(lang, #xmlAttribute.name, Attrs) of
+		       #xmlAttribute{value = Lang1} -> Lang1;
+		       false -> ""
+		   end,
+	    ["\n```", Lang, "\n", Data, "\n```\n"];
 	_ ->
 		    ["\n",
 		     xmerl_lib:start_tag(Tag,Attrs),
-- 
GitLab