9494 Links = Links , Links2 = Links2 ,
9595 ... )
9696 )
97- list (outlines = outlines , info = attr(h , " info" ))
97+ list (outlines = outlines , info = attr(h , " info" ),
98+ concordance = attr(h , " concordance" ))
9899 }
99100 structure(lapply(db , rd2lines , standalone = FALSE , ... ),
100101 pkgdir = pkgdir , src.type = src.type ,
@@ -115,13 +116,14 @@ pkg2HTML <- function(package, dir = NULL, lib.loc = NULL,
115116 ... ,
116117 Rhtml = FALSE ,
117118 mathjax_config = file.path(R.home(" doc" ), " html" , " mathjax-config.js" ),
118- include_description = TRUE )
119+ include_description = TRUE ,
120+ concordance = FALSE )
119121{
120122 toc_entry <- match.arg(toc_entry )
121123 hcontent <- .convert_package_rdfiles(package = package , dir = dir , lib.loc = lib.loc ,
122124 outputEncoding = outputEncoding ,
123125 Rhtml = Rhtml , hooks = hooks ,
124- texmath = " katex" , prism = prism , ... )
126+ texmath = " katex" , prism = prism , concordance = concordance , ... )
125127 descfile <- attr(hcontent , " descfile" )
126128 src.type <- attr(hcontent , " src.type" )
127129 pkgdir <- attr(hcontent , " pkgdir" )
@@ -177,8 +179,19 @@ pkg2HTML <- function(package, dir = NULL, lib.loc = NULL,
177179 MATHJAX_CONFIG_STATIC = mathjax_config ,
178180 language = language )
179181
180- writeHTML <- function (... , sep = " \n " , append = TRUE )
182+ linecount <- 0L
183+ writeHTML <- function (... , sep = " \n " , append = TRUE ) {
181184 cat(... , file = out , sep = sep , append = append )
185+ if (concordance ) {
186+ if (! append )
187+ linecount <<- 0L
188+ if (sep == " \n " )
189+ linecount <<- linecount + sum(lengths(list (... )))
190+ # Also add any embedded newlines...
191+ linecount <<- linecount + sum(sapply(list (... ),
192+ function (s ) sum(unlist(gregexpr(" \n " , s , fixed = TRUE )) > 0 )))
193+ }
194+ }
182195
183196 # # cat(hfcomps$header, fill = TRUE) # debug
184197 writeHTML(hfcomps $ header , sep = " " , append = FALSE )
@@ -200,7 +213,17 @@ pkg2HTML <- function(package, dir = NULL, lib.loc = NULL,
200213 ' <main>' )
201214
202215 if (include_description ) writeHTML(.DESCRIPTION_to_HTML(descfile ))
203- lapply(hcontent , function (h ) writeHTML(" <hr>" , h $ outlines ))
216+ lapply(hcontent , function (h ) {
217+ if (concordance ) {
218+ conc <- h $ concordance
219+ if (inherits(conc , " Rconcordance" )) {
220+ conc $ offset <- conc $ offset + linecount + 1L
221+ h $ outlines [length(h $ outlines )] <-
222+ paste(" <!--" , as.character(conc ), " -->" )
223+ }
224+ }
225+ writeHTML(" <hr>" , h $ outlines )
226+ })
204227 writeHTML(' </main>' )
205228 writeHTML(hfcomps $ footer , sep = " " )
206229 invisible (out )
0 commit comments