### Bug description

Hi! This was interesting issue to pin down: rendering plain .qmd with special characters (the letter **š** to be precise) to .html works on my machine but fails to render them when there's an r code chunk inside the file.  My .qmd file contains special characters and the file was saved as UTF-8.

# Reprex

To reproduce, render the following content in a .qmd file to .html (GitHub doesn't allow attaching .qmd files?):


```
---
title: "Funky .qmd file"
---

The following are special characters:

ąčęėįšųū
  
  ```{r}

plot(pressure)

     ```

```
# Output

The rendered .html file body contains the following text:

```
<html>
<body>
<!--StartFragment-->

<p>The following are special characters:</p>
--
  | <p>ąčęėį</p>

<!--EndFragment-->
</body>
</html>
```

And the console throws the following warning:

```
Warning messages:
1: In readLines(con, warn = FALSE) :
  invalid input found on input connection 'index.qmd'
2: In xfun::read_utf8(input) :
  The file index.qmd is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 8
3: In readLines(con, warn = FALSE) :
  invalid input found on input connection 'index.knit.md'
4: In readLines(con, warn = FALSE) :
  invalid input found on input connection './index.knit.md'
5: In readLines(con, warn = FALSE) :
  invalid input found on input connection 'index.qmd'
```

This seems to be an issue with `knitr` having trouble with special characters but I've tried rendering the same content using the `knitr` package from .Rmd to .md via knitr, and from .md to .html via quarto...and it worked? I think the problem stems from differences in what knitr engine Quarto uses and the `knitr` package itself but I'm not sure how to troubleshoot further. Help appreciated!

# Session Info

```
R version 4.1.3 (2022-03-10)
RStudio v2022,07.1
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=Lithuanian_Lithuania.1257  LC_CTYPE=Lithuanian_Lithuania.1257   
[3] LC_MONETARY=Lithuanian_Lithuania.1257 LC_NUMERIC=C                         
[5] LC_TIME=Lithuanian_Lithuania.1257    

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9      ps_1.7.1        digest_0.6.29   later_1.3.0     R6_2.5.1        jsonlite_1.8.0 
 [7] magrittr_2.0.2  evaluate_0.15   highr_0.9       stringi_1.7.6   rlang_1.0.2     cli_3.3.0      
[13] renv_0.15.5     rstudioapi_0.13 rmarkdown_2.14  tools_4.1.3     stringr_1.4.0   xfun_0.30      
[19] yaml_2.3.5      fastmap_1.1.0   compiler_4.1.3  processx_3.7.0  htmltools_0.5.2 knitr_1.38     
[25] quarto_1.2     
```

### `quarto check` Output

```
[>] Checking Quarto installation......OK
      Version: 1.0.37
      Path: C:\Users\Paulius\AppData\Local\Programs\Quarto\bin\
      CodePage: 1257

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.8.3
      Path: C:/Users/Paulius/AppData/Local/Programs/Python/Python38-32/python.exe
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with py -m pip install jupyter

[>] Checking R installation...........OK
      Version: 4.1.3
      Path: C:/PROGRA~1/R/R-41~1.3
      LibPaths:
        - C:/Users/Paulius/Documents/R/win-library/4.1
        - C:/Program Files/R/R-4.1.3/library
      rmarkdown: 2.13
```

[>] Checking Knitr engine render......OK

### `quarto tools check` Output

```
Tool         Status                    Installed     Latest
chromium     Not installed             ---           869685
tinytex      External Installation     ---           v2022.08
```

### Checklist

- [X] [formatted your issue](https://yihui.org/issue/#please-format-your-issue-correctly) so it is easier for us to read?
- [X] included a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [X] documented the quarto version you're running, by pasting the output from running `quarto check` in the "Quarto Check Output" text area?
- [X] documented the version of the quarto tools you're running, by providing the output from running `quarto tools check` in the "Quarto Tools Check Output" text area?
- [X] documented the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] documented which operating system you're running? If on Linux, please provide the specific distribution as well.
- [X] upgraded to the latest version, including your versions of R, the RStudio IDE, and relevant R packages?
2022-08-07T20:22:51Z
Alaburda
bug
v1.1
closed
.qmd stops rendering at special characters if there is an r code chunk
https://github.com/quarto-dev/quarto-cli/issues/1723