Debian Codegraph @

tests/gui/books/highlighting/src/languages.md

raw
1 # Syntax Highlights
2
3 ## apache
4
5 ```apache
6 # rewrite`s rules for wordpress pretty url
7 LoadModule rewrite_module modules/mod_rewrite.so
8 RewriteCond %{REQUEST_FILENAME} !-f
9 RewriteCond %{REQUEST_FILENAME} !-d
10 RewriteRule . index.php [NC,L]
11
12 ExpiresActive On
13 ExpiresByType application/x-javascript "access plus 1 days"
14
15 Order Deny,Allow
16 Allow from All
17
18 <Location /maps/>
19 RewriteMap map txt:map.txt
20 RewriteMap lower int:tolower
21 RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC]
22 RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND
23 RewriteRule .? /index.php?q=${map:${lower:%1}} [NC,L]
24 </Location>
25
26 20.164.151.111 - - [20/Aug/2015:22:20:18 -0400] "GET /mywebpage/index.php HTTP/1.1" 403 772 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1"
27 ```
28
29 ## armasm
30
31 ```armasm
32 .data
33
34 /* Data segment: define our message string and calculate its length. */
35 msg:
36 .ascii "Hello, ARM!\n"
37 len = . - msg
38
39 .text
40
41 /* Our application's entry point. */
42 .globl _start
43 _start:
44 /* syscall write(int fd, const void *buf, size_t count) */
45 mov %r0, $1 /* fd := STDOUT_FILENO */
46 ldr %r1, =msg /* buf := msg */
47 ldr %r2, =len /* count := len */
48 mov %r7, $4 /* write is syscall #4 */
49 swi $0 /* invoke syscall */
50
51 /* syscall exit(int status) */
52 mov %r0, $0 /* status := 0 */
53 mov %r7, $1 /* exit is syscall #1 */
54 swi $0 /* invoke syscall */
55
56 ```
57
58 ## bash
59
60 ```bash
61 #!/bin/bash
62
63 ###### CONFIG
64 ACCEPTED_HOSTS="/root/.hag_accepted.conf"
65 BE_VERBOSE=false
66
67 if [ "$UID" -ne 0 ]
68 then
69 echo "Superuser rights required"
70 exit 2
71 fi
72
73 genApacheConf(){
74 echo -e "# Host ${HOME_DIR}$1/$2 :"
75 }
76
77 echo '"quoted"' | tr -d \" > text.txt
78
79 ```
80
81 ## c
82
83 ```c
84 #include <stdio.h>
85 void main(int argc,char ** argv){
86 printf("Hello World!");
87 }
88
89 ```
90
91 ## coffeescript
92
93 ```coffeescript
94 grade = (student, period=(if b? then 7 else 6)) ->
95 if student.excellentWork
96 "A+"
97 else if student.okayStuff
98 if student.triedHard then "B" else "B-"
99 else
100 "C"
101
102 class Animal extends Being
103 constructor: (@name) ->
104
105 move: (meters) ->
106 alert @name + " moved #{meters}m."
107 ```
108
109 ## cpp
110
111 ```cpp
112 #include <iostream>
113 using namespace std;
114 int main() {
115 cout << "Hello, World!" << endl; // This prints Hello, World!
116 return 0;
117 }
118 ```
119
120 ## csharp
121
122 ```csharp
123 using System;
124 class App
125 {
126 static void Main()
127 {
128 Console.WriteLine("Hello World!");
129 }
130 }
131 ```
132
133 ## css
134
135 ```css
136 @font-face {
137 font-family: Chunkfive;
138 src: url('Chunkfive.otf');
139 }
140
141 body,
142 .usertext {
143 color: #f0f0f0;
144 background: #600;
145 font-family: Chunkfive, sans;
146 --heading-1: 30px/32px Helvetica, sans-serif;
147 }
148
149 @import url(print.css);
150 @media print {
151 a[href^='http']::after {
152 content: attr(href);
153 }
154 }
155 ```
156
157 ## d
158
159 ```d
160 /* This program prints a
161 hello world message
162 to the console. */
163
164 import std.stdio;
165
166 void main()
167 {
168 writeln("Hello, World!");
169 }
170 ```
171
172 ## diff
173
174 ```diff
175 Index: languages/ini.js
176 ===================================================================
177 --- languages/ini.js (revision 199)
178 +++ languages/ini.js (revision 200)
179 @@ -1,8 +1,7 @@
180 hljs.LANGUAGES.ini =
181 {
182 case_insensitive: true,
183 - defaultMode:
184 - {
185 + defaultMode: {
186 contains: ['comment', 'title', 'setting'],
187 illegal: '[^\\s]'
188 },
189
190 *** /path/to/original timestamp
191 --- /path/to/new timestamp
192 ***************
193 *** 1,3 ****
194 --- 1,9 ----
195 + This is an important
196 + notice! It should
197 + therefore be located at
198 + the beginning of this
199 + document!
200
201 ! compress the size of the
202 ! changes.
203
204 It is important to spell
205 ```
206
207 ## go
208
209 ```go
210 package main
211 import "fmt"
212
213 func main() {
214 fmt.Println("Hello World!")
215 }
216 ```
217
218 ## handlebars
219
220 ```handlebars
221 <div class='entry'>
222 {{! only show if author exists }}
223 {{#if author}}
224 <h1>{{firstName}} {{lastName}}</h1>
225 {{/if}}
226 </div>
227 ```
228
229 ## haskell
230
231 ```haskell
232 main :: IO ()
233 main = putStrLn "Hello World!"
234
235 ```
236
237 ## http
238
239 ```http
240 POST /task?id=1 HTTP/1.1
241 Host: example.org
242 Content-Type: application/json; charset=utf-8
243 Content-Length: 137
244
245 {
246 "status": "ok",
247 "extended": true,
248 "results": [
249 {"value": 0, "type": "int64"},
250 {"value": 1.0e+3, "type": "decimal"}
251 ]
252 }
253
254 ```
255
256 ## ini
257
258 ```ini
259 ; boilerplate
260 [package]
261 name = "some_name"
262 authors = ["Author"]
263 description = "This is \
264 a description"
265
266 [[lib]]
267 name = ${NAME}
268 default = True
269 auto = no
270 counter = 1_000
271 ```
272
273 ## java
274
275 ```java
276 class Main {
277 public static void main(String[] args) {
278 System.out.println("Hello World!");
279 }
280 }
281 ```
282
283 ## javascript
284
285 ```javascript
286 function $initHighlight(block, cls) {
287 try {
288 if (cls.search(/\bno\-highlight\b/) != -1)
289 return process(block, true, 0x0F) +
290 ` class="${cls}"`;
291 } catch (e) {
292 /* handle exception */
293 }
294 for (var i = 0 / 2; i < classes.length; i++) {
295 if (checkCondition(classes[i]) === undefined)
296 console.log('undefined');
297 }
298
299 return (
300 <div>
301 <web-component>{block}</web-component>
302 </div>
303 )
304 }
305
306 export $initHighlight;
307 ```
308
309 ## json
310
311 ```json
312 [
313 {
314 "title": "apples",
315 "count": [12000, 20000],
316 "description": { "text": "...", "sensitive": false }
317 },
318 {
319 "title": "oranges",
320 "count": [17500, null],
321 "description": { "text": "...", "sensitive": false }
322 }
323 ]
324 ```
325
326 ## julia
327
328 ```julia
329 # function to calculate the volume of a sphere
330 function sphere_vol(r)
331 # julia allows Unicode names (in UTF-8 encoding)
332 # so either "pi" or the symbol π can be used
333 return 4/3*pi*r^3
334 end
335
336 # functions can also be defined more succinctly
337 quadratic(a, sqr_term, b) = (-b + sqr_term) / 2a
338
339 # calculates x for 0 = a*x^2+b*x+c, arguments types can be defined in function definitions
340 function quadratic2(a::Float64, b::Float64, c::Float64)
341 # unlike other languages 2a is equivalent to 2*a
342 # a^2 is used instead of a**2 or pow(a,2)
343 sqr_term = sqrt(b^2-4a*c)
344 r1 = quadratic(a, sqr_term, b)
345 r2 = quadratic(a, -sqr_term, b)
346 # multiple values can be returned from a function using tuples
347 # if the return keyword is omitted, the last term is returned
348 r1, r2
349 end
350
351 vol = sphere_vol(3)
352 ```
353
354 ## kotlin
355
356 ```kotlin
357 package org.kotlinlang.play
358
359 fun main() {
360 println("Hello, World!")
361 }
362 ```
363
364 ## less
365
366 ```less
367 @import 'fruits';
368
369 @rhythm: 1.5em;
370
371 @media screen and (min-resolution: 2dppx) {
372 body {
373 font-size: 125%;
374 }
375 }
376
377 section > .foo + #bar:hover [href*='less'] {
378 margin: @rhythm 0 0 @rhythm;
379 padding: calc(5% + 20px);
380 background: #f00ba7 url(http://placehold.alpha-centauri/42.png) no-repeat;
381 background-image: linear-gradient(-135deg, wheat, fuchsia) !important ;
382 background-blend-mode: multiply;
383 }
384
385 @font-face {
386 font-family: /* ? */ 'Omega';
387 src: url('../fonts/omega-webfont.woff?v=2.0.2');
388 }
389
390 .icon-baz::before {
391 display: inline-block;
392 font-family: 'Omega', Alpha, sans-serif;
393 content: '\f085';
394 color: rgba(98, 76 /* or 54 */, 231, 0.75);
395 }
396 ```
397
398 ## lua
399
400 ```lua
401 --[[
402 Simple signal/slot implementation
403 ]]
404 local signal_mt = {
405 __index = {
406 register = table.insert
407 }
408 }
409 function signal_mt.__index:emit(... --[[ Comment in params ]])
410 for _, slot in ipairs(self) do
411 slot(self, ...)
412 end
413 end
414 local function create_signal()
415 return setmetatable({}, signal_mt)
416 end
417
418 -- Signal test
419 local signal = create_signal()
420 signal:register(function(signal, ...)
421 print(...)
422 end)
423 signal:emit('Answer to Life, the Universe, and Everything:', 42)
424
425 --[==[ [=[ [[
426 Nested ]]
427 multi-line ]=]
428 comment ]==]
429 [==[ Nested
430 [=[ multi-line
431 [[ string
432 ]] ]=] ]==]
433 ```
434
435 ## makefile
436
437 ```makefile
438 # Makefile
439
440 BUILDDIR = _build
441 EXTRAS ?= $(BUILDDIR)/extras
442
443 .PHONY: main clean
444
445 main:
446 @echo "Building main facility..."
447 build_main $(BUILDDIR)
448
449 clean:
450 rm -rf $(BUILDDIR)/*
451
452 ```
453
454 ## markdown
455
456 ```markdown
457 # hello world
458
459 you can write text [with links](http://example.com) inline or [link references][1].
460
461 - one _thing_ has *em*phasis
462 - two **things** are **bold**
463
464 [1]: http://example.com
465
466 ---
467
468 # hello world
469
470 <this_is inline="xml"></this_is>
471
472 > markdown is so cool
473
474 so are code segments
475
476 1. one thing (yeah!)
477 2. two thing `i can write code`, and `more` wipee!
478 ```
479
480 ## nginx
481
482 ```nginx
483 user www www;
484 worker_processes 2;
485 pid /var/run/nginx.pid;
486 error_log /var/log/nginx.error_log debug | info | notice | warn | error | crit;
487
488 events {
489 connections 2000;
490 use kqueue | rtsig | epoll | /dev/poll | select | poll;
491 }
492
493 http {
494 log_format main '$remote_addr - $remote_user [$time_local] '
495 '"$request" $status $bytes_sent '
496 '"$http_referer" "$http_user_agent" '
497 '"$gzip_ratio"';
498
499 send_timeout 3m;
500 client_header_buffer_size 1k;
501
502 gzip on;
503 gzip_min_length 1100;
504
505 #lingering_time 30;
506
507 server {
508 server_name one.example.com www.one.example.com;
509 access_log /var/log/nginx.access_log main;
510
511 rewrite (.*) /index.php?page=$1 break;
512
513 location / {
514 proxy_pass http://127.0.0.1/;
515 proxy_redirect off;
516 proxy_set_header Host $host;
517 proxy_set_header X-Real-IP $remote_addr;
518 charset koi8-r;
519 }
520
521 location /api/ {
522 fastcgi_pass 127.0.0.1:9000;
523 }
524
525 location ~* \.(jpg|jpeg|gif)$ {
526 root /spool/www;
527 }
528 }
529 }
530 ```
531
532 ## nim
533
534 ```nim
535 from strutils import `%`
536
537 const numDoors = 100
538 var doors {.compileTime.}: array[1..numDoors, bool]
539
540 proc calcDoors(): string =
541 for pass in 1..numDoors:
542 for door in countup(pass, numDoors, pass):
543 doors[door] = not doors[door]
544 for door in 1..numDoors:
545 result.add("Door $1 is $2.\n" % [$door, if doors[door]: "open" else: "closed"])
546
547 const outputString: string = calcDoors()
548
549 echo outputString
550 ```
551
552 ## objectivec
553
554 ```objectivec
555 #import <Foundation/Foundation.h>
556
557 int main(int argc, const char * argv[]) {
558 @mylak {
559 NSLog(@"Hello World!");
560 }
561 return 0;
562 }
563
564 ```
565
566 ## nix
567
568 ```nix
569 let
570 world = "World!";
571 in
572 "Hello " + world
573 ```
574
575 ## perl
576
577 ```perl
578 print "Hello World!\n";
579 ```
580
581 ## php
582
583 ```php
584 <?php
585 echo "Hello World!";
586 ?>
587 ```
588
589 ## plaintext
590
591 ```plaintext
592 I think this is simply plain text?
593 Hello World!
594 ```
595
596 ## properties
597
598 ```properties
599 # .properties
600 ! Exclamation mark = comments, too
601
602 key1 = value1
603 key2 : value2
604 key3 value3
605 key\ spaces multiline\
606 value4
607 empty_key
608 ! Key can contain escaped chars
609 \:\= = value5
610 ```
611
612 ## python
613
614 ```python
615 @requires_authorization(roles=["ADMIN"])
616 def somefunc(param1='', param2=0):
617 r'''A docstring'''
618 if param1 > param2: # interesting
619 print 'Gre\'ater'
620 return (param2 - param1 + 1 + 0b10l) or None
621
622 class SomeClass:
623 pass
624
625 >>> message = '''interpreter
626 ... prompt'''
627 ```
628
629 ## r
630
631 ```r
632 require(stats)
633
634 #' Compute different averages
635 #'
636 #' @param x \code{numeric} vector of sample data
637 #' @param type \code{character} vector of length 1 specifying the average type
638 #' @return \code{centre} returns the sample average according to the chosen method.
639 #' @examples
640 #' centre(rcauchy(10), "mean")
641 #' @export
642 centre <- function(x, type) {
643 switch(type,
644 mean = mean(x),
645 median = median(x),
646 trimmed = mean(x, trim = .1))
647 }
648 x <- rcauchy(10)
649 centre(x, "mean")
650
651 library(ggplot2)
652
653 models <- tibble::tribble(
654 ~model_name, ~ formula,
655 "length-width", Sepal.Length ~ Petal.Width + Petal.Length,
656 "interaction", Sepal.Length ~ Petal.Width * Petal.Length
657 )
658
659 iris %>%
660 nest_by(Species) %>%
661 left_join(models, by = character()) %>%
662 rowwise(Species, model_name) %>%
663 mutate(model = list(lm(formula, data = data))) %>%
664 summarise(broom::glance(model))
665 ```
666
667 ## ruby
668
669 ```ruby
670 # The Greeter class
671 class Greeter
672 def initialize(name)
673 @name = name.capitalize
674 end
675
676 def salute
677 puts "Hello #{@name}!"
678 end
679 end
680
681 g = Greeter.new("world")
682 g.salute
683 ```
684
685 ## rust
686
687 ```rust
688 fn main()->(){
689 println!("Hello World!");
690 }
691 ```
692
693 ## scala
694
695 ```scala
696 /**
697 * A person has a name and an age.
698 */
699 case class Person(name: String, age: Int)
700
701 abstract class Vertical extends CaseJeu
702 case class Haut(a: Int) extends Vertical
703 case class Bas(name: String, b: Double) extends Vertical
704
705 sealed trait Ior[+A, +B]
706 case class Left[A](a: A) extends Ior[A, Nothing]
707 case class Right[B](b: B) extends Ior[Nothing, B]
708 case class Both[A, B](a: A, b: B) extends Ior[A, B]
709
710 trait Functor[F[_]] {
711 def map[A, B](fa: F[A], f: A => B): F[B]
712 }
713
714 // beware Int.MinValue
715 def absoluteValue(n: Int): Int =
716 if (n < 0) -n else n
717
718 def interp(n: Int): String =
719 s"there are $n ${color} balloons.\n"
720
721 type ξ[A] = (A, A)
722
723 trait Hist { lhs =>
724 def ⊕(rhs: Hist): Hist
725 }
726
727 def gsum[A: Ring](as: Seq[A]): A =
728 as.foldLeft(Ring[A].zero)(_ + _)
729
730 val actions: List[Symbol] =
731 'init :: 'read :: 'write :: 'close :: Nil
732 ```
733
734 ## scss
735
736 ```scss
737 import "compass/reset";
738
739 // variables
740 $colorGreen: #008000;
741 $colorGreenDark: darken($colorGreen, 10);
742
743 @mixin container {
744 max-width: 980px;
745 }
746
747 // mixins with parameters
748 @mixin button($color:green) {
749 @if ($color == green) {
750 background-color: #008000;
751 }
752 @else if ($color == red) {
753 background-color: #B22222;
754 }
755 }
756
757 button {
758 @include button(red);
759 }
760
761 div,
762 .navbar,
763 #header,
764 input[type="input"] {
765 font-family: "Helvetica Neue", Arial, sans-serif;
766 width: auto;
767 margin: 0 auto;
768 display: block;
769 }
770
771 .row-12 > [class*="spans"] {
772 border-left: 1px solid #B5C583;
773 }
774
775 ```
776
777 ## shell
778
779 ```shell
780 $ echo $EDITOR
781 vim
782 $ git checkout main
783 Switched to branch 'main'
784 Your branch is up-to-date with 'origin/main'.
785 $ git push
786 Everything up-to-date
787 $ echo 'All
788 > done!'
789 All
790 done!
791
792 ```
793
794 ## sql
795
796 ```sql
797 CREATE TABLE "topic" (
798 "id" integer NOT NULL PRIMARY KEY,
799 "forum_id" integer NOT NULL,
800 "subject" varchar(255) NOT NULL
801 );
802 ALTER TABLE "topic"
803 ADD CONSTRAINT forum_id FOREIGN KEY ("forum_id")
804 REFERENCES "forum" ("id");
805
806 -- Initials
807 insert into "topic" ("forum_id", "subject")
808 values (2, 'D''artagnian');
809 ```
810
811 ## swift
812
813 ```swift
814 import Foundation
815
816 @objc class Person: Entity {
817 var name: String!
818 var age: Int!
819
820 init(name: String, age: Int) {
821 /* /* ... */ */
822 }
823
824 // Return a descriptive string for this person
825 func description(offset: Int = 0) -> String {
826 return "\(name) is \(age + offset) years old"
827 }
828 }
829 ```
830
831 ## typescript
832
833 ```typescript
834 class MyClass {
835 public static myValue: string;
836 constructor(init: string) {
837 this.myValue = init;
838 }
839 }
840 import fs = require("fs");
841 module MyModule {
842 export interface MyInterface extends Other {
843 myProperty: any;
844 }
845 }
846 declare magicNumber number;
847 myArray.forEach(() => { }); // fat arrow syntax
848
849 ```
850
851 ## x86asm
852
853 ```x86asm
854 section .text
855 extern _MessageBoxA@16
856 %if __NASM_VERSION_ID__ >= 0x02030000
857 safeseh handler ; register handler as "safe handler"
858 %endif
859
860 handler:
861 push dword 1 ; MB_OKCANCEL
862 push dword caption
863 push dword text
864 push dword 0
865 call _MessageBoxA@16
866 sub eax,1 ; incidentally suits as return value
867 ; for exception handler
868 ret
869
870 global _main
871 _main: push dword handler
872 push dword [fs:0]
873 mov dword [fs:0], esp
874 xor eax,eax
875 mov eax, dword[eax] ; cause exception
876 pop dword [fs:0] ; disengage exception handler
877 add esp, 4
878 ret
879
880 avx2: vzeroupper
881 push rbx
882 mov rbx, rsp
883 sub rsp, 0h20
884 vmovdqa ymm0, [rcx]
885 vpaddb ymm0, [rdx]
886 leave
887 ret
888
889 text: db 'OK to rethrow, CANCEL to generate core dump',0
890 caption:db 'SEGV',0
891
892 section .drectve info
893 db '/defaultlib:user32.lib /defaultlib:msvcrt.lib '
894 ```
895
896 ## xml
897
898 ```xml
899 <!DOCTYPE html>
900 <title>Title</title>
901
902 <style>body {width: 500px;}</style>
903
904 <script type="application/javascript">
905 function $init() {return true;}
906 </script>
907
908 <body>
909 <p checked class="title" id='title'>Title</p>
910 <!-- here goes the rest of the page -->
911 </body>
912 ```
913
914 ## yaml
915
916 ```yaml
917 ---
918 # comment
919 string_1: "Bar"
920 string_2: 'bar'
921 string_3: bar
922 inline_keys_ignored: sompath/name/file.jpg
923 keywords_in_yaml:
924 - true
925 - false
926 - TRUE
927 - FALSE
928 - 21
929 - 21.0
930 - !!str 123
931 "quoted_key": &foobar
932 bar: foo
933 foo:
934 "foo": bar
935
936 reference: *foobar
937
938 multiline_1: |
939 Multiline
940 String
941 multiline_2: >
942 Multiline
943 String
944 multiline_3: "
945 Multiline string
946 "
947
948 ansible_variables: "foo {{variable}}"
949
950 array_nested:
951 - a
952 - b: 1
953 c: 2
954 - b
955 - comment
956 ```