@enhansome/core 1.9.0 → 1.10.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/dist/markdown.js +56 -15
- package/package.json +1 -1
package/dist/markdown.js
CHANGED
|
@@ -519,14 +519,23 @@ sectionGateOpen) {
|
|
|
519
519
|
listNode.children = entries.map(entry => entry.node);
|
|
520
520
|
return entries.flatMap(entry => entry.emitted);
|
|
521
521
|
}
|
|
522
|
-
// Title with the fallbacks every entry source shares
|
|
523
|
-
//
|
|
524
|
-
// name
|
|
522
|
+
// Title with the fallbacks every entry source shares: the split's own text
|
|
523
|
+
// when it names something; else the own link's label when meaningful; else —
|
|
524
|
+
// for a degenerate base (rank/year cell, URL label, tag word) owner/name, for
|
|
525
|
+
// an absent base (an image-only link) the repo name. A degenerate base with
|
|
526
|
+
// no live repo link (a group) keeps its text: nothing better exists.
|
|
525
527
|
function entryTitle(base, ownLink, repoInfo) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
528
|
+
if (base && !isDegenerateTitle(base)) {
|
|
529
|
+
return base;
|
|
530
|
+
}
|
|
531
|
+
const linkText = ownLink ? getInlineText(ownLink.children) : '';
|
|
532
|
+
if (isMeaningfulLinkText(linkText)) {
|
|
533
|
+
return linkText;
|
|
534
|
+
}
|
|
535
|
+
if (base === '') {
|
|
536
|
+
return repoInfo?.repo ?? '';
|
|
537
|
+
}
|
|
538
|
+
return repoInfo ? `${repoInfo.owner}/${repoInfo.repo}` : base;
|
|
530
539
|
}
|
|
531
540
|
// Table rows are entries under the nearest open container. The common shape —
|
|
532
541
|
// scala's `[name](repo) | description`, spec tables with the link in a later
|
|
@@ -560,15 +569,27 @@ function processTableRows(tableNode, repoInfoMap, gateOpen) {
|
|
|
560
569
|
}
|
|
561
570
|
const repoInfo = repoInfoMap.get(ownLink.url) ?? null;
|
|
562
571
|
const firstCellText = splitEntryText(row.children[0]?.children ?? []);
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
572
|
+
// A degenerate first cell (a rank/year column) moves the title source to
|
|
573
|
+
// the link's own cell: that cell no longer feeds the description — its
|
|
574
|
+
// label became the title — and the degenerate cell drops as noise.
|
|
575
|
+
const linkCellIndex = isDegenerateTitle(firstCellText.title)
|
|
576
|
+
? cellLinks.findIndex(link => link === ownLink)
|
|
577
|
+
: -1;
|
|
578
|
+
const titleText = linkCellIndex === -1
|
|
579
|
+
? firstCellText
|
|
580
|
+
: splitEntryText(row.children[linkCellIndex].children);
|
|
581
|
+
const description = [
|
|
582
|
+
titleText.description,
|
|
583
|
+
...row.children
|
|
584
|
+
.slice(1)
|
|
585
|
+
.filter((_cell, index) => index + 1 !== linkCellIndex)
|
|
586
|
+
.map(cell => getNodeText(cell)),
|
|
587
|
+
]
|
|
588
|
+
.join(' ')
|
|
589
|
+
.trim();
|
|
567
590
|
items.push(...emitEntryNodes(ownLink.url, repoInfo, {
|
|
568
|
-
title: entryTitle(
|
|
569
|
-
description
|
|
570
|
-
.join(' ')
|
|
571
|
-
.trim(),
|
|
591
|
+
title: entryTitle(titleText.title, ownLink, repoInfo),
|
|
592
|
+
description,
|
|
572
593
|
}, []));
|
|
573
594
|
continue;
|
|
574
595
|
}
|
|
@@ -605,6 +626,26 @@ const ENTRY_LABEL_MAX = 15;
|
|
|
605
626
|
const ENTRY_TRAILING_MAX = 3;
|
|
606
627
|
const TAG_LINK_TEXT = /^[\[\]()*\s:_-]*(?:source\s+code|code|github|repo|source|src|project|paper|page|web|site|home|official|notebook|demo|data|docs|implementation|arxiv)\b[\[\]()*\s:_-]*$/i;
|
|
607
628
|
const URL_LINK_TEXT = /^https?:\/\/\S+$/i;
|
|
629
|
+
// A title that names nothing — the degenerate families every entry source can
|
|
630
|
+
// emit: a pure number/punctuation run (a table's rank or year column, "15."
|
|
631
|
+
// / "2023" / "2025-05" / "-"), a URL (a link whose label is the URL itself,
|
|
632
|
+
// scheme or scheme-less `github.com/…`), or a bare tag word ("GitHub",
|
|
633
|
+
// "Source code" — best-of's generated lines). CJK labels are letters
|
|
634
|
+
// (`\p{L}`) and stay titles.
|
|
635
|
+
const URL_TITLE = /^(?:[a-z][a-z0-9+.-]*:\/\/|www\.)\S+$|^github\.com\/\S+$/i;
|
|
636
|
+
function isDegenerateTitle(title) {
|
|
637
|
+
const trimmed = title.trim();
|
|
638
|
+
return (!!trimmed &&
|
|
639
|
+
(URL_TITLE.test(trimmed) ||
|
|
640
|
+
TAG_LINK_TEXT.test(trimmed) ||
|
|
641
|
+
!/[\p{L}]/u.test(trimmed)));
|
|
642
|
+
}
|
|
643
|
+
// A link label that can serve as a title. The degenerate shapes are excluded
|
|
644
|
+
// twice over — a URL label stays a URL, and a tag label names the link's role
|
|
645
|
+
// ("[Github](repo)"), not the repo.
|
|
646
|
+
function isMeaningfulLinkText(text) {
|
|
647
|
+
return text !== '' && !isDegenerateTitle(text);
|
|
648
|
+
}
|
|
608
649
|
// Dated entry lines end their tag cluster with a publication date ("4 Feb
|
|
609
650
|
// 2023", "19 Apr 2022", "2023") — a real corpus family (dated paper/tutorial
|
|
610
651
|
// lists), not a sentence continuation.
|