对常用的语言增加了高亮处理,下面是一些高亮的代码Demo

目录

  1. C++
  2. CSS
  3. JavaScript
  4. java
  5. objectivec1
  6. objectivec2
  7. swift Demo
  8. HTML CSS JavaScript Demo
  9. Python
  10. CSS
  11. HTTP
  12. JSON

C++

file.cppCode Block
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
}
};
}

CSS

file.cssCode Block
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
@media screen and (-webkit-min-device-pixel-ratio: 0) {
body:first-of-type pre::after {
content: 'highlight: ' attr(class);
}
body {
background: linear-gradient(45deg, blue, red);
}
}
@import url('print.css');
@page:right {
margin: 1cm 2cm 1.3cm 4cm;
}
@font-face {
font-family: Chunkfive; src: url('Chunkfive.otf');
}
div.text,
#content,
li[lang=ru] {
font: Tahoma, Chunkfive, sans-serif;
background: url('hatch.png') /* wtf? */; color: #F0F0F0 !important;
width: 100%;
}

JavaScript

file.javaCode Block
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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));
}

java

file.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public SomeClass(AnInterface param, int[] reassignedParam) {
int localVar = "IntelliJ"; // Error, incompatible types
System.out.println(anotherString + toString() + localVar);
long time = Date.parse("1.2.3"); // Method is deprecated
int reassignedValue = this.staticField;
reassignedValue ++;
field.run();
new SomeClass() {
{
int a = localVar;
}
};
reassignedParam = new ArrayList<String>().toArray(new int[0]);
}
enum AnEnum { CONST1, CONST2 }
interface AnInterface {
int CONSTANT = 2;
void method();
}
abstract class SomeAbstractClass {
}

objectivec1

file.objcCode Block
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
#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
objc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@interface SongPlayer : NSObject
- (void)playSong:(Song *)song;
@end
@implementation SongPlayer
- (void)playSong:(Song *)song {
NSError *error;
[self startAudio:&error];
//...
}
- (void)startAudio:(NSError **)error {
//...
}
@end

objectivec2

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
#import "UIButton+Block.h"
#import <objc/runtime.h>
static id key;
@implementation UIButton (Block)
- ( void )initWithBlock:( ClickActionBlock )clickBlock for:( UIControlEvents )event{
objc_setAssociatedObject ( self , & key , clickBlock, OBJC_ASSOCIATION_COPY_NONATOMIC );
[ self addTarget : self action : @selector (goAction:) forControlEvents :event];
}
- ( void )goAction:( UIButton *)sender{
ClickActionBlock block = ( ClickActionBlock ) objc_getAssociatedObject ( self , & key );
if (block) {
block(sender);
}
}
@end

swift Demo

file.swiftCode Block
1
2
3
4
5
6
7
8
9
10
11
extension MyClass : Interface {
class func unarchiveFromFile<A>(file : A, (Int,Int) -> B) -> SKNode? {
let path: String = bundle.pathForResource(file, ofType: "file\(name + 5).txt")
let funnyNumber = 3 + 0xC2.15p2 * (1_000_000.000_000_1 - 000123.456) + 0o21
var sceneData = NSData.dataWithContentsOfFile(path, options: .DataReadingMappedIfSafe, error: nil)
/* a comment /* with a nested comment */ and the end */
}
@objc override func shouldAutorotate() {
return true
}
}

HTML CSS JavaScript Demo

example
  • js
  • css
  • html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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));
}

Python

archives.pyCode Block
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@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'''

CSS

archives.cssCode Block
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
@media screen and (-webkit-min-device-pixel-ratio: 0) {
body:first-of-type pre::after {
content: 'highlight: ' attr(class);
}
body {
background: linear-gradient(45deg, blue, red);
}
}
@import url('print.css');
@page:right {
margin: 1cm 2cm 1.3cm 4cm;
}
@font-face {
font-family: Chunkfive; src: url('Chunkfive.otf');
}
div.text,
#content,
li[lang=ru] {
font: Tahoma, Chunkfive, sans-serif;
background: url('hatch.png') /* wtf? */; color: #F0F0F0 !important;
width: 100%;
}

HTTP

archives.httpCode Block
1
2
3
4
5
6
7
8
9
10
11
html:text/html
Ascii: text/plain
Json:text/json
Jpg:image/jpeg
Gif:image/gif
Ppt: application/vnd.ms-powerpoint
Quicktime:video/quicktime
Content-Length: 1024
Content-Type: text/plain
GET / index.htm HTTP/1.1
Host: hackr.jp

JSON

archives.jsonCode Block
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}
}
]