apex-ruby 1.0.35 → 1.0.36
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.
- checksums.yaml +4 -4
- data/ext/apex_ext/apex_src/include/apex/apex.h +2 -2
- data/ext/apex_ext/apex_src/src/extensions/toc.c +69 -60
- data/lib/apex/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0e8b147ca76e15cc47b7c82389cd32c925aabdb84580155ca98ea9cadaa4e94
|
|
4
|
+
data.tar.gz: 7b6c52d126e87e1d7adbd22a5eb4c0371617b056b6a8a8b019edea8f78328ee2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a24d7c5056504ad6557c259f62f4f7aa7f83f4214675793415587ad040affe6095a830a60a65387b76d0d3138ebfc659a100406dda633f4f426fab67d1d0043b
|
|
7
|
+
data.tar.gz: 3e9a435b4f1d0e3539d90ed2448b646843d7b9a8b300baa032c72dc5ba12d1d9e4f881ac588e50102df688e51d7f994cdb0bfc88f355f0149baed824e8bb82f3
|
|
@@ -21,8 +21,8 @@ typedef struct cmark_node cmark_node;
|
|
|
21
21
|
|
|
22
22
|
#define APEX_VERSION_MAJOR 1
|
|
23
23
|
#define APEX_VERSION_MINOR 1
|
|
24
|
-
#define APEX_VERSION_PATCH
|
|
25
|
-
#define APEX_VERSION_STRING "1.1.
|
|
24
|
+
#define APEX_VERSION_PATCH 38
|
|
25
|
+
#define APEX_VERSION_STRING "1.1.38"
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Processor compatibility modes
|
|
@@ -364,6 +364,32 @@ static header_item *collect_headers(cmark_node *node, header_item **tail,
|
|
|
364
364
|
return headers;
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
+
typedef struct {
|
|
368
|
+
char *data;
|
|
369
|
+
size_t length;
|
|
370
|
+
size_t capacity;
|
|
371
|
+
bool failed;
|
|
372
|
+
} toc_buffer;
|
|
373
|
+
|
|
374
|
+
static void toc_buffer_append(toc_buffer *buf, const char *str) {
|
|
375
|
+
if (buf->failed || !str) return;
|
|
376
|
+
size_t len = strlen(str);
|
|
377
|
+
if (buf->length + len + 1 > buf->capacity) {
|
|
378
|
+
size_t capacity = buf->capacity ? buf->capacity : 4096;
|
|
379
|
+
while (buf->length + len + 1 > capacity) capacity *= 2;
|
|
380
|
+
char *grown = realloc(buf->data, capacity);
|
|
381
|
+
if (!grown) {
|
|
382
|
+
buf->failed = true;
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
buf->data = grown;
|
|
386
|
+
buf->capacity = capacity;
|
|
387
|
+
}
|
|
388
|
+
memcpy(buf->data + buf->length, str, len);
|
|
389
|
+
buf->length += len;
|
|
390
|
+
buf->data[buf->length] = '\0';
|
|
391
|
+
}
|
|
392
|
+
|
|
367
393
|
/**
|
|
368
394
|
* Generate TOC HTML from headers
|
|
369
395
|
* Produces valid ul > li > ul nesting (nested lists inside list items)
|
|
@@ -371,81 +397,64 @@ static header_item *collect_headers(cmark_node *node, header_item **tail,
|
|
|
371
397
|
static char *generate_toc_html(header_item *headers, int min_level, int max_level) {
|
|
372
398
|
if (!headers) return strdup("");
|
|
373
399
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
400
|
+
toc_buffer buf = {0};
|
|
401
|
+
/* depth: open <ul> elements. level_at[d] is the shallowest heading level
|
|
402
|
+
* listed at depth d. A deeper heading nests one level under the open <li>,
|
|
403
|
+
* however many heading levels it skips; headings at that same level stay
|
|
404
|
+
* siblings. */
|
|
405
|
+
int depth = 0;
|
|
406
|
+
int level_at[8] = {0};
|
|
407
|
+
bool li_open = false;
|
|
377
408
|
|
|
378
|
-
|
|
379
|
-
size_t remaining = capacity;
|
|
380
|
-
int current_level = 0;
|
|
381
|
-
int last_level = 0; /* normalized level of last item added (0 = none yet) */
|
|
382
|
-
|
|
383
|
-
#define APPEND(str) do { \
|
|
384
|
-
size_t len = strlen(str); \
|
|
385
|
-
if (len < remaining) { \
|
|
386
|
-
memcpy(write, str, len); \
|
|
387
|
-
write += len; \
|
|
388
|
-
remaining -= len; \
|
|
389
|
-
} \
|
|
390
|
-
} while(0)
|
|
391
|
-
|
|
392
|
-
APPEND("<nav class=\"toc\">\n");
|
|
409
|
+
toc_buffer_append(&buf, "<nav class=\"toc\">\n");
|
|
393
410
|
|
|
394
411
|
for (header_item *h = headers; h; h = h->next) {
|
|
395
|
-
/* Skip headers outside min/max range */
|
|
396
412
|
if (h->level < min_level || h->level > max_level) continue;
|
|
397
413
|
int target_level = h->level - min_level + 1;
|
|
398
414
|
if (target_level < 1) target_level = 1;
|
|
399
415
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (last_level > 0) {
|
|
416
|
-
APPEND("<ul>\n");
|
|
417
|
-
current_level++;
|
|
418
|
-
break;
|
|
419
|
-
} else {
|
|
420
|
-
break; /* No parent li - add as direct child of root ul */
|
|
416
|
+
if (depth == 0) {
|
|
417
|
+
toc_buffer_append(&buf, "<ul>\n");
|
|
418
|
+
depth = 1;
|
|
419
|
+
level_at[depth] = target_level;
|
|
420
|
+
} else if (target_level > level_at[depth] && li_open && depth < 7) {
|
|
421
|
+
toc_buffer_append(&buf, "<ul>\n");
|
|
422
|
+
depth++;
|
|
423
|
+
level_at[depth] = target_level;
|
|
424
|
+
li_open = false;
|
|
425
|
+
} else {
|
|
426
|
+
while (depth > 1 && target_level <= level_at[depth - 1]) {
|
|
427
|
+
if (li_open) toc_buffer_append(&buf, "</li>\n");
|
|
428
|
+
toc_buffer_append(&buf, "</ul>\n");
|
|
429
|
+
depth--;
|
|
430
|
+
li_open = true;
|
|
421
431
|
}
|
|
432
|
+
if (li_open) toc_buffer_append(&buf, "</li>\n");
|
|
433
|
+
if (target_level < level_at[depth]) level_at[depth] = target_level;
|
|
422
434
|
}
|
|
423
435
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
char item[1024];
|
|
431
|
-
snprintf(item, sizeof(item), "<li><a href=\"#%s\">%s</a>",
|
|
432
|
-
h->id, h->text);
|
|
433
|
-
APPEND(item);
|
|
434
|
-
last_level = target_level;
|
|
436
|
+
toc_buffer_append(&buf, "<li><a href=\"#");
|
|
437
|
+
toc_buffer_append(&buf, h->id);
|
|
438
|
+
toc_buffer_append(&buf, "\">");
|
|
439
|
+
toc_buffer_append(&buf, h->text);
|
|
440
|
+
toc_buffer_append(&buf, "</a>");
|
|
441
|
+
li_open = true;
|
|
435
442
|
}
|
|
436
443
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
444
|
+
while (depth > 0) {
|
|
445
|
+
if (li_open) toc_buffer_append(&buf, "</li>\n");
|
|
446
|
+
toc_buffer_append(&buf, "</ul>\n");
|
|
447
|
+
depth--;
|
|
448
|
+
li_open = depth > 0;
|
|
441
449
|
}
|
|
442
450
|
|
|
443
|
-
|
|
451
|
+
toc_buffer_append(&buf, "</nav>\n");
|
|
444
452
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
453
|
+
if (buf.failed || !buf.data) {
|
|
454
|
+
free(buf.data);
|
|
455
|
+
return strdup("");
|
|
456
|
+
}
|
|
457
|
+
return buf.data;
|
|
449
458
|
}
|
|
450
459
|
|
|
451
460
|
void apex_toc_entries_free(apex_toc_entry *entries, size_t count) {
|
data/lib/apex/version.rb
CHANGED