pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
391 stars 42 forks source link

Parent/root Tag needed? #118

Closed marcus-at-localhost closed 7 years ago

marcus-at-localhost commented 7 years ago

Hey, I use Pug to generate HTML fractions without wrapping <html> or so.

To me it seems like I always need a wrapping parent tag on top.

Situation:

div.x
  p 1
div.y
  p 2

results in

<div class="x">
  <p>1</p>
</div>

and

div
  div.x
    p 1
  div.y
    p 2

results correctly in this:

<div>
  <div class="x">
    <p>1</p>
  </div>
  <div class="y">
    <p>2</p>
  </div>
</div>

do I miss something?

marcus-at-localhost commented 7 years ago

I close this for now, since it seems to be an issue somewhere else in my chain...

marcus-at-localhost commented 7 years ago

Here is what's happened.

this:

div.x
  p 1
div.y
  p 2

is correctly rendered as:

<div class="x"><p>1</p></div><div class="y"><p>2</p></div>

then, this fragment is parsed by https://github.com/erusev/parsedown-extra

and parsedown-extra drops every html after the first block, if it's in one line, and just outputs:

<div class="x"><p>1</p></div>

See also: https://github.com/erusev/parsedown-extra/issues/90#issue-142629807

My solution is to turn on prettyprint => true in Pug and then it works.

Rare use case, but well

kylekatarnls commented 7 years ago

Hi, thanks for feedback. I do not understand the point of passing HTML to parsedown-extra.

If what you want is using parsedown inside your pug templates, you should consider using pug filters:

$pug->filter('parsedown', function($node, $compiler){
    foreach ($node->block->nodes as $line) {
        $output[] = $compiler->interpolate($line->value);
    }
    $extra = new ParsedownExtra();

    return $extra->text(implode("\n", $output));
});

It allow you to do:

div.x
  p
    :parsedown
      # Header {.sth}