apex-ruby 1.0.50 → 1.0.51
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c2d053e5117da4e3fce80204e0ed2756d3ec7955f46a3819b6dec1f9b21adb3d
|
|
4
|
+
data.tar.gz: fafea5add3bda0d20d859631221d764cbb5a3d7af1d99cd20668fe3b065c2bba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 63a4822ef724f51ec8bb555522e9d6ca833c542f504541818eb4cc094f43a232782162369f097564a09dc383fe0c4a7d50d8540999dab9b379ff0ddcc00119f6
|
|
7
|
+
data.tar.gz: 567d78f322750c4dabc678e8761288a85183d147b1af38711e97281c25d323a0767d5b1ae11a4a27347f6eb33b504a964c751b7ceb1cf1d28fa25b14dde8f029
|
|
@@ -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 59
|
|
25
|
+
#define APEX_VERSION_STRING "1.1.59"
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Processor compatibility modes
|
|
@@ -382,8 +382,10 @@ char *apex_generate_header_id(const char *text, apex_id_format_t format) {
|
|
|
382
382
|
}
|
|
383
383
|
/* MMD format: preserve leading/trailing dashes */
|
|
384
384
|
|
|
385
|
+
apex_limit_header_id(id);
|
|
386
|
+
|
|
385
387
|
/* If result is empty, use "header" */
|
|
386
|
-
if (
|
|
388
|
+
if (id[0] == '\0') {
|
|
387
389
|
free(id);
|
|
388
390
|
return strdup("header");
|
|
389
391
|
}
|
|
@@ -391,6 +393,21 @@ char *apex_generate_header_id(const char *text, apex_id_format_t format) {
|
|
|
391
393
|
return id;
|
|
392
394
|
}
|
|
393
395
|
|
|
396
|
+
void apex_limit_header_id(char *id) {
|
|
397
|
+
if (!id) return;
|
|
398
|
+
size_t len = strlen(id);
|
|
399
|
+
if (len <= APEX_HEADER_ID_MAX) return;
|
|
400
|
+
|
|
401
|
+
size_t cut = APEX_HEADER_ID_MAX;
|
|
402
|
+
size_t min_cut = APEX_HEADER_ID_MAX > 64 ? APEX_HEADER_ID_MAX - 64 : 0;
|
|
403
|
+
while (cut > min_cut && id[cut - 1] != '-') cut--;
|
|
404
|
+
if (cut > min_cut && id[cut - 1] == '-') cut--;
|
|
405
|
+
if (cut == min_cut) cut = APEX_HEADER_ID_MAX;
|
|
406
|
+
while (cut > 0 && id[cut - 1] == '-') cut--;
|
|
407
|
+
if (cut == 0) cut = APEX_HEADER_ID_MAX;
|
|
408
|
+
id[cut] = '\0';
|
|
409
|
+
}
|
|
410
|
+
|
|
394
411
|
/**
|
|
395
412
|
* Recursively append literal text from node and its descendants to buffer.
|
|
396
413
|
* Handles TEXT, CODE, and recurses into inline containers (EMPH, STRONG, etc.)
|
|
@@ -18,6 +18,10 @@ typedef enum {
|
|
|
18
18
|
APEX_ID_FORMAT_KRAMDOWN = 2 /* Kramdown style: "header-one" (spaces→dashes, removes em/en dashes) */
|
|
19
19
|
} apex_id_format_t;
|
|
20
20
|
|
|
21
|
+
/* Auto-generated and copied header ids are capped so a long title stays a
|
|
22
|
+
* usable fragment. The HTML writer still closes id="..." after the cap. */
|
|
23
|
+
#define APEX_HEADER_ID_MAX 512
|
|
24
|
+
|
|
21
25
|
/**
|
|
22
26
|
* Generate header ID from text
|
|
23
27
|
* @param text Header text
|
|
@@ -26,6 +30,12 @@ typedef enum {
|
|
|
26
30
|
*/
|
|
27
31
|
char *apex_generate_header_id(const char *text, apex_id_format_t format);
|
|
28
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Shorten id in place to APEX_HEADER_ID_MAX. Cuts on a dash near the end
|
|
35
|
+
* when one is close, so the slug does not stop mid-word.
|
|
36
|
+
*/
|
|
37
|
+
void apex_limit_header_id(char *id);
|
|
38
|
+
|
|
29
39
|
/**
|
|
30
40
|
* Extract text content from a heading node
|
|
31
41
|
* @param heading_node The heading AST node
|
|
@@ -1261,6 +1261,7 @@ char *apex_inject_header_ids(const char *html, cmark_node *document, bool genera
|
|
|
1261
1261
|
if (id) {
|
|
1262
1262
|
memcpy(id, id_start, id_len);
|
|
1263
1263
|
id[id_len] = '\0';
|
|
1264
|
+
apex_limit_header_id(id);
|
|
1264
1265
|
}
|
|
1265
1266
|
}
|
|
1266
1267
|
}
|
|
@@ -1441,16 +1442,31 @@ char *apex_inject_header_ids(const char *html, cmark_node *document, bool genera
|
|
|
1441
1442
|
remaining -= tag_len;
|
|
1442
1443
|
read = tag_end + 1;
|
|
1443
1444
|
|
|
1444
|
-
/* Inject anchor tag after the header tag
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1445
|
+
/* Inject anchor tag after the header tag. Size it from the
|
|
1446
|
+
* (already capped) id so both copies and the closing quote fit. */
|
|
1447
|
+
size_t idn = strlen(header->id);
|
|
1448
|
+
const char *anchor_head = "<a href=\"#";
|
|
1449
|
+
const char *anchor_mid = "\" aria-hidden=\"true\" class=\"anchor\" id=\"";
|
|
1450
|
+
const char *anchor_tail = "\"></a>";
|
|
1451
|
+
size_t anchor_len = strlen(anchor_head) + idn + strlen(anchor_mid) + idn + strlen(anchor_tail);
|
|
1452
|
+
char *anchor_tag = malloc(anchor_len + 1);
|
|
1453
|
+
if (anchor_tag) {
|
|
1454
|
+
char *ap = anchor_tag;
|
|
1455
|
+
memcpy(ap, anchor_head, strlen(anchor_head));
|
|
1456
|
+
ap += strlen(anchor_head);
|
|
1457
|
+
memcpy(ap, header->id, idn);
|
|
1458
|
+
ap += idn;
|
|
1459
|
+
memcpy(ap, anchor_mid, strlen(anchor_mid));
|
|
1460
|
+
ap += strlen(anchor_mid);
|
|
1461
|
+
memcpy(ap, header->id, idn);
|
|
1462
|
+
ap += idn;
|
|
1463
|
+
memcpy(ap, anchor_tail, strlen(anchor_tail) + 1);
|
|
1464
|
+
APEX_HEADER_ID_ENSURE(anchor_len);
|
|
1465
|
+
memcpy(write, anchor_tag, anchor_len);
|
|
1466
|
+
write += anchor_len;
|
|
1467
|
+
remaining -= anchor_len;
|
|
1468
|
+
free(anchor_tag);
|
|
1469
|
+
}
|
|
1454
1470
|
} else if (!use_anchors && header && header->id) {
|
|
1455
1471
|
/* For header IDs: replace existing ID or inject new one */
|
|
1456
1472
|
if (has_id && id_attr) {
|
|
@@ -1476,14 +1492,21 @@ char *apex_inject_header_ids(const char *html, cmark_node *document, bool genera
|
|
|
1476
1492
|
old_id_end++;
|
|
1477
1493
|
}
|
|
1478
1494
|
|
|
1479
|
-
/* Inject new id="..." */
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1495
|
+
/* Inject new id="..." sized to the capped slug. */
|
|
1496
|
+
size_t slug_len = strlen(header->id);
|
|
1497
|
+
char *id_attr_str = malloc(slug_len + 6); /* id="..." + NUL */
|
|
1498
|
+
if (id_attr_str) {
|
|
1499
|
+
memcpy(id_attr_str, "id=\"", 4);
|
|
1500
|
+
memcpy(id_attr_str + 4, header->id, slug_len);
|
|
1501
|
+
id_attr_str[4 + slug_len] = '"';
|
|
1502
|
+
id_attr_str[5 + slug_len] = '\0';
|
|
1503
|
+
size_t id_len = slug_len + 5;
|
|
1504
|
+
APEX_HEADER_ID_ENSURE(id_len);
|
|
1505
|
+
memcpy(write, id_attr_str, id_len);
|
|
1506
|
+
write += id_len;
|
|
1507
|
+
remaining -= id_len;
|
|
1508
|
+
free(id_attr_str);
|
|
1509
|
+
}
|
|
1487
1510
|
|
|
1488
1511
|
/* Copy rest of tag from after old ID until '>' */
|
|
1489
1512
|
read = old_id_end;
|
|
@@ -1536,14 +1559,21 @@ char *apex_inject_header_ids(const char *html, cmark_node *document, bool genera
|
|
|
1536
1559
|
remaining--;
|
|
1537
1560
|
}
|
|
1538
1561
|
|
|
1539
|
-
/* Inject id="..." */
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1562
|
+
/* Inject id="..." sized to the capped slug. */
|
|
1563
|
+
size_t slug_len = strlen(header->id);
|
|
1564
|
+
char *id_attr_str = malloc(slug_len + 6);
|
|
1565
|
+
if (id_attr_str) {
|
|
1566
|
+
memcpy(id_attr_str, "id=\"", 4);
|
|
1567
|
+
memcpy(id_attr_str + 4, header->id, slug_len);
|
|
1568
|
+
id_attr_str[4 + slug_len] = '"';
|
|
1569
|
+
id_attr_str[5 + slug_len] = '\0';
|
|
1570
|
+
size_t id_len = slug_len + 5;
|
|
1571
|
+
APEX_HEADER_ID_ENSURE(id_len);
|
|
1572
|
+
memcpy(write, id_attr_str, id_len);
|
|
1573
|
+
write += id_len;
|
|
1574
|
+
remaining -= id_len;
|
|
1575
|
+
free(id_attr_str);
|
|
1576
|
+
}
|
|
1547
1577
|
|
|
1548
1578
|
/* Copy closing '>' */
|
|
1549
1579
|
if (*read == '>') {
|
data/lib/apex/version.rb
CHANGED