bare-script 4.1.4__tar.gz → 4.1.8__tar.gz
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.
- {bare_script-4.1.4/src/bare_script.egg-info → bare_script-4.1.8}/PKG-INFO +1 -1
- {bare_script-4.1.4 → bare_script-4.1.8}/setup.cfg +1 -1
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/markdownElements.bare +72 -64
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/markdownHighlight.bare +76 -85
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/markdownParser.bare +121 -98
- {bare_script-4.1.4 → bare_script-4.1.8/src/bare_script.egg-info}/PKG-INFO +1 -1
- {bare_script-4.1.4 → bare_script-4.1.8}/LICENSE +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/README.md +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/pyproject.toml +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/setup.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/__init__.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/__main__.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/bare.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/__init__.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/args.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/baredoc.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/baredocCLI.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/data.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/dataLineChart.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/dataTable.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/dataUtil.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/diff.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/draw.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/elementModel.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/forms.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/markdown.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/markdownUp.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/pager.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/qrcode.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/schemaDoc.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/unittest.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/include/unittestMock.bare +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/library.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/model.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/options.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/parser.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/runtime.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/runtime_c.c +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script/value.py +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script.egg-info/SOURCES.txt +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script.egg-info/dependency_links.txt +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script.egg-info/entry_points.txt +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script.egg-info/requires.txt +0 -0
- {bare_script-4.1.4 → bare_script-4.1.8}/src/bare_script.egg-info/top_level.txt +0 -0
|
@@ -72,28 +72,30 @@ endfunction
|
|
|
72
72
|
|
|
73
73
|
# Helper function to generate an element model from a markdown part
|
|
74
74
|
function markdownElementsPartElements(part, options, usedHeaderIds):
|
|
75
|
-
partKey = arrayGet(objectKeys(part), 0)
|
|
76
|
-
|
|
77
75
|
# List?
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
list = objectGet(part, 'list')
|
|
77
|
+
if list:
|
|
80
78
|
listItemElements = []
|
|
81
|
-
for item in items:
|
|
79
|
+
for item in objectGet(list, 'items'):
|
|
82
80
|
itemElements = markdownElementsPartsElements(objectGet(item, 'parts'), options, usedHeaderIds)
|
|
83
81
|
arrayPush(listItemElements, {'html': 'li', 'elem': itemElements})
|
|
84
82
|
endfor
|
|
85
83
|
return markdownElementsListPartElements(part, listItemElements)
|
|
84
|
+
endif
|
|
86
85
|
|
|
87
86
|
# Block quote?
|
|
88
|
-
|
|
87
|
+
quote = objectGet(part, 'quote')
|
|
88
|
+
if quote:
|
|
89
89
|
return { \
|
|
90
90
|
'html': 'blockquote', \
|
|
91
|
-
'elem': markdownElementsPartsElements(objectGet(
|
|
91
|
+
'elem': markdownElementsPartsElements(objectGet(quote, 'parts'), options, usedHeaderIds) \
|
|
92
92
|
}
|
|
93
|
+
endif
|
|
93
94
|
|
|
94
95
|
# Code block?
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
codeBlock = objectGet(part, 'codeBlock')
|
|
97
|
+
if codeBlock:
|
|
98
|
+
return markdownHighlightCodeBlockElements(codeBlock, options)
|
|
97
99
|
endif
|
|
98
100
|
|
|
99
101
|
return markdownElementsPartElementsBase(part, options, usedHeaderIds)
|
|
@@ -124,28 +126,30 @@ endfunction
|
|
|
124
126
|
|
|
125
127
|
# Helper function to generate an element model from a markdown part
|
|
126
128
|
async function markdownElementsPartElementsAsync(part, options, usedHeaderIds):
|
|
127
|
-
partKey = arrayGet(objectKeys(part), 0)
|
|
128
|
-
|
|
129
129
|
# List?
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
list = objectGet(part, 'list')
|
|
131
|
+
if list:
|
|
132
132
|
listItemElements = []
|
|
133
|
-
for item in items:
|
|
133
|
+
for item in objectGet(list, 'items'):
|
|
134
134
|
itemElements = markdownElementsPartsElementsAsync(objectGet(item, 'parts'), options, usedHeaderIds)
|
|
135
135
|
arrayPush(listItemElements, {'html': 'li', 'elem': itemElements})
|
|
136
136
|
endfor
|
|
137
137
|
return markdownElementsListPartElements(part, listItemElements)
|
|
138
|
+
endif
|
|
138
139
|
|
|
139
140
|
# Block quote?
|
|
140
|
-
|
|
141
|
+
quote = objectGet(part, 'quote')
|
|
142
|
+
if quote:
|
|
141
143
|
return { \
|
|
142
144
|
'html': 'blockquote', \
|
|
143
|
-
'elem': markdownElementsPartsElementsAsync(objectGet(
|
|
145
|
+
'elem': markdownElementsPartsElementsAsync(objectGet(quote, 'parts'), options, usedHeaderIds) \
|
|
144
146
|
}
|
|
147
|
+
endif
|
|
145
148
|
|
|
146
149
|
# Code block?
|
|
147
|
-
|
|
148
|
-
|
|
150
|
+
codeBlock = objectGet(part, 'codeBlock')
|
|
151
|
+
if codeBlock:
|
|
152
|
+
return markdownHighlightCodeBlockElementsAsync(codeBlock, options)
|
|
149
153
|
endif
|
|
150
154
|
|
|
151
155
|
return markdownElementsPartElementsBase(part, options, usedHeaderIds)
|
|
@@ -165,12 +169,11 @@ endfunction
|
|
|
165
169
|
|
|
166
170
|
# Helper function to generate an element model from a non-list/quote/codeBlock part
|
|
167
171
|
function markdownElementsPartElementsBase(part, options, usedHeaderIds):
|
|
168
|
-
partKey = arrayGet(objectKeys(part), 0)
|
|
169
|
-
|
|
170
172
|
# Paragraph?
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
paragraph = objectGet(part, 'paragraph')
|
|
174
|
+
if paragraph:
|
|
175
|
+
paragraphStyle = objectGet(paragraph, 'style')
|
|
176
|
+
if paragraphStyle:
|
|
174
177
|
# Determine the header ID, if requested
|
|
175
178
|
headerId = null
|
|
176
179
|
if options && objectGet(options, 'headerIds'):
|
|
@@ -199,7 +202,7 @@ function markdownElementsPartElementsBase(part, options, usedHeaderIds):
|
|
|
199
202
|
endif
|
|
200
203
|
|
|
201
204
|
return { \
|
|
202
|
-
'html':
|
|
205
|
+
'html': paragraphStyle, \
|
|
203
206
|
'attr': if(headerId != null, {'id': headerId}, null), \
|
|
204
207
|
'elem': markdownElementsParagraphSpanElements(objectGet(paragraph, 'spans'), options) \
|
|
205
208
|
}
|
|
@@ -209,10 +212,11 @@ function markdownElementsPartElementsBase(part, options, usedHeaderIds):
|
|
|
209
212
|
'html': 'p', \
|
|
210
213
|
'elem': markdownElementsParagraphSpanElements(objectGet(paragraph, 'spans'), options) \
|
|
211
214
|
}
|
|
215
|
+
endif
|
|
212
216
|
|
|
213
217
|
# Table?
|
|
214
|
-
|
|
215
|
-
|
|
218
|
+
table = objectGet(part, 'table')
|
|
219
|
+
if table:
|
|
216
220
|
aligns = objectGet(table, 'aligns')
|
|
217
221
|
alignsLength = arrayLength(aligns)
|
|
218
222
|
|
|
@@ -269,76 +273,80 @@ endfunction
|
|
|
269
273
|
|
|
270
274
|
# Helper function to generate element models from markdown span models
|
|
271
275
|
function markdownElementsParagraphSpanElements(spans, options):
|
|
276
|
+
urlFn = if(options, objectGet(options, 'urlFn'))
|
|
272
277
|
spanElements = []
|
|
273
278
|
for span in spans:
|
|
274
|
-
spanKey = arrayGet(objectKeys(span), 0)
|
|
275
|
-
|
|
276
279
|
# Text span?
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
arrayPush(spanElements, {'html': 'br'})
|
|
280
|
+
text = objectGet(span, 'text')
|
|
281
|
+
if text:
|
|
282
|
+
arrayPush(spanElements, {'text': text})
|
|
283
|
+
continue
|
|
284
|
+
endif
|
|
283
285
|
|
|
284
286
|
# Style span?
|
|
285
|
-
|
|
286
|
-
|
|
287
|
+
style = objectGet(span, 'style')
|
|
288
|
+
if style:
|
|
287
289
|
styleStyle = objectGet(style, 'style')
|
|
288
290
|
arrayPush(spanElements, { \
|
|
289
291
|
'html': if(styleStyle == 'bold', 'strong', if(styleStyle == 'italic', 'em', 'del')), \
|
|
290
292
|
'elem': markdownElementsParagraphSpanElements(objectGet(style, 'spans'), options) \
|
|
291
293
|
})
|
|
294
|
+
continue
|
|
295
|
+
endif
|
|
292
296
|
|
|
293
297
|
# Link span?
|
|
294
|
-
|
|
295
|
-
|
|
298
|
+
link = objectGet(span, 'link')
|
|
299
|
+
if link:
|
|
296
300
|
href = objectGet(link, 'href')
|
|
297
|
-
|
|
298
|
-
# URL fixup?
|
|
299
|
-
urlFn = if(options, objectGet(options, 'urlFn'))
|
|
300
301
|
if urlFn:
|
|
301
302
|
href = urlFn(href)
|
|
302
303
|
endif
|
|
303
|
-
|
|
304
304
|
linkAttr = {'href': href}
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
linkTitle = objectGet(link, 'title')
|
|
306
|
+
if linkTitle != null:
|
|
307
|
+
objectSet(linkAttr, 'title', linkTitle)
|
|
307
308
|
endif
|
|
308
309
|
arrayPush(spanElements, { \
|
|
309
310
|
'html': 'a', \
|
|
310
311
|
'attr': linkAttr, \
|
|
311
312
|
'elem': markdownElementsParagraphSpanElements(objectGet(link, 'spans'), options) \
|
|
312
313
|
})
|
|
314
|
+
continue
|
|
315
|
+
endif
|
|
316
|
+
|
|
317
|
+
# Link reference span?
|
|
318
|
+
linkRef = objectGet(span, 'linkRef')
|
|
319
|
+
if linkRef:
|
|
320
|
+
arrayExtend(spanElements, markdownElementsParagraphSpanElements(objectGet(linkRef, 'spans'), options))
|
|
321
|
+
continue
|
|
322
|
+
endif
|
|
323
|
+
|
|
324
|
+
# Code span?
|
|
325
|
+
code = objectGet(span, 'code')
|
|
326
|
+
if code:
|
|
327
|
+
arrayPush(spanElements, {'html': 'code', 'elem': {'text': code}})
|
|
328
|
+
continue
|
|
329
|
+
endif
|
|
313
330
|
|
|
314
331
|
# Image span?
|
|
315
|
-
|
|
316
|
-
|
|
332
|
+
image = objectGet(span, 'image')
|
|
333
|
+
if image:
|
|
317
334
|
src = objectGet(image, 'src')
|
|
318
|
-
|
|
319
|
-
# URL fixup?
|
|
320
|
-
urlFn = if(options, objectGet(options, 'urlFn'))
|
|
321
335
|
if urlFn:
|
|
322
336
|
src = urlFn(src)
|
|
323
337
|
endif
|
|
324
|
-
|
|
325
338
|
imageAttr = {'src': src, 'alt': objectGet(image, 'alt'), 'style': 'max-width: 100%;'}
|
|
326
|
-
|
|
327
|
-
|
|
339
|
+
imageTitle = objectGet(image, 'title')
|
|
340
|
+
if imageTitle != null:
|
|
341
|
+
objectSet(imageAttr, 'title', imageTitle)
|
|
328
342
|
endif
|
|
329
|
-
arrayPush(spanElements, {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
# Link reference span?
|
|
335
|
-
elif spanKey == 'linkRef':
|
|
336
|
-
linkRef = objectGet(span, 'linkRef')
|
|
337
|
-
arrayExtend(spanElements, markdownElementsParagraphSpanElements(objectGet(linkRef, 'spans'), options))
|
|
343
|
+
arrayPush(spanElements, {'html': 'img', 'attr': imageAttr})
|
|
344
|
+
continue
|
|
345
|
+
endif
|
|
338
346
|
|
|
339
|
-
#
|
|
340
|
-
|
|
341
|
-
arrayPush(spanElements, {'html': '
|
|
347
|
+
# Line break?
|
|
348
|
+
if objectGet(span, 'br'):
|
|
349
|
+
arrayPush(spanElements, {'html': 'br'})
|
|
342
350
|
endif
|
|
343
351
|
endfor
|
|
344
352
|
|
|
@@ -117,13 +117,11 @@ endfunction
|
|
|
117
117
|
function markdownHighlightCompileHighlightModels(highlights):
|
|
118
118
|
highlightMap = {}
|
|
119
119
|
for highlight in highlights:
|
|
120
|
-
highlightRegex = {}
|
|
121
|
-
parts = []
|
|
122
|
-
|
|
123
120
|
# Validate the highlight model (for potential debug logging)
|
|
124
121
|
schemaValidate(markdownHighlightTypes, 'MarkdownHighlight', highlight)
|
|
125
122
|
|
|
126
|
-
#
|
|
123
|
+
# Build a named-group aggregate so a single match identifies the member type via its groups dict
|
|
124
|
+
namedParts = []
|
|
127
125
|
for memberName in markdownHighlightMemberNames:
|
|
128
126
|
memberPatterns = objectGet(highlight, memberName)
|
|
129
127
|
if memberPatterns:
|
|
@@ -131,32 +129,18 @@ function markdownHighlightCompileHighlightModels(highlights):
|
|
|
131
129
|
for memberPattern in memberPatterns:
|
|
132
130
|
arrayPush(partStrs, '(?:' + memberPattern + ')')
|
|
133
131
|
endfor
|
|
134
|
-
|
|
135
|
-
memberRegex = regexNew('^(?:' + part + ')')
|
|
136
|
-
if memberRegex:
|
|
137
|
-
objectSet(highlightRegex, memberName, memberRegex)
|
|
138
|
-
arrayPush(parts, part)
|
|
139
|
-
endif
|
|
132
|
+
arrayPush(namedParts, '(?<' + memberName + '>' + arrayJoin(partStrs, '|') + ')')
|
|
140
133
|
endif
|
|
141
134
|
endfor
|
|
142
135
|
|
|
143
|
-
#
|
|
144
|
-
if
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
136
|
+
# Compile and register the language's render function
|
|
137
|
+
if namedParts:
|
|
138
|
+
highlightRegex = regexNew(arrayJoin(namedParts, '|'), 'm')
|
|
139
|
+
highlightFn = systemPartial(markdownHighlightRenderFn, highlightRegex)
|
|
140
|
+
for name in objectGet(highlight, 'names'):
|
|
141
|
+
objectSet(highlightMap, name, highlightFn)
|
|
148
142
|
endfor
|
|
149
|
-
highlightRegexAggregate = regexNew(arrayJoin(aggregateParts, '|'), 'm')
|
|
150
|
-
if highlightRegexAggregate:
|
|
151
|
-
objectSet(highlightRegex, 'highlight', highlightRegexAggregate)
|
|
152
|
-
endif
|
|
153
143
|
endif
|
|
154
|
-
|
|
155
|
-
# Add the name/alias to code block render function
|
|
156
|
-
highlightFn = systemPartial(markdownHighlightRenderFn, highlightRegex)
|
|
157
|
-
for name in objectGet(highlight, 'names'):
|
|
158
|
-
objectSet(highlightMap, name, highlightFn)
|
|
159
|
-
endfor
|
|
160
144
|
endfor
|
|
161
145
|
|
|
162
146
|
return highlightMap
|
|
@@ -179,13 +163,9 @@ endfunction
|
|
|
179
163
|
# $ignore: true
|
|
180
164
|
function markdownHighlightElements(highlightRegex, lines, options):
|
|
181
165
|
# Join the text lines
|
|
182
|
-
|
|
183
|
-
for line in lines:
|
|
184
|
-
arrayPush(textParts, if(stringEndsWith(line, '\n'), line, line + '\n'))
|
|
185
|
-
endfor
|
|
186
|
-
text = arrayJoin(textParts, '')
|
|
166
|
+
text = arrayJoin(lines, '\n') + '\n'
|
|
187
167
|
|
|
188
|
-
# The copy
|
|
168
|
+
# The copy button element
|
|
189
169
|
preAttr = null
|
|
190
170
|
copyElements = null
|
|
191
171
|
if options && objectGet(options, 'copyLinks'):
|
|
@@ -193,78 +173,89 @@ function markdownHighlightElements(highlightRegex, lines, options):
|
|
|
193
173
|
copyLinksIndex = objectGet(options, 'copyLinksIndex', 1)
|
|
194
174
|
objectSet(options, 'copyLinksIndex', copyLinksIndex + 1)
|
|
195
175
|
|
|
196
|
-
# Generate the code block ID and
|
|
176
|
+
# Generate the code block ID and copy button element
|
|
197
177
|
preID = '__markdown_copy_' + copyLinksIndex
|
|
198
|
-
preAttr = {'id': preID, 'style': 'margin-top: 0.
|
|
178
|
+
preAttr = {'id': preID, 'style': 'grid-area: 1 / 1; margin-top: 0; padding-right: 2.5em;'}
|
|
199
179
|
copyElements = { \
|
|
200
|
-
'
|
|
180
|
+
'svg': 'svg', \
|
|
201
181
|
'attr': { \
|
|
202
|
-
'
|
|
182
|
+
'width': '20', \
|
|
183
|
+
'height': '20', \
|
|
184
|
+
'viewBox': '0 0 24 24', \
|
|
185
|
+
'style': 'grid-area: 1 / 1; justify-self: end; align-self: start; margin: 0.4em; cursor: pointer; user-select: none;', \
|
|
186
|
+
'onclick': "window.navigator.clipboard.writeText(document.getElementById('" + preID + "').innerText);" \
|
|
203
187
|
}, \
|
|
204
188
|
'elem': { \
|
|
205
|
-
'
|
|
189
|
+
'svg': 'path', \
|
|
206
190
|
'attr': { \
|
|
207
|
-
'
|
|
208
|
-
|
|
209
|
-
|
|
191
|
+
'fill': 'var(--barescript-color-border)', \
|
|
192
|
+
'd': 'M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z' \
|
|
193
|
+
} \
|
|
210
194
|
} \
|
|
211
195
|
}
|
|
212
196
|
endif
|
|
213
197
|
|
|
214
|
-
#
|
|
198
|
+
# Determine the code element children
|
|
215
199
|
if !highlightRegex:
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
highlightIndex = objectGet(mHighlight, 'index')
|
|
232
|
-
|
|
233
|
-
# Add the pre-text span
|
|
234
|
-
if highlightIndex > 0:
|
|
235
|
-
arrayPush(spans, {'text': stringSlice(text, 0, highlightIndex)})
|
|
236
|
-
endif
|
|
200
|
+
# No language specified or unknown language
|
|
201
|
+
codeChildren = {'text': text}
|
|
202
|
+
else:
|
|
203
|
+
# Match the highlight spans
|
|
204
|
+
codeChildren = []
|
|
205
|
+
ixSearch = 0
|
|
206
|
+
for mHighlight in regexMatchAll(highlightRegex, text):
|
|
207
|
+
matchGroups = objectGet(mHighlight, 'groups')
|
|
208
|
+
highlightText = objectGet(matchGroups, '0')
|
|
209
|
+
highlightIndex = objectGet(mHighlight, 'index')
|
|
210
|
+
|
|
211
|
+
# Add the pre-text span
|
|
212
|
+
if ixSearch < highlightIndex:
|
|
213
|
+
arrayPush(codeChildren, {'text': stringSlice(text, ixSearch, highlightIndex)})
|
|
214
|
+
endif
|
|
237
215
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
216
|
+
# Determine the highlight style from which named group matched
|
|
217
|
+
if objectGet(matchGroups, 'builtin'):
|
|
218
|
+
attrStyle = 'color: var(--barescript-color-highlight-builtin);'
|
|
219
|
+
elif objectGet(matchGroups, 'comment'):
|
|
220
|
+
attrStyle = 'color: var(--barescript-color-highlight-comment);'
|
|
221
|
+
elif objectGet(matchGroups, 'keyword'):
|
|
222
|
+
attrStyle = 'color: var(--barescript-color-highlight-keyword);'
|
|
223
|
+
elif objectGet(matchGroups, 'literal'):
|
|
224
|
+
attrStyle = 'color: var(--barescript-color-highlight-literal);'
|
|
225
|
+
elif objectGet(matchGroups, 'preprocessor'):
|
|
226
|
+
attrStyle = 'color: var(--barescript-color-highlight-preprocessor);'
|
|
227
|
+
elif objectGet(matchGroups, 'string'):
|
|
228
|
+
attrStyle = 'color: var(--barescript-color-highlight-string);'
|
|
229
|
+
elif objectGet(matchGroups, 'tag'):
|
|
230
|
+
attrStyle = 'color: var(--barescript-color-highlight-tag);'
|
|
244
231
|
endif
|
|
245
|
-
endfor
|
|
246
232
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
233
|
+
# Add the highlight span
|
|
234
|
+
arrayPush(codeChildren, { \
|
|
235
|
+
'html': 'span', \
|
|
236
|
+
'attr': {'style': attrStyle}, \
|
|
237
|
+
'elem': {'text': highlightText} \
|
|
238
|
+
})
|
|
253
239
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
endwhile
|
|
240
|
+
ixSearch = highlightIndex + stringLength(highlightText)
|
|
241
|
+
endfor
|
|
257
242
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
243
|
+
# Add the final un-matched text
|
|
244
|
+
if ixSearch < stringLength(text):
|
|
245
|
+
arrayPush(codeChildren, {'text': stringSlice(text, ixSearch)})
|
|
246
|
+
endif
|
|
261
247
|
endif
|
|
262
248
|
|
|
263
|
-
# Create the code block
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
249
|
+
# Create the code block element, wrapping with the copy button when present
|
|
250
|
+
preElement = {'html': 'pre', 'attr': preAttr, 'elem': {'html': 'code', 'elem': codeChildren}}
|
|
251
|
+
if !copyElements:
|
|
252
|
+
return preElement
|
|
253
|
+
endif
|
|
254
|
+
return { \
|
|
255
|
+
'html': 'div', \
|
|
256
|
+
'attr': {'style': 'display: grid; margin-top: 1em;'}, \
|
|
257
|
+
'elem': [preElement, copyElements] \
|
|
258
|
+
}
|
|
268
259
|
endfunction
|
|
269
260
|
|
|
270
261
|
|
|
@@ -522,17 +522,95 @@ function markdownParserParagraphSpans(text, linkRefs):
|
|
|
522
522
|
if ixSearch < matchIndex:
|
|
523
523
|
arrayPush(spans, {'text': markdownParserRemoveEscapes(stringSlice(text, ixSearch, matchIndex), false)})
|
|
524
524
|
endif
|
|
525
|
+
ixSearch = matchIndex + stringLength(matchFullText)
|
|
525
526
|
|
|
526
|
-
#
|
|
527
|
-
|
|
528
|
-
|
|
527
|
+
# Bold style? (bold or boldu)
|
|
528
|
+
boldStr = objectGet(matchGroups, 'bold') || objectGet(matchGroups, 'boldu')
|
|
529
|
+
if boldStr:
|
|
530
|
+
boldText = stringSlice(boldStr, 2, stringLength(boldStr) - 2)
|
|
531
|
+
arrayPush(spans, {'style': {'style': 'bold', 'spans': markdownParserParagraphSpans(boldText, linkRefs)}})
|
|
532
|
+
continue
|
|
533
|
+
endif
|
|
534
|
+
|
|
535
|
+
# Italic style? (italic or italicu)
|
|
536
|
+
italicStr = objectGet(matchGroups, 'italic') || objectGet(matchGroups, 'italicu')
|
|
537
|
+
if italicStr:
|
|
538
|
+
italicText = stringSlice(italicStr, 1, stringLength(italicStr) - 1)
|
|
539
|
+
arrayPush(spans, {'style': {'style': 'italic', 'spans': markdownParserParagraphSpans(italicText, linkRefs)}})
|
|
540
|
+
continue
|
|
541
|
+
endif
|
|
542
|
+
|
|
543
|
+
# Code?
|
|
544
|
+
code = objectGet(matchGroups, 'code')
|
|
545
|
+
if code:
|
|
546
|
+
codeT = objectGet(matchGroups, 'codeT')
|
|
547
|
+
codeTLen = stringLength(codeT)
|
|
548
|
+
codeText = stringSlice(code, codeTLen, stringLength(code) - codeTLen)
|
|
549
|
+
codeScrubbed = regexReplace(markdownParserRegexCodeNewlines, codeText, ' ')
|
|
550
|
+
codeMatch = regexMatch(markdownParserRegexCodeSpaces, codeScrubbed)
|
|
551
|
+
if codeMatch:
|
|
552
|
+
codeScrubbed = objectGet(objectGet(codeMatch, 'groups'), '1')
|
|
553
|
+
endif
|
|
554
|
+
arrayPush(spans, {'code': codeScrubbed})
|
|
555
|
+
continue
|
|
556
|
+
endif
|
|
529
557
|
|
|
530
|
-
#
|
|
531
|
-
|
|
558
|
+
# Link or image?
|
|
559
|
+
link = objectGet(matchGroups, 'link')
|
|
560
|
+
if link:
|
|
561
|
+
linkResult = markdownParserGetLinkText(matchGroups, 'link')
|
|
562
|
+
linkText = arrayGet(linkResult, 0)
|
|
563
|
+
linkHref = arrayGet(linkResult, 1)
|
|
564
|
+
linkTitle = arrayGet(linkResult, 2)
|
|
565
|
+
if stringStartsWith(link, '!'):
|
|
566
|
+
arrayPush(spans, markdownParserCreateImageSpan(linkHref, linkText, linkTitle))
|
|
567
|
+
else:
|
|
568
|
+
arrayPush(spans, markdownParserCreateLinkSpan(linkHref, linkText, linkTitle, linkRefs))
|
|
569
|
+
endif
|
|
570
|
+
continue
|
|
571
|
+
endif
|
|
572
|
+
|
|
573
|
+
# Link reference?
|
|
574
|
+
linkRef = objectGet(matchGroups, 'linkRef')
|
|
575
|
+
if linkRef:
|
|
576
|
+
linkRefText = objectGet(matchGroups, 'linkRefText')
|
|
577
|
+
linkRefOtherText = objectGet(matchGroups, 'linkRefOtherText')
|
|
578
|
+
if stringStartsWith(linkRef, '!'):
|
|
579
|
+
arrayPush(spans, markdownParserCreateImageRefSpan(linkRefText, linkRefOtherText, matchFullText, linkRefs, false))
|
|
580
|
+
else:
|
|
581
|
+
arrayPush(spans, markdownParserCreateLinkRefSpan(linkRefText, linkRefOtherText, matchFullText, linkRefs, false))
|
|
582
|
+
endif
|
|
583
|
+
continue
|
|
584
|
+
endif
|
|
585
|
+
|
|
586
|
+
# Strikethrough style?
|
|
587
|
+
strike = objectGet(matchGroups, 'strike')
|
|
588
|
+
if strike:
|
|
589
|
+
strikeT = objectGet(matchGroups, 'strikeT')
|
|
590
|
+
strikeTLen = stringLength(strikeT)
|
|
591
|
+
strikeText = stringSlice(strike, strikeTLen, stringLength(strike) - strikeTLen)
|
|
592
|
+
arrayPush(spans, {'style': {'style': 'strikethrough', 'spans': markdownParserParagraphSpans(strikeText, linkRefs)}})
|
|
593
|
+
continue
|
|
594
|
+
endif
|
|
595
|
+
|
|
596
|
+
# Link (alternate syntax)?
|
|
597
|
+
linkAlt = objectGet(matchGroups, 'linkAlt')
|
|
598
|
+
if linkAlt:
|
|
599
|
+
linkAltScheme = objectGet(matchGroups, 'linkAltScheme')
|
|
600
|
+
linkAltHref = stringSlice(linkAlt, 1, stringLength(linkAlt) - 1)
|
|
601
|
+
linkHref = if(stringEndsWith(linkAltScheme, '@'), 'mailto:' + linkAltHref, linkAltHref)
|
|
602
|
+
arrayPush(spans, {'link': {'href': linkHref, 'spans': [{'text': linkHref}]}})
|
|
603
|
+
continue
|
|
604
|
+
endif
|
|
605
|
+
|
|
606
|
+
# Line break? (br or brHtml)
|
|
607
|
+
if objectGet(matchGroups, 'br') || objectGet(matchGroups, 'brHtml'):
|
|
532
608
|
arrayPush(spans, {'br': 1})
|
|
609
|
+
continue
|
|
610
|
+
endif
|
|
533
611
|
|
|
534
612
|
# Link with inline image?
|
|
535
|
-
|
|
613
|
+
if objectGet(matchGroups, 'linkImg'):
|
|
536
614
|
linkImgResult = markdownParserGetLinkText(matchGroups, 'linkImg')
|
|
537
615
|
linkImgText = arrayGet(linkImgResult, 0)
|
|
538
616
|
linkImgHref = arrayGet(linkImgResult, 1)
|
|
@@ -542,9 +620,11 @@ function markdownParserParagraphSpans(text, linkRefs):
|
|
|
542
620
|
linkImgLinkTitle = arrayGet(linkImgLinkResult, 2)
|
|
543
621
|
imgSpan = markdownParserCreateImageSpan(linkImgHref, linkImgText, linkImgTitle)
|
|
544
622
|
arrayPush(spans, markdownParserCreateLinkSpan(linkImgLinkHref, [imgSpan], linkImgLinkTitle))
|
|
623
|
+
continue
|
|
624
|
+
endif
|
|
545
625
|
|
|
546
626
|
# Link with inline image reference
|
|
547
|
-
|
|
627
|
+
if objectGet(matchGroups, 'linkImgRef'):
|
|
548
628
|
linkImgRefText = objectGet(matchGroups, 'linkImgRefText')
|
|
549
629
|
linkImgRefImgText = objectGet(matchGroups, 'linkImgRefImgText')
|
|
550
630
|
linkImgRefFull = objectGet(matchGroups, 'linkImgRefFull')
|
|
@@ -553,9 +633,11 @@ function markdownParserParagraphSpans(text, linkRefs):
|
|
|
553
633
|
linkImgRefLinkTitle = arrayGet(linkImgRefLinkResult, 2)
|
|
554
634
|
imgSpan = markdownParserCreateImageRefSpan(linkImgRefText, linkImgRefImgText, linkImgRefFull, linkRefs, true)
|
|
555
635
|
arrayPush(spans, markdownParserCreateLinkSpan(linkImgRefLinkHref, [imgSpan], linkImgRefLinkTitle))
|
|
636
|
+
continue
|
|
637
|
+
endif
|
|
556
638
|
|
|
557
639
|
# Link reference with inline image
|
|
558
|
-
|
|
640
|
+
if objectGet(matchGroups, 'linkRefImg'):
|
|
559
641
|
linkRefImgResult = markdownParserGetLinkText(matchGroups, 'linkRefImg')
|
|
560
642
|
linkRefImgText = arrayGet(linkRefImgResult, 0)
|
|
561
643
|
linkRefImgHref = arrayGet(linkRefImgResult, 1)
|
|
@@ -563,81 +645,18 @@ function markdownParserParagraphSpans(text, linkRefs):
|
|
|
563
645
|
linkRefImgLinkText = objectGet(matchGroups, 'linkRefImgLinkText')
|
|
564
646
|
imgSpan = markdownParserCreateImageSpan(linkRefImgHref, linkRefImgText, linkRefImgTitle)
|
|
565
647
|
arrayPush(spans, markdownParserCreateLinkRefSpan(linkRefImgLinkText, [imgSpan], matchFullText, linkRefs, true))
|
|
648
|
+
continue
|
|
649
|
+
endif
|
|
566
650
|
|
|
567
651
|
# Link reference with inline image reference
|
|
568
|
-
|
|
652
|
+
if objectGet(matchGroups, 'linkRefImgRef'):
|
|
569
653
|
linkRefImgRefText = objectGet(matchGroups, 'linkRefImgRefText')
|
|
570
654
|
linkRefImgRefImgText = objectGet(matchGroups, 'linkRefImgRefImgText')
|
|
571
655
|
linkRefImgRefFull = objectGet(matchGroups, 'linkRefImgRefFull')
|
|
572
656
|
linkRefImgRefLinkText = objectGet(matchGroups, 'linkRefImgRefLinkText')
|
|
573
657
|
imgSpan = markdownParserCreateImageRefSpan(linkRefImgRefText, linkRefImgRefImgText, linkRefImgRefFull, linkRefs, true)
|
|
574
658
|
arrayPush(spans, markdownParserCreateLinkRefSpan(linkRefImgRefLinkText, [imgSpan], matchFullText, linkRefs, true))
|
|
575
|
-
|
|
576
|
-
# Link or image?
|
|
577
|
-
elif objectGet(matchGroups, 'link') != null:
|
|
578
|
-
linkResult = markdownParserGetLinkText(matchGroups, 'link')
|
|
579
|
-
linkText = arrayGet(linkResult, 0)
|
|
580
|
-
linkHref = arrayGet(linkResult, 1)
|
|
581
|
-
linkTitle = arrayGet(linkResult, 2)
|
|
582
|
-
if stringStartsWith(objectGet(matchGroups, 'link'), '!'):
|
|
583
|
-
arrayPush(spans, markdownParserCreateImageSpan(linkHref, linkText, linkTitle))
|
|
584
|
-
else:
|
|
585
|
-
arrayPush(spans, markdownParserCreateLinkSpan(linkHref, linkText, linkTitle, linkRefs))
|
|
586
|
-
endif
|
|
587
|
-
|
|
588
|
-
# Link reference?
|
|
589
|
-
elif objectGet(matchGroups, 'linkRef') != null:
|
|
590
|
-
linkRefText = objectGet(matchGroups, 'linkRefText')
|
|
591
|
-
linkRefOtherText = objectGet(matchGroups, 'linkRefOtherText')
|
|
592
|
-
if stringStartsWith(objectGet(matchGroups, 'linkRef'), '!'):
|
|
593
|
-
arrayPush(spans, markdownParserCreateImageRefSpan(linkRefText, linkRefOtherText, matchFullText, linkRefs, false))
|
|
594
|
-
else:
|
|
595
|
-
arrayPush(spans, markdownParserCreateLinkRefSpan(linkRefText, linkRefOtherText, matchFullText, linkRefs, false))
|
|
596
|
-
endif
|
|
597
|
-
|
|
598
|
-
# Link (alternate syntax)?
|
|
599
|
-
elif objectGet(matchGroups, 'linkAlt') != null:
|
|
600
|
-
linkAlt = objectGet(matchGroups, 'linkAlt')
|
|
601
|
-
linkAltScheme = objectGet(matchGroups, 'linkAltScheme')
|
|
602
|
-
linkAltHref = stringSlice(linkAlt, 1, stringLength(linkAlt) - 1)
|
|
603
|
-
linkHref = if(stringEndsWith(linkAltScheme, '@'), 'mailto:' + linkAltHref, linkAltHref)
|
|
604
|
-
arrayPush(spans, {'link': {'href': linkHref, 'spans': [{'text': linkHref}]}})
|
|
605
|
-
|
|
606
|
-
# Bold style?
|
|
607
|
-
elif objectGet(matchGroups, 'bold') != null || objectGet(matchGroups, 'boldu') != null:
|
|
608
|
-
bold = if(objectGet(matchGroups, 'bold') != null, objectGet(matchGroups, 'bold'), objectGet(matchGroups, 'boldu'))
|
|
609
|
-
boldText = stringSlice(bold, 2, stringLength(bold) - 2)
|
|
610
|
-
arrayPush(spans, {'style': {'style': 'bold', 'spans': markdownParserParagraphSpans(boldText, linkRefs)}})
|
|
611
|
-
|
|
612
|
-
# Italic style?
|
|
613
|
-
elif objectGet(matchGroups, 'italic') != null || objectGet(matchGroups, 'italicu') != null:
|
|
614
|
-
italic = if(objectGet(matchGroups, 'italic') != null, objectGet(matchGroups, 'italic'), objectGet(matchGroups, 'italicu'))
|
|
615
|
-
italicText = stringSlice(italic, 1, stringLength(italic) - 1)
|
|
616
|
-
arrayPush(spans, {'style': {'style': 'italic', 'spans': markdownParserParagraphSpans(italicText, linkRefs)}})
|
|
617
|
-
|
|
618
|
-
# Strikethrough style?
|
|
619
|
-
elif objectGet(matchGroups, 'strike') != null:
|
|
620
|
-
strike = objectGet(matchGroups, 'strike')
|
|
621
|
-
strikeT = objectGet(matchGroups, 'strikeT')
|
|
622
|
-
strikeTLen = stringLength(strikeT)
|
|
623
|
-
strikeText = stringSlice(strike, strikeTLen, stringLength(strike) - strikeTLen)
|
|
624
|
-
arrayPush(spans, {'style': {'style': 'strikethrough', 'spans': markdownParserParagraphSpans(strikeText, linkRefs)}})
|
|
625
|
-
|
|
626
|
-
# Code?
|
|
627
|
-
elif objectGet(matchGroups, 'code') != null:
|
|
628
|
-
code = objectGet(matchGroups, 'code')
|
|
629
|
-
codeT = objectGet(matchGroups, 'codeT')
|
|
630
|
-
codeTLen = stringLength(codeT)
|
|
631
|
-
codeText = stringSlice(code, codeTLen, stringLength(code) - codeTLen)
|
|
632
|
-
codeScrubbed = regexReplace(markdownParserRegexCodeNewlines, codeText, ' ')
|
|
633
|
-
codeMatch = regexMatch(markdownParserRegexCodeSpaces, codeScrubbed)
|
|
634
|
-
if codeMatch:
|
|
635
|
-
codeScrubbed = objectGet(objectGet(codeMatch, 'groups'), '1')
|
|
636
|
-
endif
|
|
637
|
-
arrayPush(spans, {'code': codeScrubbed})
|
|
638
659
|
endif
|
|
639
|
-
|
|
640
|
-
ixSearch = matchIndex + stringLength(matchFullText)
|
|
641
660
|
endfor
|
|
642
661
|
|
|
643
662
|
# Add any remaining text
|
|
@@ -736,32 +755,36 @@ endfunction
|
|
|
736
755
|
# Helper function to remove span text escapes and replace character references
|
|
737
756
|
function markdownParserRemoveEscapes(text, isHref):
|
|
738
757
|
# Remove escapes
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
entityName = objectGet(entityGroups, '1')
|
|
746
|
-
entityChar = objectGet(markdownParserEntityRefs, entityName)
|
|
747
|
-
if entityChar != null:
|
|
748
|
-
result = stringReplace(result, objectGet(entityGroups, '0'), entityChar)
|
|
749
|
-
endif
|
|
750
|
-
endfor
|
|
758
|
+
if stringIndexOf(text, '\\') >= 0:
|
|
759
|
+
escapeRegex = if(isHref, markdownParserRegexEscapeHref, markdownParserRegexEscapeText)
|
|
760
|
+
result = regexReplace(escapeRegex, text, '$1')
|
|
761
|
+
else:
|
|
762
|
+
result = text
|
|
763
|
+
endif
|
|
751
764
|
|
|
752
|
-
# Replace
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
765
|
+
# Replace entity and numeric character references
|
|
766
|
+
if stringIndexOf(text, '&') >= 0:
|
|
767
|
+
for entityMatch in regexMatchAll(markdownParserRegexEntityRef, result):
|
|
768
|
+
entityGroups = objectGet(entityMatch, 'groups')
|
|
769
|
+
entityName = objectGet(entityGroups, '1')
|
|
770
|
+
entityChar = objectGet(markdownParserEntityRefs, entityName)
|
|
771
|
+
if entityChar != null:
|
|
772
|
+
result = stringReplace(result, objectGet(entityGroups, '0'), entityChar)
|
|
773
|
+
endif
|
|
774
|
+
endfor
|
|
758
775
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
776
|
+
for decimalMatch in regexMatchAll(markdownParserRegexDecimalRef, result):
|
|
777
|
+
decimalGroups = objectGet(decimalMatch, 'groups')
|
|
778
|
+
decimalValue = numberParseInt(objectGet(decimalGroups, '1'))
|
|
779
|
+
result = stringReplace(result, objectGet(decimalGroups, '0'), stringFromCharCode(decimalValue))
|
|
780
|
+
endfor
|
|
781
|
+
|
|
782
|
+
for hexMatch in regexMatchAll(markdownParserRegexHexRef, result):
|
|
783
|
+
hexGroups = objectGet(hexMatch, 'groups')
|
|
784
|
+
hexValue = numberParseInt(objectGet(hexGroups, '1'), 16)
|
|
785
|
+
result = stringReplace(result, objectGet(hexGroups, '0'), stringFromCharCode(hexValue))
|
|
786
|
+
endfor
|
|
787
|
+
endif
|
|
765
788
|
|
|
766
789
|
return result
|
|
767
790
|
endfunction
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|