瀏覽代碼

gcode source highlight. multi-lang tweaks.

Thomas Buck 2 年之前
父節點
當前提交
2886c6f1fe
共有 4 個檔案被更改,包括 30 行新增10 行删除
  1. 19
    0
      input/blog/2022/2022_06_12_shjs_ini.md
  2. 2
    8
      macros.py
  3. 8
    2
      page.html
  4. 1
    0
      static/js/sh/sh_gcode.min.js

+ 19
- 0
input/blog/2022/2022_06_12_shjs_ini.md 查看文件

@@ -2,6 +2,7 @@ title: Blog
2 2
 post: Improved syntax highlighting on my website
3 3
 description: Getting to know SHJS and GNU source-highlight
4 4
 date: 2022-06-12
5
+update: 2022-11-10
5 6
 comments: true
6 7
 ---
7 8
 
@@ -81,3 +82,21 @@ $ java -jar ~/bin/yuicompressor-2.4.8.jar desktop_test.lang.js > desktop_test.la
81 82
 That's it, worked flawlessly!
82 83
 Now I have some nicer ini file syntax highlighting.
83 84
 And this was a fun little exercise for sunday morning!
85
+
86
+**Update** from November 2022:
87
+
88
+I also added [YAML](https://gist.githubusercontent.com/AlexZeitler/48813447f253360ccc431ae22d6939fd/raw/1c1d9372cce5fb2b568b2dd953d334ef8fe3f33d/yaml.lang), for which I found a ready-made language definition file by AlexZeitler.
89
+
90
+And I added support for G-Code by making my own language definition, [based on this](https://github.com/PrismJS/prism/blob/master/components/prism-gcode.js):
91
+
92
+<pre>
93
+# highlighting for CNC G-Code
94
+# based on https://github.com/PrismJS/prism/blob/master/components/prism-gcode.js
95
+
96
+comment = `;.*|\B\(.*?\)\B`
97
+string = `"(?:""|[^"])*"`
98
+keyword = `\b[GM]\d+(?:\.\d+)?\b`
99
+function = `\b[A-Z]`
100
+number = `(\*)\d+`
101
+label = `[:*]`
102
+</pre>

+ 2
- 8
macros.py 查看文件

@@ -95,7 +95,7 @@ def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStart
95 95
     if lang != "":
96 96
         if p.get("title_" + lang, "") != "":
97 97
             title = p.get("title_" + lang, "")
98
-    if p.title == "Blog":
98
+    if title == "Blog":
99 99
         title = p.post
100 100
 
101 101
     year = p.get("date", "")[0:4]
@@ -142,7 +142,7 @@ def printRecentMenu(count = 5):
142 142
         printMenuItem(p, False, False, False, True, "0", "", False)
143 143
 
144 144
 def printBlogMenu():
145
-    posts = [p for p in pages if "post" in p]
145
+    posts = [p for p in pages if "post" in p and p.lang == "en"]
146 146
     posts.sort(key=lambda p: p.get("date", "9999-01-01"), reverse=True)
147 147
     lastyear = "0"
148 148
     for p in posts:
@@ -375,12 +375,6 @@ def hook_preconvert_anotherlang():
375 375
                                     else p["title"]
376 376
             # Keep track of the current lang of the virtual page
377 377
             vp["lang"] = lang
378
-            # Fix post name if exists
379
-            if vp.has_key("post"):
380
-                if lang == "en":
381
-                    vp["post"] = vp["post"][:]
382
-                else:
383
-                    vp["post"] = vp["post"][:-len(lang) - 1]
384 378
             page_vpages[lang] = vp
385 379
 
386 380
         # Each virtual page has to know about its sister vpages

+ 8
- 2
page.html 查看文件

@@ -78,8 +78,14 @@ else:
78 78
                     else:
79 79
                         print "<h1>%s</h1>" % (page.get("title", ""))
80 80
 
81
-                if page.get("description", "") != "":
82
-                    print "<h5>%s</h5>" % (page.get("description", ""))
81
+                if page.get("lang", "en") == "de":
82
+                    if page.get("description_de", "") != "":
83
+                        print "<h5>%s</h5>" % (page.get("description_de", ""))
84
+                    elif page.get("description", "") != "":
85
+                        print "<h5>%s</h5>" % (page.get("description", ""))
86
+                else:
87
+                    if page.get("description", "") != "":
88
+                        print "<h5>%s</h5>" % (page.get("description", ""))
83 89
 
84 90
                 if page.get("date", "") != "":
85 91
                     if page.get("title", "") == "Blog":

+ 1
- 0
static/js/sh/sh_gcode.min.js 查看文件

@@ -0,0 +1 @@
1
+if(!this.sh_languages){this.sh_languages={}}sh_languages.gcode=[[[/;.*|\B\(.*?\)\B/g,"sh_comment",-1],[/"(?:""|[^"])*"/g,"sh_string",-1],[/\b[GM]\d+(?:\.\d+)?\b/g,"sh_keyword",-1],[/\b[A-Z]/g,"sh_function",-1],[/(\*)\d+/g,"sh_number",-1],[/[:*]/g,"sh_label",-1]]];

Loading…
取消
儲存