Snow Flower Text’s lightweight markup supports syntax highlighting of the source code. Syntax highlighting makes it easier to grasp the source code in a structured language such as a programming language or markup language by expressing it by color coding, making it easy to visually distinguish its structure. By highlighting the source code in the programming article, it becomes a document that is easy for the reader to read.
static int fibonacci(int n) {
switch (n) {
case 0: return 0;
case 1: return 1;
default: return fibonacci(n - 2) + fibonacci(n - 1);
}
}
static int fibonacci(int n) {
switch (n) {
case 0: return 0;
case 1: return 1;
default: return fibonacci(n - 2) + fibonacci(n - 1);
}
}
In this article we will explain how to use the lightweight markup highlight function.
Snow Flower Text is a text editor that supports writing and programming. |
1. Features
The syntax highlight function of Snow Flower Text has the following features.
- Supports many programming languages
Snow Flower Text v1.7.x supports over 170 languages, including relatively new languages such as Go, Scala, TypeScript, CoffeeScript and others. For a list of supported languages, see “List of supported languages”.
- Unified syntax highlight engine
Snow Flower Text is designed to minimize the difference in lightweight markup as much as possible. Snow Flower Text uses the unified highlight engine in AsciiDoc and MarkDown. Therefore, there is no difference in the spelling of the languages and languages supported by them.
- It does not depend on setting of document viewing environment
The exported HTML file does not need to execute JavaScript for highlights. Highlighted HTML is output. Therefore, you do not need to specially load JavaScript files, you can easily post articles. Also, documents containing highlighted source code will work regardless of whether JavaScript on the Web browser is enabled or disabled.
2. How to use
AsciiDoc and Markdown enable syntax highlighting by specifying the language for the source code block. You can do it easily with the following procedure.
Select the range of the source code.
Select the menu
Menu
>Format
>Code
to mark up the selection as source code.By specifying the language according to the description format of the markup language, the source code is displayed with coloring according to the syntax classification. For languages that are not supported, it is simply ignored. Refer to “List of Support Languages” for specific language names that can be used.
- Descriptions in AsciiDoc
Enclose the source code description in the
[source]
block and specify the programming language or markup language.[source, Language]
----------------------------------------
Write source code here.
----------------------------------------or
[source, language="Language"]
----------------------------------------
Write source code here.
----------------------------------------Below is An example of highlighting C source code in AsciiDoc document.
Example of using highlights in AsciiDoc document[source, c]
----------------------------------------
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
puts("Hello World!");
return EXIT_SUCCESS;
}
----------------------------------------- Descriptions in MarkDown
In the MarkDown document, specify the language following the backquote.
``` Language
Write source code here.
```Below is An example of highlighting C source code in MarkDown document.
Example of using highlights in MarkDown document``` C
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
puts("Hello World!");
return EXIT_SUCCESS;
}
```
3. Syntax highlight usage example
The following is an example of actually highlighting using Snow Flower Text. The sample code is a simple program that outputs only “Hello, world” Extract languages that are considered to be relatively frequently used.
Since certain coloring rules are applied, you can see that it is easier to read even in unknown languages.
[source, actionscript]
package {
import flash.display.Sprite;
import flash.text.TextField;
public class HelloWorld extends Sprite {
public function HelloWorld():void {
var message:TextField = new TextField;
message.text = "Hello, World";
this.addChild(message);
}
}
}
[source, applescript]
display dialog "Hello, world"
[source, awk]
BEGIN { print "Hello, world" }
[source, c]
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
puts("Hello World!");
return EXIT_SUCCESS;
}
[source, bash]
echo 'Hello, world'
[source, cpp]
main()
{
cout << "Hello World!" << endl;
return 0;
}
[source, commonlisp]
(print "Hello World")
[source, clojure]
(javax.swing.JOptionPane/showMessageDialog nil "Hello World")
[source, cs]
class HelloWorldApp {
public static void Main() {
System.Windows.Forms.MessageBox.Show("Hello, world");
}
}
[source, delphi]
program HelloWorld;
uses
Dialogs;
begin
ShowMessage('Hello, World');
end.
[source, erlang]
-module(hello).
-export([hello/0]).
hello() ->
io:format("Hello World~n", []).
[source, fsharp]
printf "Hello World\n"
[source, go]
package main
import "fmt"
func main() {
fmt.Printf("Hello World\n")
}
[source, groovy]
println "Hello World"
[source, haskell]
main = putStrLn "Hello World"
[source, html]
<HTML>
<!-- Hello World in HTML -->
<HEAD>
<TITLE>Hello World</TITLE>
</HEAD>
<BODY>
Hello World
</BODY>
</HTML>
[source, java]
import java.awt.*;
import java.awt.event.*;
public class HelloFrame extends Frame {
HelloFrame(String title) {
super(title);
}
public void paint(Graphics g) {
super.paint(g);
Insets ins = this.getInsets();
g.drawString("Hello, World", ins.left + 25, ins.top + 25);
}
public static void main(String[] args) {
HelloFrame fr = new HelloFrame("Hello");
fr.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
fr.setResizable(true);
fr.setSize(500, 100);
fr.setVisible(true);
}
}
[source, js]
document.body.appendChild(document.createTextNode("Hello World"));
[source, jsp]
<%= "Hello, world" %>
[source, kotlin]
package hello
fun getHelloString() : String {
return "Hello, world!"
}
fun main(args : Array<String>) {
println(getHelloString())
}
[source, matlab]
disp('Hello World');
[source, objc]
#include <stdio.h>
#include <objpak.h>
int main(int argc,char **argv)
{
id set = [Set new];
argv++;while (--argc) [set add:[String str:*argv++]];
[set do:{ :each | printf("hello, %s\n",[each str]); }];
return 0;
}
[source, ocaml]
print_string "Hello World\n";;
[source, pascal]
program HelloWorld(output);
begin
WriteLn('Hello World');
end.
[source, perl]
print "Hello World\n";
[source, php]
<?php
echo 'Hello, world';
exit;
?>
set serveroutput on
begin
dbms_output.enable(10000);
dbms_output.put_line('Hello World');
end;
/
[source, powershell]
'Hello World'
[source, python]
print "Hello World"
[source, r]
cat("Hello world\n")
[source, ruby]
puts "Hello, world"
[source, rust]
fn main() {
io::println("hello, world");
}
[source, scala]
object HelloWorld extends Application {
println("Hello, world")
}
[source, scheme]
(display "Hello, world")
(newline)
[source, smalltalk]
'Hello, world' printOn: Transcript.
[source, sql]
select 'hello world' from dual;
select 'hello world';
[source, swift]
println("Hello World")
[source, tcl]
puts "Hello, world"
[source, tex]
\documentclass{article}
\begin{document}
Hello World
\end{document}
[source, svg]
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="6.4cm" height="4.8cm" viewBox="0 0 639 479"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<desc>Hello, World</desc>
<text x="320" y="250" font-family="Verdana" font-size="1cm" text-anchor="middle">
Hello, world
</text>
</svg>
[source, vbnet]
Public Class HelloWorldApp
Shared Sub Main()
System.Windows.Forms.MessageBox.Show("Hello, World")
End Sub
End Class
[source, verilog]
module main;
initial
begin
$display("Hello, World");
$finish ;
end
endmodule
[source, vhdl]
ENTITY helloworld IS
END helloworld;
ARCHITECTURE hw OF helloworld IS
BEGIN
ASSERT FALSE
REPORT "HELLO, WORLD"
SEVERITY NOTE;
END hw;
[source, xhtml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<title>Hello, World</title>
</head>
<body>
<p>Hello, World</p>
</body>
</html>
[source, xml]
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="HelloWorld.xsl" ?>
<!-- Hello World in XML -->
<text><string>Hello, World</string></text>
4. List of Support Languages
The following list is a syntax highlightable language supported by Snow Flower Text
. It is specified as the highlight language of the source code. Case differences are ignored for language names.
0-9
1c
A
abnf
accesslog
actionscript
ada
apache
applescript
arduino
armasm
asciidoc
aspectj
autohotkey
autoit
avrasm
awk
axapta
B
bash
basic
bnf
brainfuck
C
cal
capnproto
ceylon
clean
clojure
clojure-repl
cmake
coffeescript
coq
cos
cpp
crmsh
crystal
cs
csp
css
D
d
dart
delphi
diff
django
dns
dockerfile
dos
dsconfig
dts
dust
E
ebnf
elixir
elm
erb
erlang
erlang-repl
excel
F
fix
flix
fortran
fsharp
G
gams
gauss
gcode
gherkin
glsl
go
golo
gradle
groovy
H
haml
handlebars
haskell
haxe
hsp
htmlbars
http
hy
I
inform7
ini
irpf90
J
java
javascript
jboss-cli
json
julia
julia-repl
K
kotlin
L
lasso
ldif
leaf
less
lisp
livecodeserver
livescript
llvm
lsl
lua
M
makefile
markdown
mathematica
matlab
maxima
mel
mercury
mipsasm
mizar
mojolicious
monkey
moonscript
N
n1ql
nginx
nimrod
nix
nsis
O
objectivec
ocaml
openscad
oxygene
P
parser3
perl
pf
php
pony
powershell
processing
profile
prolog
protobuf
puppet
purebasic
python
Q
q
qml
R
r
rib
roboconf
routeros
rsl
ruby
ruleslanguage
rust
S
scala
scheme
scilab
scss
shell
smali
smalltalk
sml
sqf
sql
stan
stata
step21
stylus
subunit
swift
T
taggerscript
tap
tcl
tex
thrift
tp
twig
typescript
V
vala
vbnet
vbscript
vbscript-html
verilog
vhdl
vim
X
x86asm
xl
xml
xquery
Y
yaml
Z
zephir