highlighted code showcase
Tranquilpeak Hugo theme have its own theme to highlight source code. It’s based on GitHub theme: simple and elegant. Check out how it sublimate source codes.
目录
Tabbed code block
ApacheConf
1 |
|
Bash
1 |
|
Coffeescript
1 |
|
C++
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
/*
* Block comment
*/
#include <vector>
using namespace std; // line comment
namespace foo {
typedef struct Struct {
int field;
} Typedef;
enum Enum {Foo = 1, Bar = 2};
Typedef *globalVar;
extern Typedef *externVar;
template<typename T, int N>
class Class {
T n;
public:
void function(int paramName) {
int *localVar = new int[1];
this->n = N;
label:
printf("Formatted string %d\n\g", localVar[0]);
printf(R"**(Formatted raw-string %d\n)**", 1);
std::cout << (1 << 2) << std::endl;
#define FOO(A) A
#ifdef DEBUG
printf("debug");
#endif
}
};
}
CShparp
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
using System;
#pragma warning disable 414, 3021
public class Program
{
/// <summary>The entry point to the program.</summary>
public static int Main(string[] args)
{
Console.WriteLine("Hello, World!");
string s = @"This
""string""
spans
multiple
lines!";
return 0;
}
}
async Task<int> AccessTheWebAsync()
{
// ...
string urlContents = await getStringTask;
return urlContents.Length;
}
CSS
1 |
|
DIFF
1 |
|
HTTP
1 |
|
INI
1 |
|
Java
1 |
|
JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function $initHighlight(block, flags) {
try {
if (block.className.search(/\bno\-highlight\b/) != -1)
return processBlock(block.function, true, 0x0F) + ' class=""';
} catch (e) {
/* handle exception */
var e4x =
<div>Example
<p>1234</p></div>;
}
for (var i = 0 / 2; i < classes.length; i++) { // "0 / 2" should not be parsed as regexp
if (checkCondition(classes[i]) === undefined)
return /\d+[\s/]/g;
}
console.log(Array.every(classes, Boolean));
}
JSON
1 |
|
Makefile
1 |
|
Markdown
1 |
|
Nginx
1 |
|
Objective-C
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
#import <UIKit/UIKit.h>
#import "Dependency.h"
@protocol WorldDataSource
@optional
- (NSString*)worldName;
@required
- (BOOL)allowsToLive;
@end
@interface Test : NSObject <HelloDelegate, WorldDataSource> {
NSString *_greeting;
}
@property (nonatomic, readonly) NSString *greeting;
- (IBAction) show;
@end
@implementation Test
@synthesize test=_test;
+ (id) test {
return [self testWithGreeting:@"Hello, world!\nFoo bar!"];
}
+ (id) testWithGreeting:(NSString*)greeting {
return [[[self alloc] initWithGreeting:greeting] autorelease];
}
- (id) initWithGreeting:(NSString*)greeting {
if ( (self = [super init]) ) {
_greeting = [greeting retain];
}
return self;
}
- (void) dealloc {
[_greeting release];
[super dealloc];
}
@end
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
# loads object
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;
#$o->{'SHCUT'} = $flds->{'SHCUT'};
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'};
# GH-117
my $g = glob("/usr/bin/*");
return $o;
}
=head1 NAME
POD till the end of file
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
<?php
$heredoc = <<< HEREDOC_ID
some $contents
HEREDOC_ID;
function foo() {
return SomeClass::$shared;
}
// Sample comment
class SomeClass extends One implements Another {
private $my;
public static $shared;
const MAGIC = 0987654321;
/**
* Description by <a href="mailto:">user@host.dom</a>
* @return SomeType
*/
function doSmth($abc, $def) {
foo();
$def .= self::MAGIC;
$v = Helper::convert($abc . "\n {$def}" . $$def);
$q = new Query( $this->invent(abs(0x80)) );
return array($v => $q->result);
}
}
interface Another {
}
include (dirname(__FILE__) . "inc.php");
`rm -r`;
goto Label;
Label:
<php_bad>№</php_bad>
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
@requires_authorization
def somefunc(param1='', param2=0):
r'''A docstring'''
if param1 > param2: # interesting
print 'Gre\'ater'
return (param2 - param1 + 1 + 0b10l) or None
class SomeClass:
pass
>>> message = '''interpreter
... prompt'''
Ruby
1 |
|
SQL
1 |
|
HTML
1 |
|
Puppet
1 |
|
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
@import 'mixins'; // external mixins
@the-border: 1px;
@base-color: #111;
#header:after {
color: @base-color * 3;
border-right: @the-border * 2;
}
.colored(@c) when (iscolor(@c)) {
color: (@base-color + #111) * 1.5;
}
@var: `"hello".toUpperCase() + '!'`;
@font-face {
font-family: DroidSans;
src: url(DroidSans.ttf);
unicode-range: U+000-5FF, U+1e00-1fff, U+2000-2300;
}
div > p, p ~ ul, input[type="radio"] {
color: green !important;
}
SCSS
1 |
|
Stylus
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
@import "nib"
// variables
$green = #008000
$green_dark = darken($green, 10)
// mixin/function
container()
max-width 980px
// mixin/function with parameters
buttonBG($color = green)
if $color == green
background-color #008000
else if $color == red
background-color #B22222
button
buttonBG(red)
#content, .content
font Tahoma, Chunkfive, sans-serif
background url('hatch.png')
color #F0F0F0 !important
width 100%
Go
1 |
|
Swift
1 |
|