@@ -2,20 +2,200 @@ import { describe, it, expect } from "vitest";
22import dedent from "dedent" ;
33
44import { process } from "./util/index" ;
5+ import { type FlexibleContainerOptions } from "../src" ;
56
67describe ( "nesting with varying fence lengths" , ( ) => {
78 it ( "supports an outer 4-colon container with inner 3-colon containers" , async ( ) => {
89 const input = dedent `
910 :::: tab-group My Group
11+
1012 ::: tab Some Tab
1113 :::
14+
1215 ::: tab Another tab
1316 :::
17+
18+ ::::
19+ ` ;
20+
21+ expect ( await process ( input ) ) . toMatchInlineSnapshot (
22+ `"<div class="remark-container tab-group"><div class="remark-container-title tab-group">My Group</div><div class="remark-container tab"><div class="remark-container-title tab">Some Tab</div></div><div class="remark-container tab"><div class="remark-container-title tab">Another tab</div></div></div>"` ,
23+ ) ;
24+ } ) ;
25+
26+ it ( "supports custom component names (TabGroup/CodeTab) and custom title components" , async ( ) => {
27+ const options : FlexibleContainerOptions = {
28+ containerTagName ( type ) {
29+ if ( type === "tab-group" ) return "TabGroup" ;
30+ if ( type === "tab" ) return "CodeTab" ;
31+ return "div" ;
32+ } ,
33+ containerClassName ( type ) {
34+ if ( type === "tab-group" ) return [ "tab-group" ] ;
35+ if ( type === "tab" ) return [ "tab" ] ;
36+ return [ "remark-container" , type ?? "" ] ;
37+ } ,
38+ titleTagName ( type ) {
39+ if ( type === "tab-group" ) return "TabGroupTitle" ;
40+ if ( type === "tab" ) return "CodeTabTitle" ;
41+ return "div" ;
42+ } ,
43+ titleClassName ( type ) {
44+ if ( type === "tab-group" ) return [ "tab-group-title" ] ;
45+ if ( type === "tab" ) return [ "tab-title" ] ;
46+ return [ "remark-container-title" ] ;
47+ } ,
48+ } ;
49+
50+ const input = dedent `
51+ :::: tab-group My Group
52+
53+ ::: tab Some Tab
54+ :::
55+
56+ ::: tab Another tab
57+ :::
58+
59+ ::::
60+ ` ;
61+
62+ expect ( await process ( input , options ) ) . toMatchInlineSnapshot (
63+ `"<TabGroup class="tab-group"><TabGroupTitle class="tab-group-title">My Group</TabGroupTitle><CodeTab class="tab"><CodeTabTitle class="tab-title">Some Tab</CodeTabTitle></CodeTab><CodeTab class="tab"><CodeTabTitle class="tab-title">Another tab</CodeTabTitle></CodeTab></TabGroup>"` ,
64+ ) ;
65+ } ) ;
66+
67+ it ( "supports custom tag names (tab-group/code-tab) and custom title tags" , async ( ) => {
68+ const options : FlexibleContainerOptions = {
69+ containerTagName ( type ) {
70+ if ( type === "tab-group" ) return "tab-group" ;
71+ if ( type === "tab" ) return "code-tab" ;
72+ return "div" ;
73+ } ,
74+ containerClassName ( type ) {
75+ if ( type === "tab-group" ) return [ "tabs" ] ;
76+ if ( type === "tab" ) return [ "tab" ] ;
77+ return [ "remark-container" , type ?? "" ] ;
78+ } ,
79+ titleTagName ( type ) {
80+ if ( type === "tab-group" ) return "tab-group-title" ;
81+ if ( type === "tab" ) return "code-tab-title" ;
82+ return "div" ;
83+ } ,
84+ titleClassName ( type ) {
85+ if ( type === "tab-group" ) return [ "tabs-title" ] ;
86+ if ( type === "tab" ) return [ "tab-title" ] ;
87+ return [ "remark-container-title" ] ;
88+ } ,
89+ } ;
90+
91+ const input = dedent `
92+ :::: tab-group My Group
93+
94+ ::: tab First
95+ :::
96+
97+ ::: tab Second
98+ :::
99+
100+ ::::
101+ ` ;
102+
103+ expect ( await process ( input , options ) ) . toMatchInlineSnapshot (
104+ `"<tab-group class="tabs"><tab-group-title class="tabs-title">My Group</tab-group-title><code-tab class="tab"><code-tab-title class="tab-title">First</code-tab-title></code-tab><code-tab class="tab"><code-tab-title class="tab-title">Second</code-tab-title></code-tab></tab-group>"` ,
105+ ) ;
106+ } ) ;
107+
108+ it ( "supports passing custom properties to containers and titles" , async ( ) => {
109+ const options : FlexibleContainerOptions = {
110+ containerTagName ( type ) {
111+ if ( type === "tab-group" ) return "tab-group" ;
112+ if ( type === "tab" ) return "code-tab" ;
113+ return "div" ;
114+ } ,
115+ containerClassName ( type ) {
116+ if ( type === "tab-group" ) return [ "tabs" ] ;
117+ if ( type === "tab" ) return [ "tab" ] ;
118+ return [ "remark-container" , type ?? "" ] ;
119+ } ,
120+ containerProperties ( type , title ) {
121+ if ( type === "tab-group" ) return { role : "tablist" , "data-kind" : "group" } as const ;
122+ if ( type === "tab" ) return { role : "tab" , "data-tab" : title } as const ;
123+ return { } as const ;
124+ } ,
125+ titleTagName ( type ) {
126+ if ( type === "tab-group" ) return "tab-group-title" ;
127+ if ( type === "tab" ) return "code-tab-title" ;
128+ return "div" ;
129+ } ,
130+ titleClassName ( type ) {
131+ if ( type === "tab-group" ) return [ "tabs-title" ] ;
132+ if ( type === "tab" ) return [ "tab-title" ] ;
133+ return [ "remark-container-title" ] ;
134+ } ,
135+ titleProperties ( type , title ) {
136+ if ( type === "tab-group" ) return { "data-title" : title } as const ;
137+ if ( type === "tab" ) return { "aria-selected" : title === "Active" } as const ;
138+ return { } as const ;
139+ } ,
140+ } ;
141+
142+ const input = dedent `
143+ :::: tab-group My Group
144+
145+ ::: tab Active
146+ :::
147+
148+ ::: tab Passive
149+ :::
150+
151+ ::::
152+ ` ;
153+
154+ expect ( await process ( input , options ) ) . toMatchInlineSnapshot (
155+ `"<tab-group class="tabs" role="tablist" data-kind="group"><tab-group-title class="tabs-title" data-title="My Group">My Group</tab-group-title><code-tab class="tab" role="tab" data-tab="Active"><code-tab-title class="tab-title" aria-selected>Active</code-tab-title></code-tab><code-tab class="tab" role="tab" data-tab="Passive"><code-tab-title class="tab-title">Passive</code-tab-title></code-tab></tab-group>"` ,
156+ ) ;
157+ } ) ;
158+
159+ it ( "supports inline specific identifiers for tags/ids/classes for nested containers" , async ( ) => {
160+ const input = dedent `
161+ :::: tab-group {tab-group#group.tabs} My Group {tab-group-title#group-title.title}
162+
163+ ::: tab {code-tab#t1.pill} Active {code-tab-title#t1-title.pill-title}
164+ :::
165+
166+ ::: tab {code-tab#t2.pill} Passive {code-tab-title#t2-title.pill-title}
167+ :::
168+
169+ ::::
170+ ` ;
171+
172+ expect ( await process ( input ) ) . toMatchInlineSnapshot (
173+ `"<tab-group class="remark-container tab-group tabs" id="group"><tab-group-title class="remark-container-title tab-group title" id="group-title">My Group</tab-group-title><code-tab class="remark-container tab pill" id="t1"><code-tab-title class="remark-container-title tab pill-title" id="t1-title">Active</code-tab-title></code-tab><code-tab class="remark-container tab pill" id="t2"><code-tab-title class="remark-container-title tab pill-title" id="t2-title">Passive</code-tab-title></code-tab></tab-group>"` ,
174+ ) ;
175+ } ) ;
176+ } ) ;
177+
178+ // add a test for this with tags specified, e.g.
179+ // ### ::: [type] [{tagname#id.classname}] [title] [{tagname#id.classname}]
180+
181+ // so it's "<tab-group> and <single-tab>"
182+
183+ describe ( "nesting with PascalCase brace syntax" , ( ) => {
184+ it ( "supports inline specific identifiers with PascalCase tag names (TabGroup/CodeTab)" , async ( ) => {
185+ const input = dedent `
186+ :::: tab-group {TabGroup#group.tabs} My Group {TabGroupTitle#group-title.title}
187+
188+ ::: tab {CodeTab#t1.pill} Active {CodeTabTitle#t1-title.pill-title}
189+ :::
190+
191+ ::: tab {CodeTab#t2.pill} Passive {CodeTabTitle#t2-title.pill-title}
192+ :::
193+
14194 ::::
15195 ` ;
16196
17197 expect ( await process ( input ) ) . toMatchInlineSnapshot (
18- `"<div class=\ "remark-container tab-group\"><div class=\ "remark-container-title tab-group\" >My Group</div><div class=\ "remark-container tab\"><div class=\ "remark-container-title tab\">Some Tab</div ></div><div class=\ "remark-container tab\"><div class=\ "remark-container-title tab\">Another tab</div ></div ></div >"` ,
198+ `"<TabGroup class="remark-container tab-group tabs" id="group"><TabGroupTitle class="remark-container-title tab-group title" id="group-title" >My Group</TabGroupTitle><CodeTab class="remark-container tab pill" id="t1"><CodeTabTitle class="remark-container-title tab pill-title" id="t1-title">Active</CodeTabTitle ></CodeTab><CodeTab class="remark-container tab pill" id="t2"><CodeTabTitle class="remark-container-title tab pill-title" id="t2-title">Passive</CodeTabTitle ></CodeTab ></TabGroup >"` ,
19199 ) ;
20200 } ) ;
21201} ) ;
0 commit comments