Skip to content

feat(doc): expand callout type= shorthand into background-color and border-color#467

Open
herbertliu wants to merge 2 commits intomainfrom
feat/callout-type-to-color
Open

feat(doc): expand callout type= shorthand into background-color and border-color#467
herbertliu wants to merge 2 commits intomainfrom
feat/callout-type-to-color

Conversation

@herbertliu
Copy link
Copy Markdown
Collaborator

@herbertliu herbertliu commented Apr 14, 2026

Summary

When users write <callout type="warning" emoji="📝"> without an explicit background-color, the Feishu doc renders the callout block with no color. This PR adds fixCalloutType() which maps the semantic type= attribute to the corresponding background-color/border-color pair that create-doc accepts.

Changes

  • shortcuts/doc/markdown_fix.go: Add calloutTypeColors mapping table, fixCalloutType() function, and prepareMarkdownForCreate() helper; integrate fixCalloutType into fixExportedMarkdown() for round-trip fidelity
  • shortcuts/doc/docs_create.go: Apply prepareMarkdownForCreate() to markdown before sending to MCP
  • shortcuts/doc/docs_update.go: Same as above for the update path (both DryRun and Execute)
  • shortcuts/doc/markdown_fix_test.go: Add TestFixCalloutType with 11 table-driven cases

type → color mapping

type background-color border-color
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 on the tag are always preserved (never overwritten).

Test Plan

  • Unit tests pass (go test ./shortcuts/doc/...) — coverage 64.5%
  • go vet ./... clean
  • golangci-lint run --new-from-rev=origin/main — 0 issues
  • gofmt clean

Related Issues

  • Fixes callout background color missing when using type= semantic shorthand

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a Markdown checker that warns when callout blocks lack explicit background/border colors and suggests default color values during document create/update.
  • Bug Fixes
    • Create and update flows now emit the checker’s hint for Markdown callouts when a type is present but colors are missing.
  • Tests
    • Added unit tests verifying hints are produced for known types and suppressed when colors are provided or types are unknown.

…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>
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@github-actions github-actions bot added domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact labels Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Adds a new WarnCalloutType(md string, w io.Writer) utility that scans Markdown for <callout> tags missing background-color and emits formatted hints; WarnCalloutType is invoked from docs create/update code paths when a --markdown value is present. Tests for the utility were added.

Changes

Cohort / File(s) Summary
Callout warning utility
shortcuts/doc/markdown_fix.go, shortcuts/doc/markdown_fix_test.go
Added WarnCalloutType(md string, w io.Writer) plus callout-type→color mapping and regexes to detect <callout> tags missing background-color. Added unit test TestWarnCalloutType.
Docs create integration
shortcuts/doc/docs_create.go
buildDocsCreateArgs now reads the markdown flag into a local md, calls WarnCalloutType(md, runtime.IO().ErrOut), and passes md as the "markdown" arg to the MCP tool.
Docs update integration
shortcuts/doc/docs_update.go
Both DryRun and Execute flows now call WarnCalloutType(v, runtime.IO().ErrOut) when the --markdown flag value is non-empty, then set args["markdown"] = v.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

size/L

Suggested reviewers

  • fangshuyu-768

Poem

🐰 I sniffed the markdown, found callouts bare,
I whispered colors, a helpful little care.
Hints hop out gently, a pastel parade,
So docs wear borders the rabbit brigade! 🎨✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description follows the required template with all sections complete: Summary, Changes, Test Plan, and Related Issues. However, the description content refers to the original approach (fixCalloutType) rather than the revised approach (WarnCalloutType) that was implemented per reviewer feedback. Update the description to reflect the current implementation: replace references to fixCalloutType with WarnCalloutType, clarify that warnings are emitted to stderr rather than silently transforming markdown, and update test names accordingly.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding logic to expand callout type= into background-color and border-color attributes for proper Feishu rendering.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/callout-type-to-color

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 14, 2026

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@011da3d0f19e1ebfb498e884c0b00788a494f9ae

🧩 Skill update

npx skills add larksuite/cli#feat/callout-type-to-color -y -g

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
shortcuts/doc/markdown_fix.go (1)

38-40: Broaden fence detection for create-time preprocessing.

prepareMarkdownForCreate now runs on hand-authored markdown, but applyOutsideCodeFences only 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

📥 Commits

Reviewing files that changed from the base of the PR and between 20761fa and a59a0d0.

📒 Files selected for processing (4)
  • shortcuts/doc/docs_create.go
  • shortcuts/doc/docs_update.go
  • shortcuts/doc/markdown_fix.go
  • shortcuts/doc/markdown_fix_test.go

@SunPeiYang996
Copy link
Copy Markdown
Collaborator

Thanks for the PR and the thorough test coverage!
However, I think this change puts protocol-adaptation logic in the wrong layer. The type → color mapping is essentially compensating for a gap in the create-doc API itself. If we add this to the shortcut, every other client that calls create-doc will need to duplicate the same mapping.
A few specific concerns:

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.
It transforms user input without any visibility, making debugging harder.
It expands the shortcut's responsibility from "invoke MCP" to "fix MCP's input format."

Suggested alternatives:

File a feature request for create-doc to natively support type= on callout blocks.
If we need a short-term workaround, make it an explicit opt-in flag (e.g. --fix-callout-types) with a deprecation plan.
Or, surface a clear warning when type= is used without background-color, telling the user what to write instead.

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>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a59a0d0 and 011da3d.

📒 Files selected for processing (4)
  • shortcuts/doc/docs_create.go
  • shortcuts/doc/docs_update.go
  • shortcuts/doc/markdown_fix.go
  • shortcuts/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

Comment on lines +261 to +263
// Skip tags that already carry an explicit background-color.
if strings.Contains(attrs, "background-color=") {
return tag
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

@herbertliu
Copy link
Copy Markdown
Collaborator Author

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 fixCalloutType() with WarnCalloutType(), which:

  • Leaves the Markdown unchanged — user input reaches create-doc exactly as written
  • Writes a hint to stderr for each type= callout missing background-color, e.g.:
    hint: callout type="warning" has no background-color; consider: background-color="light-yellow" border-color="yellow"
    

This surfaces the issue visibly without any silent transformation. On the longer term, filing a feature request for create-doc to natively support type= makes sense — happy to do that as a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants