@rip-lang/print 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +2 -2
- package/print.rip +7 -1
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rip-lang/print",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Syntax-highlighted source code printer — highlight.js-powered, serves once, auto-opens browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "print.rip",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"author": "Steve Shreeve <steve.shreeve@gmail.com>",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"rip-lang": "^3.
|
|
32
|
+
"rip-lang": "^3.12.0",
|
|
33
33
|
"highlight.js": "^11.11.1"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
package/print.rip
CHANGED
|
@@ -195,6 +195,12 @@ def stripTopComments(code)
|
|
|
195
195
|
def escapeHtml(str)
|
|
196
196
|
str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
197
197
|
|
|
198
|
+
def rehighlightRipScripts(html)
|
|
199
|
+
html.replace /("text\/rip"[\s\S]*?><\/span>)<span class="language-\w+">([\s\S]*?)<\/span>(<span class="hljs-tag">)/g, (match, before, inner, after) ->
|
|
200
|
+
plain = inner.replace(/<\/?span[^>]*>/g, '').replace(/'/g, "'").replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&')
|
|
201
|
+
rip = hljs.highlight(plain, { language: 'rip' }).value
|
|
202
|
+
"#{before}<span class=\"language-rip\">#{rip}</span>#{after}"
|
|
203
|
+
|
|
198
204
|
def highlightCode(code, lang)
|
|
199
205
|
highlighted = null
|
|
200
206
|
try
|
|
@@ -204,8 +210,8 @@ def highlightCode(code, lang)
|
|
|
204
210
|
catch
|
|
205
211
|
# fall through
|
|
206
212
|
highlighted ?= escapeHtml code
|
|
213
|
+
highlighted = rehighlightRipScripts(highlighted) if lang is 'html' or lang is 'xml'
|
|
207
214
|
|
|
208
|
-
# Add line numbers (fixed 4-digit width for consistent gutter)
|
|
209
215
|
lines = highlighted.split('\n')
|
|
210
216
|
numbered = lines.map (line, i) ->
|
|
211
217
|
num = String(i + 1).padStart(4)
|