Below you will find pages that utilize the taxonomy term “Formatting Code”
a post with tabs
This is how a post with tabs looks like. Note that the tabs could be used for different purposes, not only for code.
First tabs
To add tabs, use the following syntax:
{% raw %}
{% tabs group-name %}
{% tab group-name tab-name-1 %}
Content 1
{% endtab %}
{% tab group-name tab-name-2 %}
Content 2
{% endtab %}
{% endtabs %}
{% endraw %}
With this you can generate visualizations like:
a post with pseudo code
This is an example post with some pseudo code rendered by pseudocode. The example presented here is the same as the one in the pseudocode.js documentation, with only one simple but important change: everytime you would use $
, you should use $$
instead. Also, note that the pseudocode
key in the front matter is set to true
to enable the rendering of pseudo code. As an example, using this code:
```pseudocode
% This quicksort algorithm is extracted from Chapter 7, Introduction to Algorithms (3rd edition)
\begin{algorithm}
\caption{Quicksort}
\begin{algorithmic}
\PROCEDURE{Quicksort}{$$A, p, r$$}
\IF{$$p < r$$}
\STATE $$q = $$ \CALL{Partition}{$$A, p, r$$}
\STATE \CALL{Quicksort}{$$A, p, q - 1$$}
\STATE \CALL{Quicksort}{$$A, q + 1, r$$}
\ENDIF
\ENDPROCEDURE
\PROCEDURE{Partition}{$$A, p, r$$}
\STATE $$x = A[r]$$
\STATE $$i = p - 1$$
\FOR{$$j = p$$ \TO $$r - 1$$}
\IF{$$A[j] < x$$}
\STATE $$i = i + 1$$
\STATE exchange
$$A[i]$$ with $$A[j]$$
\ENDIF
\STATE exchange $$A[i]$$ with $$A[r]$$
\ENDFOR
\ENDPROCEDURE
\end{algorithmic}
\end{algorithm}
```
Generates:
a post with code diff
You can display diff code by using the regular markdown syntax:
```diff
diff --git a/sample.js b/sample.js
index 0000001..0ddf2ba
--- a/sample.js
+++ b/sample.js
@@ -1 +1 @@
-console.log("Hello World!")
+console.log("Hello from Diff2Html!")
```
Which generates:
diff --git a/sample.js b/sample.js
index 0000001..0ddf2ba
--- a/sample.js
+++ b/sample.js
@@ -1 +1 @@
-console.log("Hello World!")
+console.log("Hello from Diff2Html!")
But this is difficult to read, specially if you have a large diff. You can use diff2html to display a more readable version of the diff. For this, just use diff2html
instead of diff
for the code block language:
a post with code
This theme implements a built-in Jekyll feature, the use of Rouge, for syntax highlighting. It supports more than 100 languages. This example is in C++. All you have to do is wrap your code in markdown code tags:
```c++
code code code
```
int main(int argc, char const \*argv[])
{
string myString;
cout << "input a string: ";
getline(cin, myString);
int length = myString.length();
char charArray = new char * [length];
charArray = myString;
for(int i = 0; i < length; ++i){
cout << charArray[i] << " ";
}
return 0;
}
For displaying code in a list item, you have to be aware of the indentation, as stated in this Stackoverflow answer. You must indent your code by (3 * bullet_indent_level) spaces. This is because kramdown (the markdown engine used by Jekyll) indentation for the code block in lists is determined by the column number of the first non-space character after the list item marker. For example: