File size: 1,185 Bytes
036b3a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
hljs.registerLanguage("python-custom", (hljs) => {
  var python = hljs.getLanguage("python");

  python.name = "Python Custom";

  python.contains.push({
    className: "decorator",
    begin: "/@/",
    end: "/$/",
    contains: [
      {
        className: "symbol",
        match: "@",
      },
      {
        className: "name",
        begin: /[\w\.]+/,
      },
      {
        className: "params",
        begin: /\(/,
        end: /\)/,
      },
    ],
  });

  var yellowTokens = {
    className: "yellow-char",
    begin: /\*/,
  };
  var whiteTokens = {
    className: "white-char",
    begin: /[,.:()@]/,
  };
  var attributeTokens = {
    className: "attribute",
    begin: /\./,
    end: /[\w]+/,
    contains: [
      {
        begin: /\w+/,
        className: "attr-name",
      },
    ],
  };

  // Remove id from built-in keywords
  python.keywords.built_in = python.keywords.built_in.filter(
    (el) => el !== `id`
  );

  // Ensure custom rules are applied at the beginning
  python.contains.push(whiteTokens);
  python.contains.push(attributeTokens);
  python.contains.push(yellowTokens);

  return python;
});

hljs.highlightAll();
hljs.initLineNumbersOnLoad();