yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.36k stars 873 forks source link

`* 2.` does not produce <li>2.</li> #2337

Closed jpcaveiro closed 2 months ago

jpcaveiro commented 2 months ago

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.


This does **not** produce <li>2.</li>:

* 2.  
* 3.
* 4.
* 5.

This does produce <li>2.123</li>:

* 2.123
* 3.3
* 4.34564523
* 5.

This does produce <li>6</li>:

* 6
* 7
* 8
* 9
> xfun::session_info('knitr')
R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621), RStudio 2023.12.1.402

Locale:
  LC_COLLATE=Portuguese_Portugal.utf8  LC_CTYPE=C                          
  LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C                        
  LC_TIME=Portuguese_Portugal.utf8    
system code page: 65001

Package version:
  evaluate_0.23   graphics_4.3.3  grDevices_4.3.3 highr_0.10      knitr_1.45     
  methods_4.3.3   stats_4.3.3     tools_4.3.3     utils_4.3.3     xfun_0.43      
  yaml_2.3.8  
atusy commented 2 months ago

This behavior comes from Pandoc which parses * 2. as a bullet list containing an ordered list.

» echo '* 2.' | pandoc -t native                                                                                                                                                
[ BulletList
    [ [ OrderedList ( 2 , Decimal , Period ) [ [] ] ] ]
]

You need backslash escape to avoid the behavior.

» echo '* 2\.' | pandoc -t native                                                                                                                                                
[ BulletList
    [ [ OrderedList ( 2 , Decimal , Period ) [ [] ] ] ]
]

Just for the next time you face unexpected behaviors with markdown syntax, I would recommend inspect Pandoc's behavior. knitr only deals with chunks and inline chunks, not with markdown syntaxes in general.