Browse Source

gcode source highlight. multi-lang tweaks.

Thomas Buck 1 year ago
parent
commit
2886c6f1fe
4 changed files with 30 additions and 10 deletions
  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 View File

2
 post: Improved syntax highlighting on my website
2
 post: Improved syntax highlighting on my website
3
 description: Getting to know SHJS and GNU source-highlight
3
 description: Getting to know SHJS and GNU source-highlight
4
 date: 2022-06-12
4
 date: 2022-06-12
5
+update: 2022-11-10
5
 comments: true
6
 comments: true
6
 ---
7
 ---
7
 
8
 
81
 That's it, worked flawlessly!
82
 That's it, worked flawlessly!
82
 Now I have some nicer ini file syntax highlighting.
83
 Now I have some nicer ini file syntax highlighting.
83
 And this was a fun little exercise for sunday morning!
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 View File

95
     if lang != "":
95
     if lang != "":
96
         if p.get("title_" + lang, "") != "":
96
         if p.get("title_" + lang, "") != "":
97
             title = p.get("title_" + lang, "")
97
             title = p.get("title_" + lang, "")
98
-    if p.title == "Blog":
98
+    if title == "Blog":
99
         title = p.post
99
         title = p.post
100
 
100
 
101
     year = p.get("date", "")[0:4]
101
     year = p.get("date", "")[0:4]
142
         printMenuItem(p, False, False, False, True, "0", "", False)
142
         printMenuItem(p, False, False, False, True, "0", "", False)
143
 
143
 
144
 def printBlogMenu():
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
     posts.sort(key=lambda p: p.get("date", "9999-01-01"), reverse=True)
146
     posts.sort(key=lambda p: p.get("date", "9999-01-01"), reverse=True)
147
     lastyear = "0"
147
     lastyear = "0"
148
     for p in posts:
148
     for p in posts:
375
                                     else p["title"]
375
                                     else p["title"]
376
             # Keep track of the current lang of the virtual page
376
             # Keep track of the current lang of the virtual page
377
             vp["lang"] = lang
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
             page_vpages[lang] = vp
378
             page_vpages[lang] = vp
385
 
379
 
386
         # Each virtual page has to know about its sister vpages
380
         # Each virtual page has to know about its sister vpages

+ 8
- 2
page.html View File

78
                     else:
78
                     else:
79
                         print "<h1>%s</h1>" % (page.get("title", ""))
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
                 if page.get("date", "") != "":
90
                 if page.get("date", "") != "":
85
                     if page.get("title", "") == "Blog":
91
                     if page.get("title", "") == "Blog":

+ 1
- 0
static/js/sh/sh_gcode.min.js View File

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…
Cancel
Save