Skip to content

Commit

Permalink
fix #130: check the lenght of the provided caption
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Nov 15, 2014
1 parent 5ca6c70 commit fa4a47e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
14 changes: 14 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,17 @@ splitLine <- function(x, max.width = panderOptions('table.split.cells'), use.hyp
koRpus::hyphen(s, hyph.pattern = 'en.us', quiet = TRUE)@hyphen[1, 2]
.Call('pander_splitLine_cpp', PACKAGE = 'pander', x, max.width, use.hyphening, hyphen_f)
}


#' Check if caption is valid
#' @param caption R object to check
#' @return boolean
#' @keywords internal
check_caption <- function(caption) {

if (length(caption) > 1)
stop('The caption should be exactly one string.')

if (is.character(caption) | is.null(caption))
stop('The caption should be string (character class) or NULL.')
}
5 changes: 4 additions & 1 deletion R/pandoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ pandoc.link <- function(...)
#' @references John MacFarlane (2012): _Pandoc User's Guide_. \url{http://johnmacfarlane.net/pandoc/README.html}
pandoc.image.return <- function(img, caption = storage$caption) {

check_caption(caption)

if (is.null(caption))
caption <- ''

Expand Down Expand Up @@ -1021,6 +1023,7 @@ pandoc.table.return <- function(t, caption, digits = panderOptions('digits'), de
res <- paste0(res, '\n\n')

## (optional) caption
check_caption(caption)
if (!is.null(caption) && caption != '')
res <- paste0(res, panderOptions('table.caption.prefix'), caption, '\n\n')

Expand Down Expand Up @@ -1062,7 +1065,7 @@ pandoc.formula.return <- function(x, text = NULL, max.width = 80, caption, add.l
if (add.line.breaks)
res <- paste(res, "\n\n")
## (optional) caption
if (!is.null(caption) && caption != '')
if (!is.null(caption) && caption != '' && check_caption(caption))
res <- paste0(res, panderOptions('formula.caption.prefix'), caption, '\n\n')
return(res)
}
Expand Down
18 changes: 18 additions & 0 deletions man/check_caption.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{check_caption}
\alias{check_caption}
\title{Check if caption is valid}
\usage{
check_caption(caption)
}
\arguments{
\item{caption}{R object to check}
}
\value{
boolean
}
\description{
Check if caption is valid
}
\keyword{internal}

0 comments on commit fa4a47e

Please sign in to comment.