— layout: post title: “Code snippets” date: 2016-10-01 16:25:06 tags: code jekyll
description: Sample post showing how code samples would look like¶ ↑
Introduction¶ ↑
For code syntax coloration I'm using Darcula theme from Intellij IDEA, which I've found in this post Darcula theme for Pygments.
XML with line numbers (linenos flag), {{ "{%" }} highlight xml linenos %}
: {% highlight xml linenos %} {% raw %} <?xml version=“1.0” encoding=“UTF-8”?> <rss version=“2.0” xmlns:atom=“www.w3.org/2005/Atom”> <channel> <title>{{ site.name }}</title> <description>{{ site.description }}</description> <link>{{site.baseurl | prepend:site.url}}</link> <atom:link href=“{{site.baseurl | prepend:site.url}}/feed.xml” rel=“self” type=“application/rss+xml” /> {% for post in site.posts limit:10 %} <item> <title>{{ post.title }}</title> <description>{{ post.content | xml_escape }}</description> <pubDate>{{ post.date | date: “%a, %d %b %Y %H:%M:%S %z” }}</pubDate> <link>{{post.url | prepend:site.baseurl | prepend:site.url}}</link> <guid isPermaLink=“true”>{{post.url | prepend:site.baseurl | prepend:site.url}}</guid> </item> {% endfor %} </channel> </rss> {% endraw %} {% endhighlight xml %}
JSON {:.filename} {% highlight json %} {“employees”:[ {“firstName”:“John”, “lastName”:“Doe”}, {“firstName”:“Anna”, “lastName”:“Smith”}, {“firstName”:“Peter”, “lastName”:“Jones”} ]} {% endhighlight %}
SQL {:.filename} {% highlight SQL %} select count(*) as cm_content_nodes from alf_node nd, alf_qname qn, alf_namespace ns where qn.ns_id = ns.id and nd.type_qname_id = qn.id and ns.uri = 'www.alfresco.org/model/content/1.0' and qn.local_name = 'content'; {% endhighlight %}
Java {:.filename} {% highlight java %} private String getToken(HttpClient client) throws UnsupportedEncodingException{ Cookie[] cookies = client.getState().getCookies(); for (Cookie cookie : cookies){ if (cookie.getName().equals(“Alfresco-CSRFToken”)){ return URLDecoder.decode(cookie.getValue(), “UTF-8”); } } return null; } {% endhighlight %}
To add name to the code snippet, as in the examples above, add following construction before the snippet:
{% highlight bash %} {% raw %}
Java {:.filename} {% highlight java %} … {% endraw %} {% endhighlight %}