@@ -144,22 +144,39 @@ create_sidebar_headings <- function(nodes) {
144
144
# ' @param name the name of the current chapter
145
145
# ' @param html the html of the current chapter. defaults to a link that will
146
146
# ' produce a sidebar with no links to headings.
147
+ # ' @param disable_numbering a boolean indicating if the sidebar should not automatically
148
+ # ' number the chapters. Defaults to `FALSE`. If `TRUE`, developers should consider
149
+ # ' adding their own custom numbering to the chapter titles in the frontmatter.
147
150
# ' @return a character vector of HTML divs that can be appended to display the
148
151
# ' sidebar.
149
152
# ' @keywords internal
150
153
# ' @seealso [create_sidebar_item()] for creation of individual sidebar items,
151
154
# ' [set_globals()] for where `create_sidebar()` is called and
152
155
# ' [build_html()] for where `update_sidebar()` is called.
153
156
# ' @rdname create_sidebar
154
- create_sidebar <- function (chapters , name = " " , html = " <a href='https://carpentries.org'/>" ) {
157
+ create_sidebar <- function (
158
+ chapters ,
159
+ name = " " ,
160
+ html = " <a href='https://carpentries.org'/>" ,
161
+ disable_numbering = FALSE ) {
155
162
res <- character (length(chapters ))
163
+
156
164
for (i in seq(chapters )) {
157
165
position <- if (name == chapters [i ]) " current" else i
158
166
info <- get_navbar_info(chapters [i ])
159
- # We use zero index to count the index page (which is removed later)
167
+
168
+ numbering_prefix = paste0(i - 1 , " . " )
169
+ # if numbering is disabled, remove list numbering prefix
170
+ if (disable_numbering ) {
171
+ numbering_prefix = " "
172
+ }
173
+
174
+ # We use zero index to count the index page
175
+ # (which is removed later if automated numbering is enabled)
160
176
page_link <- paste0(
161
177
" <a href='" , info $ href , " '>" ,
162
- i - 1 , " . " , parse_title(info $ pagetitle ),
178
+ numbering_prefix ,
179
+ parse_title(info $ pagetitle ),
163
180
" </a>"
164
181
)
165
182
res [i ] <- create_sidebar_item(html , page_link , position )
@@ -253,7 +270,7 @@ update_sidebar <- function(
253
270
# '
254
271
# ' # Add an anchor to the links
255
272
# ' snd$fix_sidebar_href(my_links, scheme = "https", fragment = "anchor")
256
- # '
273
+ # '
257
274
# ' # NOTE: this will _always_ return a character vector, even if the input is
258
275
# ' # incorrect
259
276
# ' snd$fix_sidebar_href(list(), server = "example.com")
0 commit comments