feat(doc): expand callout type= shorthand into background-color and border-color#467
feat(doc): expand callout type= shorthand into background-color and border-color#467herbertliu wants to merge 2 commits intomainfrom
Conversation
…order-color When users write <callout type="warning" emoji="📝"> without an explicit background-color, the Feishu doc renders the block with no color. This commit adds fixCalloutType() which maps the semantic type= attribute to the corresponding background-color/border-color pair accepted by create-doc. - warning → light-yellow/yellow - info/note → light-blue/blue - tip/success/check → light-green/green - error/danger → light-red/red - caution → light-orange/orange - important → light-purple/purple Explicit background-color or border-color attributes are always preserved. The fix is applied via prepareMarkdownForCreate() in both +create and +update paths, and also inside fixExportedMarkdown() for round-trip fidelity. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
📝 WalkthroughWalkthroughAdds a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@011da3d0f19e1ebfb498e884c0b00788a494f9ae🧩 Skill updatenpx skills add larksuite/cli#feat/callout-type-to-color -y -g |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
shortcuts/doc/markdown_fix.go (1)
38-40: Broaden fence detection for create-time preprocessing.
prepareMarkdownForCreatenow runs on hand-authored markdown, butapplyOutsideCodeFencesonly recognizes bare triple-backtick fences. That can misclassify~~~, 4+-backtick fences, or blockquote-prefixed fences and lead to missed/incorrect transformations around code blocks. Consider centralizing fence parsing (prefix + marker + length) and reusing it here.Based on learnings:
applyOutsideCodeFences ... only recognize bare triple-backtick fences ... accepted limitation ... because fetch-doc export currently emits only bare triple-backtick fences.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/doc/markdown_fix.go` around lines 38 - 40, prepareMarkdownForCreate currently delegates to applyOutsideCodeFences which only recognizes bare triple-backtick fences; update the code so fence detection is centralized and supports fence prefix (optional blockquote '>' or spaces), marker char (` or ~), and variable length (3+). Introduce or reuse a shared fence-parsing helper (e.g., parseFence or fenceRegex used by applyOutsideCodeFences) and call it from both applyOutsideCodeFences and prepareMarkdownForCreate (or make applyOutsideCodeFences accept the new parser) so create-time preprocessing correctly skips/handles fences like ~~~, 4+ backticks, and blockquote-prefixed fences while preserving existing behavior for fetch-doc exports.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@shortcuts/doc/markdown_fix.go`:
- Around line 262-265: fixCalloutType currently uses typeRe :=
regexp.MustCompile(`\btype="([^"]*)"`) which only matches double-quoted
attributes and leaves single-quoted callouts (e.g., <callout type='warning'>)
unchanged; update the regex used in fixCalloutType (variable typeRe and its use
with attrs and tag) to accept either single or double quotes (for example use a
pattern that captures quote with backreference or a pattern like
\btype=(?:'|")([^'"]*)(?:'|")) and adjust how you read the capture groups from
typeParts accordingly so single-quoted and double-quoted type attributes are
both handled.
---
Nitpick comments:
In `@shortcuts/doc/markdown_fix.go`:
- Around line 38-40: prepareMarkdownForCreate currently delegates to
applyOutsideCodeFences which only recognizes bare triple-backtick fences; update
the code so fence detection is centralized and supports fence prefix (optional
blockquote '>' or spaces), marker char (` or ~), and variable length (3+).
Introduce or reuse a shared fence-parsing helper (e.g., parseFence or fenceRegex
used by applyOutsideCodeFences) and call it from both applyOutsideCodeFences and
prepareMarkdownForCreate (or make applyOutsideCodeFences accept the new parser)
so create-time preprocessing correctly skips/handles fences like ~~~, 4+
backticks, and blockquote-prefixed fences while preserving existing behavior for
fetch-doc exports.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 99b5687c-bc19-48c5-bb18-d0fd4e78ba9a
📒 Files selected for processing (4)
shortcuts/doc/docs_create.goshortcuts/doc/docs_update.goshortcuts/doc/markdown_fix.goshortcuts/doc/markdown_fix_test.go
|
Thanks for the PR and the thorough test coverage! The mapping (e.g. warning → light-yellow) is not defined by any Feishu spec — it's a convention we'd be inventing and then silently applying. Suggested alternatives: File a feature request for create-doc to natively support type= on callout blocks. Happy to discuss further! |
…output Per reviewer feedback (SunPeiYang996), silently rewriting user Markdown is the wrong layer for this adaptation. The type→color mapping is not part of the Feishu spec, and covert transforms make debugging harder. Replace fixCalloutType() (which rewrote the Markdown) with WarnCalloutType() which leaves the Markdown unchanged and instead writes a hint line to stderr for each callout tag that has type= but no background-color, telling the user the recommended explicit attributes to add: hint: callout type="warning" has no background-color; consider: background-color="light-yellow" border-color="yellow" Also fixes CodeRabbit feedback: the type= regex now accepts both single-quoted and double-quoted attribute values (type='warning' and type="warning"). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@shortcuts/doc/markdown_fix.go`:
- Around line 261-263: The check that skips tags with an explicit background
color is too strict: it only looks for the literal substring "background-color="
using strings.Contains(attrs, "background-color="), so forms like
'background-color = "light-yellow"' or with varied spacing/quotes are missed;
update the detection in the markdown_fix.go logic that currently inspects attrs
(the variable checked and returns tag) to use a whitespace-tolerant match (e.g.,
a regex or normalize attrs by collapsing whitespace) to detect
"background-color" followed by optional spaces and an '='
(background-color\s*=?), and then skip returning the hint when that match is
present. Ensure the change targets the same check that returns tag and continues
to accept other attributes unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d8d41789-3d3c-40cb-8744-954cabb9b237
📒 Files selected for processing (4)
shortcuts/doc/docs_create.goshortcuts/doc/docs_update.goshortcuts/doc/markdown_fix.goshortcuts/doc/markdown_fix_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
- shortcuts/doc/docs_update.go
- shortcuts/doc/docs_create.go
- shortcuts/doc/markdown_fix_test.go
| // Skip tags that already carry an explicit background-color. | ||
| if strings.Contains(attrs, "background-color=") { | ||
| return tag |
There was a problem hiding this comment.
Harden background-color detection to avoid false hints.
Line 262 only checks the exact substring background-color=. It misses valid forms like background-color = "light-yellow" and can emit incorrect hints.
🔧 Suggested patch
var calloutTypeAttrRe = regexp.MustCompile(`\btype=(?:"([^"]*)"|'([^']*)')`)
+var calloutBackgroundColorAttrRe = regexp.MustCompile(`\bbackground-color\s*=`)
func WarnCalloutType(md string, w io.Writer) {
calloutOpenTagRe.ReplaceAllStringFunc(md, func(tag string) string {
attrs := ""
if m := calloutOpenTagRe.FindStringSubmatch(tag); len(m) == 2 {
attrs = m[1]
}
// Skip tags that already carry an explicit background-color.
- if strings.Contains(attrs, "background-color=") {
+ if calloutBackgroundColorAttrRe.MatchString(attrs) {
return tag
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@shortcuts/doc/markdown_fix.go` around lines 261 - 263, The check that skips
tags with an explicit background color is too strict: it only looks for the
literal substring "background-color=" using strings.Contains(attrs,
"background-color="), so forms like 'background-color = "light-yellow"' or with
varied spacing/quotes are missed; update the detection in the markdown_fix.go
logic that currently inspects attrs (the variable checked and returns tag) to
use a whitespace-tolerant match (e.g., a regex or normalize attrs by collapsing
whitespace) to detect "background-color" followed by optional spaces and an '='
(background-color\s*=?), and then skip returning the hint when that match is
present. Ensure the change targets the same check that returns tag and continues
to accept other attributes unchanged.
|
Thanks for the detailed review and the thoughtful suggestions! You're right — silently rewriting user Markdown is the wrong approach here. The latest commit (011da3d) replaces
This surfaces the issue visibly without any silent transformation. On the longer term, filing a feature request for |
Summary
When users write
<callout type="warning" emoji="📝">without an explicitbackground-color, the Feishu doc renders the callout block with no color. This PR addsfixCalloutType()which maps the semantictype=attribute to the correspondingbackground-color/border-colorpair thatcreate-docaccepts.Changes
shortcuts/doc/markdown_fix.go: AddcalloutTypeColorsmapping table,fixCalloutType()function, andprepareMarkdownForCreate()helper; integratefixCalloutTypeintofixExportedMarkdown()for round-trip fidelityshortcuts/doc/docs_create.go: ApplyprepareMarkdownForCreate()to markdown before sending to MCPshortcuts/doc/docs_update.go: Same as above for the update path (both DryRun and Execute)shortcuts/doc/markdown_fix_test.go: AddTestFixCalloutTypewith 11 table-driven casestype → color mapping
warninglight-yellowyellowinfo/notelight-bluebluetip/success/checklight-greengreenerror/dangerlight-redredcautionlight-orangeorangeimportantlight-purplepurpleExplicit
background-colororborder-colorattributes on the tag are always preserved (never overwritten).Test Plan
go test ./shortcuts/doc/...) — coverage 64.5%go vet ./...cleangolangci-lint run --new-from-rev=origin/main— 0 issuesgofmtcleanRelated Issues
type=semantic shorthand🤖 Generated with Claude Code
Summary by CodeRabbit