khajavi / pandoc

Automatically exported from code.google.com/p/pandoc
GNU General Public License v2.0
0 stars 0 forks source link

Wrapping sections in divs can break embedded HTML usage #230

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Ever since Issue 70 was fixed in release 1.2.1, sections in HTML output
have been wrapped in div tags, so:

# Foo
Bar

Becomes:

<div id="foo">
  <h1>Foo</h1>
  <p>Bar</p>
</div>

Instead of the previous:

<h1 id="foo">Foo</h1>
<p>Bar</p>

The problem with this is apparent when using custom HTML around the Markdown:

<div id="enclosing">
# Foo
Bar
</div>
<div id="not_enclosing">baz</div>

Now, the </div> and what follows is considered part of the Foo section, so
the Foo-closing </div> is inserted only afterwards. But, the directly
embedded </div> actually closes the one opened by the Foo section header.
Typically, this will end up breaking the resulting HTML completely. For the
above, the result is:

<div id="enclosing">
  <div id="foo"><h1>Foo</h1>Bar</div>
  <div id="not_enclosing">baz</div>
</div>

Now "not_enclosing" is actually inside "enclosing"!

I'd be satisfied with just making the div-wrappers optional, as I don't
need them and the extra div tags are just cruft in the final HTML.

More general solutions would be to either provide some way of closing a
section manually, or for the parser to recognize that a tag opened before
the section is being closed and the section div should thus be closed right
there.

Original issue reported on code.google.com by Deewi...@gmail.com on 1 Apr 2010 at 5:18

GoogleCodeExporter commented 9 years ago
Can't you get around this by using raw html for the header?

<div id="enclosing">
<h1>Foo</h1>
Bar
</div>
etc.

I'm guessing this is a pretty rare kind of case -- wanting a div to surround 
the header 
and part of the section, but not the whole section -- and I'm reluctant to make 
changes if there's a way to work around it.

Original comment by fiddloso...@gmail.com on 1 Apr 2010 at 11:31

GoogleCodeExporter commented 9 years ago
(Sorry for responding so late, I seem to have missed the e-mail notifying of 
your
comment.)

Yes, raw HTML works, but that way lies not using Pandoc at all and just writing
everything in HTML. :-P

My use case is that I write the contents of a web page in Markdown, with the 
per-page
content in one div—analogously to the id="enclosing"—and then some stuff 
like
navigation afterwards—like the id="not_enclosing" div. If I have to use raw 
HTML for
headers I'd have to use it for every header everywhere: it's not an isolated 
situation.

Original comment by Deewi...@gmail.com on 24 Apr 2010 at 2:35

GoogleCodeExporter commented 9 years ago
If what you want is a navigation section at the end of the document, I'd put 
this in
a separate file and include it using the -A option.  This is generally best 
practice
anyway, since you'll generally have the same nav section across multiple pages.

I'm not sure ending the section when a <div> tag is encountered would always 
yield
the desired results -- some people might want their divs to be inside the 
section. 
How is pandoc going to know?

Providing some way to manually end a section might be a possibility, but I'd 
have to
think about an unobtrusive way to do that...

Original comment by fiddloso...@gmail.com on 24 Apr 2010 at 10:07

GoogleCodeExporter commented 9 years ago
I was simplifying: there is content both before and after the enclosing div 
which
varies per page. I probably /could/ work around this whole thing somehow but it 
would
require rethinking large parts of my build system.

No, ending a section at any </div> wouldn't work. In this case, though, Pandoc 
could
know that closing at the </div> is appropriate, since it sees the opening <div>,
which precedes the section, as well. You'd need to keep track of tags nesting 
for
that to work. This is probably the most "correct" way of handling this while 
keeping
the section-divs.

But like said, I'm fine with just optionally getting rid of the divs inserted by
pandoc, reverting to the old behaviour. It seems to me to be the simplest way of
handling this.

Original comment by Deewi...@gmail.com on 25 Apr 2010 at 4:59

GoogleCodeExporter commented 9 years ago
Issue 239 has been merged into this issue.

Original comment by fiddloso...@gmail.com on 25 May 2010 at 6:22

GoogleCodeExporter commented 9 years ago
Fixed in
9be9bccfcfc2c46459b3da963bc59a37f841fe8a

The new default is not to include the divs (and to put the identifiers directly 
on the header elements).

However, the pandoc 1.2-1.5 behavior can be restored using the --section-divs 
command-line option.

Original comment by fiddloso...@gmail.com on 16 Jul 2010 at 5:32