diff --git a/R/ebook.R b/R/ebook.R index 4f38b42e0..22974f75e 100644 --- a/R/ebook.R +++ b/R/ebook.R @@ -116,13 +116,14 @@ resolve_refs_md = function(content, ref_table, to_md = output_md()) { for (j in ids) { m = sprintf('\\(\\\\#%s\\)', j) if (grepl(m, content[i])) { - id = ''; sep = ':' + id = ''; sep = ':'; bold = FALSE type = gsub('^([^:]+).*$', '\\1', j) if (type %in% theorem_abbr) { id = sprintf('', j) sep = '' + bold = TRUE } - label = label_prefix(type, sep = sep)(ref_table[j]) + label = label_prefix(type, sep = sep, bold = bold)(ref_table[j]) content[i] = sub(m, paste0(id, label, ' '), content[i]) break } diff --git a/R/html.R b/R/html.R index 6b04a4cda..a422bd6bd 100644 --- a/R/html.R +++ b/R/html.R @@ -693,7 +693,7 @@ parse_fig_labels = function(content, global = FALSE) { # given a label, e.g. fig:foo, figure out the appropriate prefix -label_prefix = function(type, dict = label_names, sep = '') { +label_prefix = function(type, dict = label_names, sep = '', bold = FALSE) { label = i18n('label', type, dict) supported_type = c('fig', 'tab', 'eq') if (is.function(label)) { @@ -703,7 +703,8 @@ label_prefix = function(type, dict = label_names, sep = '') { } function(num = NULL) { if (is.null(num)) return(label) - paste0(label, num, sep) + label = paste0(label, num, sep) + if (bold) sprintf("**%s**", label) else label } } diff --git a/tests/testit/test-html.R b/tests/testit/test-html.R index 6fa4178de..4851b95b1 100644 --- a/tests/testit/test-html.R +++ b/tests/testit/test-html.R @@ -49,12 +49,16 @@ assert("i18n config can be retrieved ", { opts$set(config = list()) }) +assert("label_prefix can set text to bold", { + (is.function(label_prefix("fig"))) + (label_prefix("fig")(1) %==% "Figure 1") + (label_prefix("fig", bold = TRUE)(1) %==% "**Figure 1**") + (label_prefix("fig", sep = ":")(1) %==% "Figure 1:") +}) + assert("label_prefix retrieves correct config", { fun = function(i) paste0("TAB-", i) opts$set(config = list(language = list(label = list(tab = fun)))) (label_prefix("tab") %==% fun) - (is.function(label_prefix("fig"))) - (label_prefix("fig")(1) %==% "Figure 1") - (label_prefix("fig", sep = ":")(1) %==% "Figure 1:") opts$set(config = list()) })