rapier-markdown-kit 1.1.26 → 1.1.29

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.
@@ -55,6 +55,10 @@ export function scanColorMarkers(source) {
55
55
  return markers;
56
56
  }
57
57
 
58
+ export function pairColorMarkers(source) {
59
+ return pairMarkers(source, 'color');
60
+ }
61
+
58
62
  export function stripColorMarkers(text) {
59
63
  return String(text == null ? '' : text).replace(new RegExp('<!--(?:c ' + COLOR_VALUE + '|/c)-->', 'g'), '');
60
64
  }
@@ -189,12 +193,28 @@ export function scanInkMarkers(source) {
189
193
  // The runs: an opener and the next closer with no opener between them. A marker that pairs with nothing is text
190
194
  // (it shows nothing and marks nothing) and is listed under strays.
191
195
  export function pairInkMarkers(source) {
196
+ return pairMarkers(source, 'ink');
197
+ }
198
+
199
+ // Colour keeps the first opener, as its inline parser does; ink replaces an unclosed opener.
200
+ // Neither kind nests in itself. The shared range shape lets custody owners treat both alike.
201
+ export function pairMarkers(source, kind) {
202
+ if (kind !== 'ink' && kind !== 'color') throw new TypeError('Unknown paired marker kind');
203
+ const color = kind === 'color';
192
204
  const runs = [], strays = [];
193
205
  let open = null;
194
- for (const marker of scanInkMarkers(source)) {
195
- if (!marker.close) { if (open) strays.push(open); open = marker; continue; }
206
+ for (const marker of color ? scanColorMarkers(source) : scanInkMarkers(source)) {
207
+ if (color ? marker.hex !== null : !marker.close) {
208
+ if (open) {
209
+ strays.push(color ? marker : open);
210
+ if (color) continue;
211
+ }
212
+ open = marker;
213
+ continue;
214
+ }
196
215
  if (!open) { strays.push(marker); continue; }
197
- runs.push({ start: open.start, end: marker.end, innerStart: open.end, innerEnd: marker.start, mark: open.mark });
216
+ runs.push({ start: open.start, end: marker.end, innerStart: open.end, innerEnd: marker.start,
217
+ ...(color ? { hex: open.hex } : { mark: open.mark }) });
198
218
  open = null;
199
219
  }
200
220
  if (open) strays.push(open);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapier-markdown-kit",
3
- "version": "1.1.26",
3
+ "version": "1.1.29",
4
4
  "description": "Read, write and style Self-contained Markdown: the universal stylesheet, picture layout, text marks, picture appendix, line planner and Will/1 markers. MIT, no dependencies.",
5
5
  "author": "Jack Skipworth",
6
6
  "license": "MIT",