Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extractPreserveChunks() when string contains emoji unicode on Windows #156

Closed
shrektan opened this issue Feb 19, 2020 · 1 comment · Fixed by #157
Closed

extractPreserveChunks() when string contains emoji unicode on Windows #156

shrektan opened this issue Feb 19, 2020 · 1 comment · Fixed by #157

Comments

@shrektan
Copy link
Contributor

When the string contains emoji Unicode like "\U0001F937" on Windows , extractPreserveChunks() returns unexpected results.

It leads to an issue that when the user compiles an Rmd file with such Unicode strings on Windows, the htmlwidgets of the HTML output file after the line contains the emoji string, can't be displayed properly, e.g., rstudio/DT#661

The cause of this issue I believe is that gregexpr(perl = FALSE) (the default) can't handle such cases properly on Windows (I don't know the reason). By explicitly using perl = TRUE will fix this issue.

matches <- gregexpr(pattern, strval)[[1]]

R code to reproduce

x <- "<!--html_preserve-->chunck1<!--/html_preserve-->\U0001F937<!--html_preserve-->chunck2<!--/html_preserve-->"
htmltools::extractPreserveChunks(x)

The output

$value
[1] "preserve054aaf381ec98343\U0001f937<preserve86252470130ed05d"

$chunks
preserve86252470130ed05d preserve054aaf381ec98343 
               "hunck2<"                "chunck1" 

The session info

R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936 
[2] LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.4.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3      rstudioapi_0.11 knitr_1.28      whisker_0.4    
 [5] magrittr_1.5    xtable_1.8-4    R6_2.4.1        rlang_0.4.2    
 [9] fastmap_1.0.1   tools_3.6.2     xfun_0.12       miniUI_0.1.1.1 
[13] clipr_0.7.0     htmltools_0.4.0 digest_0.6.23   processx_3.4.2 
[17] callr_3.4.2     later_1.0.0     fs_1.3.1        promises_1.1.0 
[21] ps_1.3.0        evaluate_0.14   mime_0.8        rmarkdown_2.1  
[25] reprex_0.3.0    compiler_3.6.2  jsonlite_1.6    httpuv_1.5.2 
@cpsievert
Copy link
Collaborator

It appears that the perl = TRUE change in #157 didn't fix this for any version of perl on windows. https://github.com/rstudio/htmltools/runs/750362532#step:12:284

cpsievert added a commit that referenced this issue Jun 9, 2020
* Use fixed=TRUE when finding preserve chunk locations, closes #156

* Store match.length attr directly as `lengths`

Co-authored-by: Barret Schloerke <[email protected]>

* make sure not to return (instead error) if one marker is present but the other is missing

Co-authored-by: Barret Schloerke <[email protected]>
cpsievert added a commit that referenced this issue Jun 10, 2020
* Use fixed=TRUE when finding preserve chunk locations, closes #156

* Store match.length attr directly as `lengths`

Co-authored-by: Barret Schloerke <[email protected]>

* make sure not to return (instead error) if one marker is present but the other is missing

Co-authored-by: Barret Schloerke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants