Skip to content

Commit

Permalink
handle sideeffects of typographic opening/closing double quotation marks
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Blätte authored and Andreas Blätte committed Apr 23, 2023
1 parent 6145e58 commit db73937
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -31,6 +31,8 @@ tooltips based on corpus positions.
* New function `href()` to add hypertext references to fulltext output.
* Method `read()` has new argument `annotation` to get values for arguments
`highlight`, `tooltips` and `href` from a subcorpus object.
* Internally, variants of opening/closing double quotes are removed that interfere
with html output.

# polmineR v0.8.8

Expand Down
48 changes: 36 additions & 12 deletions R/as.markdown.R
Expand Up @@ -3,18 +3,18 @@ NULL

#' Get markdown-formatted full text of a partition.
#'
#' The method is the worker behind the \code{read}-method, which will be called
#' usually to reconstruct the full text of a \code{partition} and read it. The
#' \code{as.markdown}-method can be customized for different classes inheriting
#' from the \code{partition}-class.
#' The method is the worker behind the `read()`-method, which will be called
#' usually to reconstruct the full text of a `partition` and read it. The
#' `as.markdown()`-method can be customized for different classes inheriting
#' from the `partition`-class.
#'
#' @param .Object The object to be converted, a \code{partition}, or a class
#' inheriting from \code{partition}, such as \code{plpr_partition}.
#' @param meta The metainformation (s-attributes) to be displayed.
#' @param cpos A \code{logical} value, whether to add cpos as ids in span elements.
#' @param interjections A \code{logical} value, whether to format interjections.
#' @param cutoff The maximum number of tokens to reconstruct, to avoid that full text is
#' excessively long.
#' @param cpos A `logical` value, whether to add cpos as ids in span elements.
#' @param interjections A `logical` value, whether to format interjections.
#' @param cutoff The maximum number of tokens to reconstruct, to avoid that full
#' text is excessively long.
#' @param template A template for formating output.
#' @param verbose A \code{logical} value, whether to output messages.
#' @param ... further arguments
Expand All @@ -32,10 +32,32 @@ setGeneric("as.markdown", function(.Object, ...) standardGeneric("as.markdown"))
# vectorized sprintf is considerably faster than shiny::span,
# an alternative that could be considered
.tagTokens <- function(tokens){
if (is.null(names(tokens))) {
return( sprintf('<span token="%s" class="fulltext">%s</span>', tokens, tokens) )

# This is different from purging markdown doc from signs that would interfere
# with markdown formatting syntax: We replace signs that would mess up
# opening and closing double quotes here.

if ('"' %in% tokens) tokens[which(tokens == '"')] <- "'"
if ('' %in% tokens) tokens[which(tokens == '')] <- "'"
if ('' %in% tokens) tokens[which(tokens == '')] <- "'"

if (is.null(names(tokens))){
return(
sprintf(
'<span token="%s" class="fulltext">%s</span>',
tokens,
tokens
)
)
} else {
return( sprintf('<span id="%s" token="%s" class="fulltext">%s</span>', names(tokens), tokens, tokens) )
return(
sprintf(
'<span id="%s" token="%s" class="fulltext">%s</span>',
names(tokens),
tokens,
tokens
)
)
}
}

Expand Down Expand Up @@ -70,7 +92,9 @@ setMethod(
.message("as.markdown", verbose = verbose)
# ensure that template requested is available
if (is.null(template)){
warning(sprintf("No template available for corpus '%s', using default template.", get_corpus(.Object)))
cli_alert_warning(
"No template available for corpus {.val {get_corpus(.Object)}}. Using default template."
)
template <- default_template
}
if (is.null(template[["paragraphs"]])){
Expand Down
6 changes: 5 additions & 1 deletion R/read.R
Expand Up @@ -210,7 +210,11 @@ setMethod("read", "data.table", function(.Object, col, partition_bundle, highlig
DT <- .Object[which(.Object[[col]] > 0)]
partitionsToGet <- DT[["partition"]]
if (col == "TOTAL") col <- colnames(.Object)[2:(ncol(.Object)-1)]
toRead <- as.bundle(lapply(partitionsToGet, function(x) partition_bundle@objects[[x]]))
toRead <- as.bundle(
lapply(
partitionsToGet,
function(x) partition_bundle@objects[[x]])
)
read(toRead, highlight = list(yellow = col), ...)
})

Expand Down
6 changes: 4 additions & 2 deletions inst/css/tooltips.css
Expand Up @@ -8,7 +8,8 @@
/* Tooltip text */
.tooltipping .tooltippingtext {
visibility: hidden;
width: auto;
/* width: auto; */
width: 180px;
background-color: #555;
color: #fff;
text-align: center;
Expand All @@ -24,7 +25,8 @@
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
/* margin-left: auto; */
margin-left: -90px;

/* Fade in tooltip */
opacity: 0;
Expand Down

0 comments on commit db73937

Please sign in to comment.