Closed CurtLH closed 6 years ago
I think you need to use chunk option results = "raw" and produce the interpretations as python output. Please ignore the "\" character wherever it occurs. There is an empty line in the output that I am not sure how to eliminate.
\```python echo=False
x = 1
\```
Your x is too
\```python results='raw', echo=False
if x > 0:
print ("high")
else:
print ("low")
\```
I mean, there are several ways to eliminate the newline, but I would like to do the same thing directly inline, to minimize the code part. That may or may not matter to you.
Like this:
\```python echo=False
x = 1
\```
Your x is too <%print("high" if x>0 else "low")%>
Thanks for responding, but I think our situations are slightly different. I want to conditionally display a mardown chunk with headers, bullet points, bold text, ect, and I want control which markdown chunk appears based on some value of x.
For example, if x
is less than 0.50, display the following markdown chunk:
But if x
is greater than 0.50, display this other markdown chunk:
Not sure what your last question really adds to the problem. Of course you can put markdown in the print statements. Maybe I am missing the point.
\```python echo=False
x = 0
\```
# You are really <% print("really" if x > 0.50 else "")%> smart
\```python results='raw', echo=False
if x < 0.50:
print (
"""
- bullet point number 1
- bullet point number 2
- bullet point number 3
""")
else:
print (
"""
- bullet point 9
- bullet point 8
- bullet point 7
""")
\```
Does that come close enough?
There is no asis
chunk type in Pweave. You can use workaround that @piccolbo showed.
A pull request adding this feature with documentation and tests would be welcome.
Thanks for the info. I'll go with the workaround @piccolbo mentioned for now, but will look into possibly submitting a PR to add the feature.
I tried your example @piccolbo, but the bullet point section is not being rendered as markdown. Instead, the output put all the bullet points on one line (example below).
- bullet point number 1 - bullet point number 2 - bullet point number 3
Instead, I want to output to render as markdown.
Did you check the markdown that was generated and do you find any fault with it? It works for me. How are you doing the rendering?
When I use the following command, the pweave -f markdown report.pmd
, the outputs is as I would expect. However, when I use pweave -f md2html report.pmd
, the markdown within the code chunk does not render as proper markdown.
Ultimately, I want to get to an HTML document, so I guess that I could go from pmd -> markdown -> HTML. However, maybe there is a more straight forward way to do this.
I think it's a bug in pweave. I tried to add the same markdown inside and outside the code block as in
\```python echo=False
x = 0
\```
# You are really <% print("really" if x > 0.50 else "")%> smart
\```python results='raw', echo=False
if x < 0.50:
print (
"""
- bullet point number 1
- bullet point number 2
- bullet point number 3
""")
else:
print (
"""
- bullet point 9
- bullet point 8
- bullet point 7
""")
\```
- bullet point number 1
- bullet point number 2
- bullet point number 3
The generated markdown is the same:
# You are really smart
- bullet point number 1
- bullet point number 2
- bullet point number 3
- bullet point number 1
- bullet point number 2
- bullet point number 3
But with md2html or pandoc2html only the second becomes a list. Strange, I thought any conversion would go through markdown as an intermediate format. Your workaround makes sense, but best would be to get to the bottom of this.
md2html uses python-markdown instead of pandoc. You could try adding empty line after the list and see if that helps.
I tried your suggestion of adding an empty line after the list, and that didn't seem to make any difference.
I'm am using
pweave
to create a scientific report. Within the report, I am calculating a value and I want to control the markdown text that is shown based on the value. When using R-notebooks withknitr
, I am able to do this by usingasis
in the code chunk. However, I cannot figure out how to accomplish this usingpweave
.For example, if x <= 0.5, then show interpretation #1, but if x > 0.5, show interpretation #2.
In an R-notebook, I would do this as follows:
(I'm using single-quotes to represent backticks in this example)
Continuing with this example, if
x
came out to be 0.75, only interpretation #2 to appear in the HTML report that is generated. The code chunk is not python, but just regular markdown.I've tried wrapping each possible markdown interpretation in separate code chunks and including either
echo = False
orevaluate = False
as code chunk options, but that doesn't appear to do what I want it do. Instead of controlling whether or not the chunk is rendered, it just prints out at the beginning of the chunk.How can I conditionally control the markdown that appears in the HTML report that is generated?