Syntax 语法高亮

wtdf

支持以下几种语言语法高亮:

html, css, clike, js, bash, c, cpp, Django/jinjia, java, http, less, json, markdown, makefile, php, nginx, vim, typescript, sql, scss/sass, ruby, python, react jsx, reStructuredText, yaml, toml, rust

HTML:

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
</body>
</html>

Jinja/Django(django):

{% macro form_field(field) -%}
    {{ field }}
    {%- if field.errors %}
        {% for error in field.errors %}
            <span class="form-tip">{{ error }}</span> {% if not loop.last %} / {% endif %}
        {% endfor %}
    {% endif %}
{%- endmacro %}

CSS:

header {
    line-height: 48px;
}

JavaScript(js):

function reset(type) {
    let content = ls.get(type)
    if (content) {
        val(`#input-${type}`, content)
    }
}

Bash:

# 打开文件test.data以供读取
exec 6<test.data
# 读文件直到文件尾
while read -u 6 dta
do
echo "$dta"
done
# 关闭文件test.data
exec 6<&-

C:

#include <stdio.h>

int main(void)
{
    printf("Hello, world!\n");
    return 0;
}

C++(cpp):

#include <iostream>
using namespace std;
int main() {
    cout << "Hello, world!" << endl;
    return 0;
}

class Car {
private:
    int isRunning;
public:
    Run();
};

Python(py):

def jsvalue(val):
    if val is True:
        return 'true'
    if val is False:
        return 'false'
    return 'null'

Rust:

fn main() {
    println!("Hello, world!");
}

Java:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Prints the string to the console.
    }
}

Ruby:

# The famous Hello World
# Program is trivial in
# Ruby. Superfluous:
#
# * A "main" method
# * Newline
# * Semicolons
#
# Here is the Code:

puts "Hello World!"

HTTP:

HTTP/1.1 200 OK
Content-Disposition: attachment; filename=httpie-master.tar.gz
Content-Length: 257336
Content-Type: application/x-gzip

Downloading 251.30 kB to "httpie-master.tar.gz"
Done. 251.30 kB in 2.73862s (91.76 kB/s)

JSON:

[
   { "颜色": "红", "尺码": "大", "型号": "A", "skuId": "3158054" },
   { "颜色": "白", "尺码": "中", "型号": "B", "skuId": "3133859" },
   { "颜色": "蓝", "尺码": "小", "型号": "C", "skuId": "3516833" }
]

markdown:

# 标题一

## 标题二

### 标题三

* HTML 超文本传输协议
* CSS 层叠样式表
* JavaScript 脚本

PHP:

<?php
    echo 'Hello World!';
?>

React JSX(jsx):

ReactDOM.render(
    <MyComponent name="comp1">
        <Title name="Hello World" />
    </MyComponent>,
    document.body
)

reStructuredText(rest):

- A bullet list item
- Second item

  - A sub item

- Spacing between items creates separate lists

- Third item

1) An enumerated list item

2) Second item

3) Third item

#) Another enumerated list item

#) Second item

yaml:

---
receipt:     Oz-Ware Purchase Invoice
date:        2012-08-06
customer:
    given:   Dorothy
    family:  Gale
   
items:
    - part_no:   A4786
      descrip:   Water Bucket (Filled)
      price:     1.47
      quantity:  4

    - part_no:   E1628
      descrip:   High Heeled "Ruby" Slippers
      size:      8
      price:     133.7
      quantity:  1

toml:

# This is a TOML document.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true

[servers]

  # Indentation (tabs and/or spaces) is allowed but not required
  [servers.alpha]
  ip = "10.0.0.1"
  dc = "eqdc10"

  [servers.beta]
  ip = "10.0.0.2"
  dc = "eqdc10"

Nginx:

user  www www;
worker_processes  2;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    use epoll;
    worker_connections  2048;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    # tcp_nopush     on;

    keepalive_timeout  65;
}

VIM:

" General {{{
filetype indent plugin on
set nocompatible
set nobackup
set noswapfile
set history=2048
set autochdir
set whichwrap=b,s,<,>,[,]
set matchpairs+=<:>,「:」,“:”,『:』
set wrap
set nobomb
set backspace=indent,eol,start whichwrap+=<,>,[,]
" Vim 的默认寄存器和系统剪贴板共享
set clipboard+=unnamed
" 设置 alt 键不映射到菜单栏
set winaltkeys=no
A