Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix: wrap exceptionally wide contributor usernames

Yunyue Li64eeca7a09be
diff --git a/tools/contributor-cards/README.md b/tools/contributor-cards/README.md
index 3d7d8c68..666b3a76 100644
--- a/tools/contributor-cards/README.md
+++ b/tools/contributor-cards/README.md
@@ -12,7 +12,7 @@ node tools/contributor-cards/cli.mjs --pr 394 --out /tmp/archify-card
An optional `--repo owner/repository` selects another repository. On Linux, install `fonts-noto-cjk` for Chinese titles; on macOS the template uses PingFang SC. `ARCHIFY_CHROME` can select a Chrome executable. Preview mode never writes to GitHub.
-The output includes the 1000 × 1500 PNG, a portable HTML document with embedded map/fonts, original metadata with a PNG digest, a browser layout receipt, and the proposed reply. Full PR titles remain in metadata and the HTML title attribute. Font size is reduced within a readable range; exceptionally long titles end with an explicit ellipsis. Usernames are fitted without truncation. Middle-dot text separators are not used.
+The output includes the 1000 × 1500 PNG, a portable HTML document with embedded map/fonts, original metadata with a PNG digest, a browser layout receipt, and the proposed reply. Full PR titles remain in metadata and the HTML title attribute. Font size is reduced within a readable range; exceptionally long titles end with an explicit ellipsis. Usernames are fitted without truncation; exceptionally wide 39-character handles wrap to two lines at the minimum 30px size. Middle-dot text separators are not used.
## Publish and reply
diff --git a/tools/contributor-cards/card.mjs b/tools/contributor-cards/card.mjs
index baf5ad8a..11ab816b 100644
--- a/tools/contributor-cards/card.mjs
+++ b/tools/contributor-cards/card.mjs
@@ -76,6 +76,10 @@ export async function renderCard(record, outputDirectory, { chrome = findChrome(
while (overflow(e) && size > Number(e.dataset.fitMin)) {
size -= 1; e.style.fontSize = size + 'px';
}
+ if (overflow(e) && e.dataset.wrap === 'true') {
+ e.style.whiteSpace = 'normal'; e.style.overflowWrap = 'anywhere';
+ e.dataset.wrapped = 'true';
+ }
if (overflow(e) && e.dataset.ellipsis === 'true') {
e.dataset.truncated = 'true';
const parts = [...new Intl.Segmenter('en', {granularity:'grapheme'}).segment(e.textContent)].map(p => p.segment);
@@ -89,9 +93,10 @@ export async function renderCard(record, outputDirectory, { chrome = findChrome(
const fonts = [...document.fonts].map(f => ({family:f.family,status:f.status}));
if (fonts.some(f => f.status !== 'loaded')) throw new Error('A bundled font did not load');
if (clipped.length) throw new Error('Clipped elements: ' + clipped.join(', '));
+ if (document.querySelector('.identity').getBoundingClientRect().bottom > 320) throw new Error('Contributor identity exceeds the map clearance');
if (document.querySelector('.moment').getBoundingClientRect().bottom + 20 > document.querySelector('footer').getBoundingClientRect().top) throw new Error('Message overlaps the contribution record');
return {width:1000,height:1500,fonts,clipped,text:document.body.innerText,
- fitted:[...document.querySelectorAll('[data-fit-min]')].map(e=>({text:e.innerText,fontSize:getComputedStyle(e).fontSize,truncated:e.dataset.truncated === 'true'}))};
+ fitted:[...document.querySelectorAll('[data-fit-min]')].map(e=>({text:e.innerText,fontSize:getComputedStyle(e).fontSize,truncated:e.dataset.truncated === 'true',wrapped:e.dataset.wrapped === 'true'}))};
})()` });
if (metrics.exceptionDetails) throw new Error(metrics.exceptionDetails.exception?.description || metrics.exceptionDetails.text);
receipt = metrics.result.value;
diff --git a/tools/contributor-cards/template.html b/tools/contributor-cards/template.html
index 0ac678c8..9aef26b6 100644
--- a/tools/contributor-cards/template.html
+++ b/tools/contributor-cards/template.html
@@ -272,7 +272,7 @@
</header>
<section class="identity" aria-label="Contributor identity">
- <p class="handle" data-fit-min="30">@{{AUTHOR}}</p>
+ <p class="handle" data-fit-min="30" data-wrap="true">@{{AUTHOR}}</p>
<div class="role">System cartographer</div>
</section>
diff --git a/tools/contributor-cards/test/card.test.mjs b/tools/contributor-cards/test/card.test.mjs
index 50c03536..ddcea159 100644
--- a/tools/contributor-cards/test/card.test.mjs
+++ b/tools/contributor-cards/test/card.test.mjs
@@ -37,13 +37,14 @@ test('real browser fits long GitHub usernames, long unbroken titles and Chinese
try {
for (const [number, login, title] of [
[394,'tt-a1i',pull.title],
- [395,'a'.repeat(39),'W'.repeat(256)],
+ [395,'W'.repeat(39),'W'.repeat(256)],
[396,'contributor','修复复杂架构图中的边界重叠问题,并改善中文说明和长标题在贡献卡上的排版效果。'.repeat(3)],
[397,'contributor','<script>document.body.remove()</script> & safe text'],
]) {
const record=recordFromPull({...pull,number,title,user:{type:'User',login}},'tt-a1i/archify');
const result=await renderCard(record,output);
assert.deepEqual(result.receipt.clipped,[]);
+ if(number===395) { assert.equal(result.receipt.fitted[0].wrapped,true); assert.equal(result.receipt.fitted[1].truncated,true); }
assert.ok(result.receipt.text.includes('@'+login));
assert.ok(result.receipt.text.includes('Merged'));
const png=await fs.readFile(result.stem+'.png');