feat(parser/renderer): implement badge/pill component with |Label|{.variant} syntax#92
Open
teezeit wants to merge 1 commit intoakonan:mainfrom
Open
feat(parser/renderer): implement badge/pill component with |Label|{.variant} syntax#92teezeit wants to merge 1 commit intoakonan:mainfrom
teezeit wants to merge 1 commit intoakonan:mainfrom
Conversation
Adds inline badges for status labels, counts, and filter chips.
Parser detects |Label| and |Label|{.variant} in both plain and rich-content
paragraphs; renderers (HTML, React, Tailwind) and all 7 CSS styles updated.
Includes 23 new tests and docs updated across SKILL.md, syntax references,
QUICK-REFERENCE.md, SYNTAX-SPEC, and guide.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the badge/pill component proposed in the wiremd spec (
docs/api/types.mdreferences aBadgeNodethat was never wired up). This PR adds the full stack: parser detection, HTML/React/Tailwind renderers, CSS for all 7 styles, tests, and documentation.Syntax
Variants:
success·warning·error·primary· (none = neutral gray)Why
|Label|instead of`Label`{.pill}The spec proposed backtick-attribute syntax (
`Active`{.pill .success}). We evaluated both options and chose|Label|for three reasons:Backticks are already code in CommonMark. remark tokenises
`Active`as aninlineCodenode before the wiremd transformer can intercept it. Attaching{.pill}to a backtick span would require forking or patching remark's own tokeniser — fragile and non-standard.|Label|parses trivially. A single regex (/\|([^|]+)\|(?:\s*\{([^}]*)\})?/) handles detection in any inline context, with no ambiguity against existing wiremd syntax ([buttons],:icons:,[inputs___]).Visual clarity. In a wireframe source file,
|Active|{.success}reads immediately as a distinct inline element. The backtick form looks like inline code, which would confuse readers and conflict with legitimate code spans.The one trade-off:
|is the Markdown table-cell delimiter, so|Label|cannot be used inside a table cell without escaping (\|Label\|). This is documented in the spec and the syntax guide.Changes
Parser (
src/parser/transformer.ts)|Label|and|Label|{.variant}in both plain and rich-content paragraph pathssuccess,warning,error,primary,default) are promoted toprops.variant; unrecognised classes remain inprops.classesbadgenode; mixed with text →paragraphwithbadgechildrenRenderers
src/renderer/html-renderer.ts—renderBadge()→<span class="wmd-badge [wmd-badge-variant]">text</span>src/renderer/react-renderer.ts— same, withclassNamesrc/renderer/tailwind-renderer.ts— Tailwind utility classes per variant (e.g.bg-green-100 text-green-800)Styles (
src/renderer/styles.ts)Badge CSS added to all 7 styles, each matching the style's aesthetic:
Tests
tests/parser.test.ts— 6 badge parsing tests (all variants, mixed text, multiple pills)tests/renderer.test.ts— 5 HTML rendering teststests/react-renderer.test.ts— 3 React rendering teststests/tailwind-renderer.test.ts— 5 Tailwind rendering testsDocs
SYNTAX-SPEC-v0.1.md§7.4 — updated from unimplemented backtick spec to|Label|with parser rules and table-cell limitationQUICK-REFERENCE.md— added to component table, disambiguation rules, tipsdocs/guide/syntax.md— new Badges/Pills section with examples and gotchaChecklist
npm test)npm run typecheck)examples/pills-test.md, pre-rendered for all 7 styles)