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

Bug with pandoc.list and one sub-element #33

Closed
mathematicalcoffee opened this issue Apr 22, 2013 · 1 comment
Closed

Bug with pandoc.list and one sub-element #33

mathematicalcoffee opened this issue Apr 22, 2013 · 1 comment

Comments

@mathematicalcoffee
Copy link

pandoc.list doesn't return the properly indented list if a sub-list has only one element.

Example

Suppose I want to make the following list:

  • one
    • two

I'd do

pandoc.list(list('one', list('two')))

However this returns

* one 
* list("two") 

If however the sublist has more than one element, everything works fine:

pandoc.list(list('one', list('two', 'three')))
* one 
    * two 
    * three  

Fix

I believe the error is in this line of pandoc.list.return.

    if (length(elements[[i]]) == 1) { # <--- THIS LINE
        paste0(paste(rep(' ', indent.level * 4), collapse = ''), marker[i-i.lag], elements[i])
    } else {
    ...

Note that in the case of the element list('two'), elements[i] has length 1 but the string representation of elements[i] is list("two").

If you change it to:

if (length(elements[[i]]) == 1 && !is.list(elements[[i]])) {

then all works as expected.

I am unsure if this breaks some other use case, though.

@daroczig
Copy link
Member

Thank you very much for the detailed issue, I have merged your proposed fix.
To be honest, I have never used pandoc.list directly in the last 10 months for sure, always called pander instead which resolved this issue by analyzing the class of each part before applying any of the pandoc.* functions. E.g. (before fix):

> pander(list('one', list('two')))


  * one
  *

      * two


<!-- end of list -->

But that was a bug for sure, thanks again!

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

No branches or pull requests

2 participants