对常用的语言增加了高亮处理,下面是一些高亮的代码Demo
目录
- C++
- CSS
- JavaScript
- java
- objectivec1
- objectivec2
- swift Demo
- HTML CSS JavaScript Demo
- Python
- CSS
- HTTP
- JSON
C++
file.cppCode Block1 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
| #include <vector> using namespace std; 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 Block1 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') ; color: #F0F0F0 !important; width: 100%; }
|
JavaScript
file.javaCode Block1 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) { var e4x = <div>Example <p>1234</p></div>; } for (var i = 0 / 2; i < classes.length; i++) { if (checkCondition(classes[i]) === undefined) return /\d+[\s/]/g; } console.log(Array.every(classes, Boolean)); }
|
java
file.java1 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"; System.out.println(anotherString + toString() + localVar); long time = Date.parse("1.2.3"); 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 Block1 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.m1 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 Block1 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) } @objc override func shouldAutorotate() { return true } }
|
HTML CSS JavaScript Demo
example1 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) { var e4x = <div>Example <p>1234</p></div>; } for (var i = 0 / 2; i < classes.length; i++) { if (checkCondition(classes[i]) === undefined) return /\d+[\s/]/g; } console.log(Array.every(classes, Boolean)); }
|
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
| @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') ; color: #F0F0F0 !important; width: 100%; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?xml version="1.0"?> <response value="ok" xml:lang="en"> <text>Ok</text> <comment html_allowed="true"/> <ns1:description><![CDATA[ CDATA is <not> magical. ]]></ns1:description> <a></a> <a/> </response>
<!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>
|
Python
archives.pyCode Block1 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: print 'Gre\'ater' return (param2 - param1 + 1 + 0b10l) or None class SomeClass: pass >>> message = '''interpreter ... prompt'''
|
CSS
archives.cssCode Block1 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') ; color: #F0F0F0 !important; width: 100%; }
|
HTTP
archives.httpCode Block1 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 Block1 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} } ]
|