@@ -7,8 +7,12 @@ function panelTabset()
77 return {
88 -- tabsets and callouts
99 Div = function (div )
10- if hasBootstrap () and div .attr .classes :find (" panel-tabset" ) then
11- return tabsetDiv (div )
10+ if div .attr .classes :find (" panel-tabset" ) then
11+ if hasBootstrap () then
12+ return tabsetDiv (div , bootstrapTabs ())
13+ else
14+ return tabsetDiv (div , tabbyTabs ())
15+ end
1216 elseif isLatexOutput () or isDocxOutput () or isEpubOutput () then
1317 return tabsetLatex (div )
1418 else
@@ -18,7 +22,8 @@ function panelTabset()
1822 }
1923end
2024
21- function tabsetDiv (div )
25+
26+ function tabsetDiv (div , renderer )
2227
2328 -- create a unique id for the tabset
2429 local tabsetid = " tabset-" .. tabsetidx
@@ -44,7 +49,7 @@ function tabsetDiv(div)
4449
4550 -- init tab navigation
4651 local nav = pandoc .List :new ()
47- nav :insert (pandoc .RawInline (' html' , ' <ul class="nav nav-tabs" role="tablist" >' ))
52+ nav :insert (pandoc .RawInline (' html' , ' <ul ' .. renderer . ulAttribs ( tabsetid ) .. ' >' ))
4853
4954 -- init tab panes
5055 local panes = pandoc .Div ({}, div .attr )
@@ -68,26 +73,14 @@ function tabsetDiv(div)
6873 local tablinkid = tabid .. " -tab"
6974
7075 -- navigation
71- local active = " "
72- local selected = " false"
73- if i == 1 then
74- active = " active"
75- selected = " true"
76- end
77- nav :insert (pandoc .RawInline (' html' , ' <li class="nav-item" role="presentation">' ))
78- nav :insert (pandoc .RawInline (' html' , ' <a class="nav-link' .. active .. ' " id="' .. tablinkid .. ' " data-bs-toggle="tab" data-bs-target="#' .. tabid .. ' " role="tab" aria-controls="' .. tabid .. ' " aria-selected="' .. selected .. ' ">' ))
76+ nav :insert (pandoc .RawInline (' html' , ' <li ' .. renderer .liAttribs () .. ' >' ))
77+ nav :insert (pandoc .RawInline (' html' , ' <a ' .. renderer .liLinkAttribs (tabid , i == 1 ) .. ' >' ))
7978 nav :extend (heading .content )
8079 nav :insert (pandoc .RawInline (' html' , ' </a></li>' ))
8180
8281 -- pane
83- local pane = pandoc .Div ({}, heading .attr )
84- pane .attr .identifier = tabid
85- pane .attr .classes :insert (" tab-pane" )
86- if i == 1 then
87- pane .attr .classes :insert (" active" )
88- end
89- pane .attr .attributes [" role" ] = " tabpanel"
90- pane .attr .attributes [" aria-labeledby" ] = tablinkid
82+ local paneAttr = renderer .paneAttribs (tabid , i == 1 , heading .attr )
83+ local pane = pandoc .Div ({}, paneAttr )
9184 pane .content :extend (tab .content )
9285 panes .content :insert (pane )
9386 end
@@ -104,6 +97,63 @@ function tabsetDiv(div)
10497 end
10598end
10699
100+ function bootstrapTabs ()
101+ return {
102+ ulAttribs = function (tabsetid )
103+ return ' class="nav nav-tabs" role="tablist"'
104+ end ,
105+ liAttribs = function (tabid , isActive )
106+ return ' class="nav-item" role="presentation"'
107+ end ,
108+ liLinkAttribs = function (tabid , isActive )
109+ local tablinkid = tabid .. " -tab"
110+ local active = " "
111+ local selected = " false"
112+ if isActive then
113+ active = " active"
114+ selected = " true"
115+ end
116+ return ' class="nav-link' .. active .. ' " id="' .. tablinkid .. ' " data-bs-toggle="tab" data-bs-target="#' .. tabid .. ' " role="tab" aria-controls="' .. tabid .. ' " aria-selected="' .. selected .. ' "'
117+ end ,
118+ paneAttribs = function (tabid , isActive , headingAttribs )
119+ local tablinkid = tabid .. " -tab"
120+ local attribs = headingAttribs :clone ()
121+ attribs .identifier = tabid
122+ attribs .classes :insert (" tab-pane" )
123+ if isActive then
124+ attribs .classes :insert (" active" )
125+ end
126+ attribs .attributes [" role" ] = " tabpanel"
127+ attribs .attributes [" aria-labeledby" ] = tablinkid
128+ return attribs
129+ end
130+ }
131+ end
132+
133+ function tabbyTabs ()
134+ return {
135+ ulAttribs = function (tabsetid )
136+ return ' id="' .. tabsetid .. ' " class="panel-tabset-tabby"'
137+ end ,
138+ liAttribs = function (tabid , isActive )
139+ return ' '
140+ end ,
141+ liLinkAttribs = function (tabid , isActive )
142+ local default = " "
143+ if isActive then
144+ default = " data-tabby-default "
145+ end
146+ return default .. ' href="#' .. tabid .. ' "'
147+ end ,
148+ paneAttribs = function (tabid , isActive , headingAttribs )
149+ local attribs = headingAttribs :clone ()
150+ attribs .identifier = tabid
151+ return attribs
152+ end
153+ }
154+ end
155+
156+
107157function tabsetLatex (div )
108158 -- find the first heading in the tabset
109159 local heading = div .content :find_if (function (el ) return el .t == " Header" end )
0 commit comments