Skip to content

Commit e2ba081

Browse files
programadclaude
andcommitted
fix: šŸ› resolve Slack directives in section/mrkdwn (verbatim + non-verbatim)
Slack directives like `<@u123>`, `<#C123>`, `<!subteam^S1|@team>`, `<!channel|here|everyone>`, and `<!date^…>` now fire the matching hooks (`hooks.user`, `hooks.channel`, `hooks.usergroup`, `hooks.atHere` / `atChannel` / `atEveryone`, `hooks.date`) in both `verbatim: true` and `verbatim: false` modes — matching the behaviour of the rich_text path. - Verbatim mode no longer early-returns. It splits the input by directive boundaries and renders each segment, preserving non-directive text literally (no markdown sugar expansion — that's the point of verbatim). - Non-verbatim mode now masks fenced code, inline code, and directive atoms before the URL-rewrite / asterisk-doubling regex pass, then restores them before Yozora parses — so directives can't be mangled by the pre-pass and directive-shaped text inside code stays literal. - Broadcast tokenizer recognises `<!here>` / `<!everyone>` / `<!channel>` natively, alongside the existing `@here` / `@everyone` / `@channel`. - Yozora's `autolink` and `autolink-extension` are unmounted; bare URL autolinking is handled by the existing `<X>` / `<X|Y>` regex rewrite, and the autolink-extension was stealing directives like `<!subteam^S1|@team>` because of the embedded `@`. - mrkdwn sub-element hook payloads now include `style: undefined` to match the rich_text path shape (`{ id, name, style }`). - `<@U…|fallback>` and `<!subteam^S…|@team>` now split on `|` for data lookup + fallback display name (channel mention already did this). - `&amp;` is decoded alongside `&gt;` / `&lt;` in text-object payloads so escaped ampersands don't leak into hrefs or visible text. Adds a vitest test suite (the repo previously had none) covering the directive Ɨ verbatim matrix, code-span suppression, escaped entities, hook payload shape, data-map resolution, and non-directive regression. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bb2b269 commit e2ba081

17 files changed

Lines changed: 1545 additions & 59 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"slack-blocks-to-jsx": patch
3+
---
4+
5+
Resolve Slack directive atoms (`<@U…>`, `<#C…>`, `<!subteam^…>`, `<!channel|here|everyone>`, `<!date^…>`) in `section`/`mrkdwn` text and other mrkdwn-typed text. Directives now fire the same hooks as the rich_text path in both `verbatim: true` and `verbatim: false` modes. Code-span content stays literal (directives inside `` `…` `` or ` ```…``` ` are not resolved). `&amp;` is now decoded alongside the existing `&gt;` / `&lt;` decoding so link `href`s and visible text don't leak literal `&amp;`.

ā€Žpackage.jsonā€Ž

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"dev:css": "postcss ./src/style.css -o ./dist/style.css --watch",
2626
"dev": "tsup --watch",
2727
"lint": "tsc",
28-
"test": "node --test \"test/**/*.test.mjs\"",
28+
"test": "vitest run && node --test \"test/**/*.test.mjs\"",
29+
"test:watch": "vitest",
2930
"release": "node scripts/release.mjs",
3031
"release:dry": "node scripts/release.mjs --dry-run",
3132
"release:beta": "node scripts/release.mjs prerelease --preid=beta",
@@ -44,19 +45,24 @@
4445
"react-dom": "^17 || ^18 || ^19"
4546
},
4647
"devDependencies": {
48+
"@testing-library/jest-dom": "^6.9.1",
49+
"@testing-library/react": "^16.3.2",
50+
"@types/react": "^17 || ^18 || ^19",
51+
"@types/react-dom": "^17 || ^18 || ^19",
52+
"@vitejs/plugin-react": "^6.0.2",
4753
"@yozora/ast": "^2.3.2",
4854
"@yozora/character": "^2.3.2",
4955
"@yozora/core-tokenizer": "^2.3.2",
5056
"@yozora/parser": "^2.3.2",
51-
"@types/react": "^17 || ^18 || ^19",
52-
"@types/react-dom": "^17 || ^18 || ^19",
5357
"autoprefixer": "^10.4.17",
5458
"cssnano": "^6.0.3",
59+
"happy-dom": "^20.9.0",
5560
"postcss": "^8.4.33",
5661
"postcss-cli": "^11.0.0",
5762
"postcss-nesting": "^12.0.2",
5863
"tailwindcss": "^3.4.1",
5964
"tsup": "^8.5.0",
60-
"typescript": "^5.2.2"
65+
"typescript": "^5.2.2",
66+
"vitest": "^4.1.6"
6167
}
6268
}

0 commit comments

Comments
Ā (0)