Closed niftylettuce closed 2 years ago
What about the failing test?
I'll look if I get time!
On Nov 20, 2016 2:58 PM, "Zephraph" notifications@github.com wrote:
What about the failing test?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zephraph/nunjucks-markdown/pull/23#issuecomment-261801223, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf7hc8aUI0CUaxuxfUn0G00uBHOcGEeks5rAKZsgaJpZM4K3XQl .
@internalfx @zephraph Okay we have an issue here that we need to standardize.
Either people need to do it like this:
<div>
{% markdown %}
foo bar baz
{% endmarkdown %}
</div>
Or like this:
<div>
{% markdown %}
foo bar baz
{% endmarkdown %}
</div>
And we need to enforce strictly one or the other in our tests and Readme. We should enforce the first.
It's impossible to support both - why? Because if you have variables that have indentation in them, the indentation is not preserved, it is all stripped. Imagine you have a JSON object stored as a variable named foo
, and it looks like this:
{
"statusCode": 401,
"error": "Unauthorized",
"message": "Invalid token"
}
When rendered (with the old approach before this pull request was submitted):
{
"statusCode": 401,
"error": "Unauthorized",
"message": "Invalid token"
}
Especially with async rendered variables - the spacing in the variables when rendered is lost.
Actually, I think the variable rendering issue is due to the parser not preserving indentation with rendered variables that have line breaks.
// Otherwise parse until the close block and move the parser to the next position
var body = parser.parseUntilBlocks('endmarkdown');
Input:
var jsonSpaces = JSON.stringify({
"baz": "beep"
}, null, 2);
<div class="col-xs-12">
{% markdown %}
```json
{{ jsonWithSpaces }}
{% endmarkdown %}
</div>
Expected:
```html
<div class="col-xs-12">
<pre><code class="lang-json">{
&quot;baz&quot;: &quot;beep&quot;
}
</code></pre>
</div>
Actual:
<div class="col-xs-12">
<pre><code class="lang-json">{
&quot;baz&quot;: &quot;beep&quot;
}
</code></pre>
</div>
I agree with supporting only the first, but yeah, seems like the other issue will need to be fixed first. Thanks for your work so far. Maybe we can get some traction. This has been a lingering issue for a bit.
is anyone still working on this? I’ve been using raml2html which in turn uses nunjucks and this plugin to render rest api documentation. unfortunately all my json example objects are stripped of indentation :). sooo… why strip indentation in the first place? html doesn’t care so is there any reason why it was implemented this way?
This may be ok...
@zephraph I'm not sure if this will break existing users templates...It shouldn't if your using the library "correctly".