Highlight.js Test Code
Highlight.js Test Code Created 24-04-20 | Updated 25-01-12 작성일 24-04-20 | 업데이트 25-01-12
| Words 단어수 2.7k | Reading 독해시간 16 mins 16분 | Views 조회수 |
이 게시물은 한글과 영어로 동시에 작성되어 있습니다.
If you want to see in English, please change the language by clicking the right-bottom gear button.
This post is written in both Korean and English.
한글로 보시려면 페이지 우측 하단의 톱니바퀴 버튼을 눌러 언어를 변경하세요.
This article is for testing my blog’s customized highlight color scheme.
All the example source codes are scratched from highlight.js official site .
Supported languages and their abbreviations can be found from highlight.js github page .
If you want to test for your own blog, use this markdown file rather than copying it manually.
이 게시물은 제 블로그의 highlight color scheme을 테스트하기 위한 목적으로 작성되었습니다.
모든 예제 코드는 highlight.js 공식 사이트 에서 그대로 긁어온 자료입니다.
지원하는 프로그래밍 언어의 종류와 줄임말은 highlight.js 깃헙 페이지 에서 확인할 수 있습니다.
만일 직접 테스트해보고 싶으시다면, 공홈에서 수동으로 복붙하지 마시고 이 마크다운 파일 을 다운받아 사용하세요.
HTML, XML
1 2 3 4 5 6 7 8 9 10 11 12 13 <!DOCTYPE html > <title > Title</title > <style > body {width : 500px ;}</style > <script type ="application/javascript" > function $init ( ) {return true ;} </script > <body > <p checked class ="title" id ='title' > Title</p > </body >
Bash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #!/bin/bash ACCEPTED_HOSTS="/root/.hag_accepted.conf" BE_VERBOSE=false if [ "$UID " -ne 0 ]then echo "Superuser rights required" exit 2 fi genApacheConf (){ echo -e "# Host ${HOME_DIR} $1 /$2 :" } echo '"quoted"' | tr -d \" > text.txt
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <iostream> int main (int argc, char *argv[]) { for (auto i = 0 ; i < 0xFFFF ; i++) cout << "Hello, World!" << endl; char c = '\n' ; unordered_map <string, vector<string> > m; m["key" ] = "\\\\" ; return -2e3 + 12l ; }
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 using System.IO.Compression;#pragma warning disable 414, 3021 namespace MyApplication { [Obsolete("..." ) ] class Program : IInterface { public static List<int > JustDoIt (int count ) { Span<int > numbers = stackalloc int [length]; Console.WriteLine($"Hello {Name} !" ); return new List<int >(new int [] { 1 , 2 , 3 }) } } }
CSS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @font-face { font-family : Chunkfive; src : url ('Chunkfive.otf' ); } body , .usertext { color : #F0F0F0 ; background : #600 ; font-family : Chunkfive, sans; --heading-1 : 30px /32px Helvetica, sans-serif; } @import url(print.css);@media print { a [href^=http] ::after { content : attr (href) } }
Markdown
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 # hello world you can write text [with links ](http://example.com ) inline or [link references ][1 ]. * one _thing_ has *em* phasis* two __things__ are **bold** [1 ]: http://example.com --- hello world =========== <this_is inline ="xml" > </this_is > > markdown is so cool so are code segments 1. one thing (yeah!)2. two thing `i can write code` , and `more` wipee!
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 @@ -1,8 +1,7 @@ hljs.LANGUAGES.ini = { case_insensitive: true, - defaultMode: - { + defaultMode: { contains: ['comment', 'title', 'setting'], illegal: '[^\\s]' }, *** 1,3 **** --- 1,9 ---- + This is an important + notice! It should + therefore be located at + the beginning of this + document! ! compress the size of the ! changes. It is important to spell
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 class Greeter def initialize (name ) @name = name.capitalize end def salute puts "Hello #{@name } !" end end g = Greeter .new("world" ) g.salute
Go
1 2 3 4 5 6 7 8 9 10 11 12 package mainimport "fmt" func main () { ch := make (chan float64 ) ch <- 1.0e10 x, ok := <- ch defer fmt.Println(`exitting now\` ) go println (len ("hello world!" )) return }
TOML, INI
1 2 3 4 5 6 7 8 9 10 11 12 [package] name = "some_name" authors = ["Author" ]description = "This is \ a description" [[lib]] name = ${NAME} default = True auto = no counter = 1_000
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 package l2f.gameserver.model;public abstract strictfp class L2Char extends L2Object { public static final Short ERROR = 0x0001 ; public void moveTo (int x, int y, int z) { _ai = null ; log("Should not be called" ); if (1 > 5 ) { return ; } } }
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 function $initHighlight (block, cls ) { try { if (cls.search (/\bno\-highlight\b/ ) != -1 ) return process (block, true , 0x0F ) + ` class="${cls} "` ; } catch (e) { } for (var i = 0 / 2 ; i < classes.length ; i++) { if (checkCondition (classes[i]) === undefined ) console .log ('undefined' ); } return ( <div > <web-component > {block}</web-component > </div > ) } export $initHighlight;
JSON
1 2 3 4 5 6 7 8 9 10 11 12 [ { "title" : "apples" , "count" : [ 12000 , 20000 ] , "description" : { "text" : "..." , "sensitive" : false } } , { "title" : "oranges" , "count" : [ 17500 , null ] , "description" : { "text" : "..." , "sensitive" : false } } ]
Kotlin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 import kotlinx.serialization.Serializableimport kotlin.random.Randominterface Building @Serializable class House ( private val rooms: Int ? = 3 , val name: String = "Palace" ) : Building { var residents: Int = 4 get () { println("Current residents: $field " ) return field } fun burn (evacuation: (people : Int ) -> Boolean ) { rooms ?: return if (evacuation((0. .residents).random())) residents = 0 } } fun main () { val house = House(name = "Skyscraper 1" ) house.burn { Random.nextBoolean() } }
Less
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 @import "fruits" ;@rhythm: 1.5em ;@media screen and (min-resolution : 2dppx ) { body {font-size : 125% } } section > .foo + #bar :hover [href*="less" ] { margin : @rhythm 0 0 @rhythm ; padding : calc (5% + 20px ); background : #f00ba7 url(http://placehold.alpha-centauri/42.png ) no-repeat; background-image : linear-gradient (-135deg , wheat, fuchsia) !important ; background-blend-mode : multiply; } @font-face { font-family : 'Omega' ; src : url('../fonts/omega-webfont.woff?v=2.0.2' ); } .icon-baz ::before { display : inline-block; font-family : "Omega" , Alpha, sans-serif; content : "\f085" ; color : rgba (98 , 76 , 231 , .75 ); }
Lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 local signal_mt = { __index = { register = table .insert } } function signal_mt.__index:emit (... ) for _, slot in ipairs (self ) do slot(self , ...) end end local function create_signal () return setmetatable ({}, signal_mt) end local signal = create_signal()signal:register(function (signal, ...) print (...) end )signal:emit('Answer to Life, the Universe, and Everything:' , 42 ) [==[ Nested [=[ multi-line [[ string ]] ]=] ]==]
Makefile
1 2 3 4 5 6 7 8 9 10 11 12 13 BUILDDIR = _build EXTRAS ?= $(BUILDDIR) /extras .PHONY : main cleanmain: @echo "Building main facility..." build_main $(BUILDDIR) clean: rm -rf $(BUILDDIR) /*
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 sub load { my $flds = $c ->db_load($id ,@_ ) || do { Carp::carp "Can`t load (class: $c , id: $id ): '$! '" ; return undef }; my $o = $c ->_perl_new(); $id12 = $id / 24 / 3600 ; $o ->{'ID' } = $id12 + 123 ; my $p = $o ->props; my $vt ; $string =~ m/^sought_text$/ ; $items = split // , 'abc' ; $string //= "bar" ; for my $key (keys %$ p) { if (${$vt .'::property' }) { $o ->{$key . '_real' } = $flds ->{$key }; tie $o ->{$key }, 'CMSBuilder::Property' , $o , $key ; } } $o ->save if delete $o ->{'_save_after_load' }; my $g = glob ("/usr/bin/*" ); return $o ; } __DATA__ <!DOCTYPE html > <html > <head > <title > <%= title %></title > </head > <body > <%= content %></body > </html > __END__
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 #import <UIKit/UIKit.h> #import "Dependency.h" @protocol WorldDataSource @optional - (NSString *)worldName; @required - (BOOL )allowsToLive; @end @property (nonatomic , readonly ) NSString *title;- (IBAction ) show; @end
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 require_once 'Zend/Uri/Http.php' ;namespace Location \Web ;interface Factory { static function _factory ( ) ; } abstract class URI extends BaseURI implements Factory { abstract function test ( ) ; public static $st1 = 1 ; const ME = "Yo" ; var $list = NULL ; private $var ; static public function _factory ($stats = array ( ), $uri = 'http' ) { echo __METHOD__ ; $uri = explode (':' , $uri , 0b10 ); $schemeSpecific = isset ($uri [1 ]) ? $uri [1 ] : '' ; $desc = 'Multi line description' ; if (!ctype_alnum ($scheme )) { throw new Zend_Uri_Exception ('Illegal scheme' ); } $this ->var = 0 - self ::$st ; $this ->list = list (Array ("1" => 2 , 2 =>self ::ME , 3 => \Location\Web\URI::class )); return [ 'uri' => $uri , 'value' => null , ]; } } match ($key ) { 1 => 'Integer 1' , '1' => 'String 1' , true => 'Bool true' , [] => 'Empty array' , [1 ] => 'Array [1]' , }; enum Foo : string { case Test = 'test' ; } match ($key ) { 1 => 'Integer 1' , '1' => 'String 1' , true => 'Bool true' , [] => 'Empty array' , [1 ] => 'Array [1]' , }; echo URI::ME . URI::$st1 ;__halt_compiler () ; dataheredatahere datahere */ datahere
Python
1 2 3 4 5 6 7 8 9 10 11 12 @requires_authorization(roles=["ADMIN" ] ) def somefunc (param1='' , param2=0 ): r'''A docstring''' if param1 > param2: print 'Gre\'ater' return (param2 - param1 + 1 + 0b10l ) or None class SomeClass : pass >>> message = '''interpreter ... prompt'''
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 require( stats) centre <- function ( x, type) { switch ( type, mean = mean( x) , median = median( x) , trimmed = mean( x, trim = .1 ) ) } x <- rcauchy( 10 ) centre( x, "mean" ) library( ggplot2) models <- tibble:: tribble( ~ model_name, ~ formula, "length-width" , Sepal.Length ~ Petal.Width + Petal.Length, "interaction" , Sepal.Length ~ Petal.Width * Petal.Length ) iris %>% nest_by( Species) %>% left_join( models, by = character( ) ) %>% rowwise( Species, model_name) %>% mutate( model = list ( lm( formula, data = data) ) ) %>% summarise( broom:: glance( model) )
Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #[derive(Debug)] pub enum State { Start, Transient, Closed, } impl From <&'a str > for State { fn from (s: &'a str ) -> Self { match s { "start" => State::Start, "closed" => State::Closed, _ => unreachable! (), } } }
SCSS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 @import "compass/reset" ;$colorGreen : #008000 ;$colorGreenDark : darken ($colorGreen , 10 );@mixin container { max-width : 980px ; } @mixin button($color :green) { @if ($color == green) { background-color : #008000 ; } @else if ($color == red) { background-color : #B22222 ; } } button { @include button(red); } div ,.navbar ,#header ,input [type="input" ] { font-family : "Helvetica Neue" , Arial, sans-serif; width : auto; margin : 0 auto; display : block; } .row-12 > [class*="spans" ] { border-left : 1px solid #B5C583 ; } ul { width : 100% ; padding : { left : 5px ; right : 5px ; } li { float : left; margin-right : 10px ; .home { background : url ('http://placehold.it/20' ) scroll no-repeat 0 0 ; } } } .banner { @extend .container; } a { color : $colorGreen ; &:hover { color : $colorGreenDark ; } &:visited { color : #c458cb ; } } @for $i from 1 through 5 { .span #{$i } { width : 20px *$i ; } } @mixin mobile { @media screen and (max-width : 600px ) { @content ; } }
Shell Session
1 2 3 4 5 6 7 8 9 10 11 $ echo $EDITOR vim $ git checkout main Switched to branch 'main' Your branch is up-to-date with 'origin/main'. $ git push Everything up-to-date $ echo 'All > done!' All done!
SQL
1 2 3 4 5 6 7 8 9 10 11 12 CREATE TABLE "topic" ( "id" integer NOT NULL PRIMARY KEY , "forum_id" integer NOT NULL , "subject" varchar (255 ) NOT NULL ); ALTER TABLE "topic"ADD CONSTRAINT forum_id FOREIGN KEY ("forum_id")REFERENCES "forum" ("id");insert into "topic" ("forum_id", "subject")values (2 , 'D''artagnian' );
Swift
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import Foundation@objc class Person : Entity { var name: String ! var age: Int ! init (name : String , age : Int ) { } func description (offset : Int = 0 ) -> String { return "\(name) is \(age + offset) years old" } }
YAML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 --- string_1: "Bar" string_2: 'bar' string_3: bar inline_keys_ignored: sompath/name/file.jpg keywords_in_yaml: - true - false - TRUE - FALSE - 21 - 21.0 - !!str 123 "quoted_key": &foobar bar: foo foo: "foo": bar reference: *foobar multiline_1: | Multiline String multiline_2: > Multiline String multiline_3: " Multiline string " ansible_variables: "foo {{variable}} " array_nested: - a - b: 1 c: 2 - b - comment
TypeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 class MyClass { public static myValue : string ; constructor (init : string ) { this .myValue = init; } } import fs = require ("fs" );module MyModule { export interface MyInterface extends Other { myProperty : any ; } } declare magicNumber number ;myArray.forEach (() => { });
Visual Basic .NET
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Imports SystemImports System.IO#Const DEBUG = True Namespace Highlighter.Test Public Class Program Protected Shared hello As Integer = 3 Private Const ABC As Boolean = False #Region "Code" <STAThread()> _ Public Shared Sub Main(ByVal args() As String , ParamArray arr As Object ) Handles Form1.Click On Error Resume Next If ABC Then While ABC : Console.WriteLine() : End While For i As Long = 0 To 1000 Step 123 Try System.Windows.Forms.MessageBox.Show(CInt ("1" ).ToString()) Catch ex As Exception Dim exp = CType(ex, IOException) Return End Try Next Else Dim l As New System.Collections.List<String >() SyncLock l If TypeOf l Is Decimal And l IsNot Nothing Then RemoveHandler button1.Paint, delegate End If Dim d = New System.Threading.Thread(AddressOf ThreadProc) Dim a = New Action(Sub (x, y) x + y) Static u = From x As String In l Select x.Substring(2 , 4 ) Where x.Length > 0 End SyncLock Do : Laugh() : Loop Until hello = 4 End If End Sub #End Region End Class End Namespace