jankatins / knitpy

knitpy: Elegant, flexible and fast dynamic report generation with python
https://github.com/jankatins/knitpy
Other
368 stars 29 forks source link

multiple line indents failing to preserve indent after first indented line #15

Closed thatcher closed 9 years ago

thatcher commented 9 years ago

Here is simple test that demonstrates the gist. Note I had to escape all triple back ticks inside the ticket description to get the example to render in a code block for the ticket.


---
title: "knitpy: multi line indent test"
author: "thatcher"
date: "15.04.2015"
output:
  pdf_document: default
  word_document: default
  html_document:
    keep_md: yes

---

\```{python}
x = 0
y = 0
z = 0
for i in range(10):
    x=x+i
    y=y+i
    z=z+1
print x, y, z
\```

The value of x should be 45 and is `python x`.

The value of y should be 45 and is `python y`.

The value of z should be 10 and is `python z`.

And here is the resulting output intermediate markdown file:


---
title: "knitpy: multi line indent test"
author: "thatcher"
date: "15.04.2015"
output:
  pdf_document: default
  word_document: default
  html_document:
    keep_md: yes

---

\```python
x = 0
y = 0
z = 0
for i in range(10):
    x=x+i
    y=y+i
    z=z+1
print x, y, z

\```

\```
45 9 1

\```

The value of x should be 45 and is 45.

The value of y should be 45 and is 9.

The value of z should be 10 and is 1.

This demonstrates the {python} code block is actually being interpreted as:

\```python
x = 0
y = 0
z = 0
for i in range(10):
    x=x+i
y=y+i
z=z+1
print x, y, z
\```

This issue was originally discovered on a unix box and I verified it also occurred on my windows machine, though I havent checked my osx machine yet.

jankatins commented 9 years ago

Oh wow, thanks for finding this!

Currently I let the kernel decide if lines are valid code and of course, the first two lines of a loop are valid :-(

thatcher commented 9 years ago

No worries, I dont want to overwhelm, hopefully being a beta user for you will help sort out the doh! level issues. I want to commit patches as well but also know that comes with its own extra effort since you know the code better and can probably fix it faster and better. I'm watching all the commits now and keeping my clone up, so as I get more familiar with it I'll be a better asset than a ticket clerk ;)

jankatins commented 9 years ago

Ok, produced a fix... #18

jankatins commented 9 years ago

And please keep the bugreports coming! :-)

jankatins commented 9 years ago

This should be fixed in #18, which I just merged. Please reopen if the problem wasn't fixed.

@thatcher: Thanks for your bugreport!