Skip to content

Commit 2367d63

Browse files
programadclaude
authored 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 2a9ebce commit 2367d63

17 files changed

Lines changed: 2987 additions & 2980 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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"dev": "tsup --watch",
2727
"new-version": "pnpm changeset",
2828
"lint": "tsc",
29+
"test": "vitest run",
30+
"test:watch": "vitest",
2931
"release": "pnpm run build && changeset publish",
3032
"release-alpha-without-git": "pnpm run build && pnpm publish --tag alpha --no-git-checks",
3133
"playground:install": "cd playground && npm install",
@@ -42,20 +44,25 @@
4244
"react-dom": "^17 || ^18 || ^19"
4345
},
4446
"devDependencies": {
47+
"@changesets/cli": "^2.26.2",
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",
4553
"@yozora/ast": "^2.3.2",
4654
"@yozora/character": "^2.3.2",
4755
"@yozora/core-tokenizer": "^2.3.2",
4856
"@yozora/parser": "^2.3.2",
49-
"@changesets/cli": "^2.26.2",
50-
"@types/react": "^17 || ^18 || ^19",
51-
"@types/react-dom": "^17 || ^18 || ^19",
5257
"autoprefixer": "^10.4.17",
5358
"cssnano": "^6.0.3",
59+
"happy-dom": "^20.9.0",
5460
"postcss": "^8.4.33",
5561
"postcss-cli": "^11.0.0",
5662
"postcss-nesting": "^12.0.2",
5763
"tailwindcss": "^3.4.1",
5864
"tsup": "^8.5.0",
59-
"typescript": "^5.2.2"
65+
"typescript": "^5.2.2",
66+
"vitest": "^4.1.6"
6067
}
6168
}

0 commit comments

Comments
Ā (0)