Plugin with HTML code on wrong position
Initial situation:
We have a tool to export articles of our DokuWiki to create a costumer document. But we have also the situation, that sometimes not all the content of an article should be exported to the customer document. So we have the idea to embrace content, which should not exported, by markers, so the exporting tool could ignore this content. Second intention is, to visualize this 'no export' content inside the DokuWiki article as a special content by changing the background color in this area of the article. This content could be normal text, headlines, notes, images and so on.
For this we write a plugin with two control macros (We use Control Macros now, because with tags like '<xyz>' the formatting of headlines will disturbed in the article). The result of our export tool is abolute correct, all content embraced by the control macros is not in the customer document. But in the rendered HTML code of the DokuWiki article I have some problems. Here is what we have done and what we get.
The 'syntax.php' of our plugin looks like this (excerpt):
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~NOEXPORT:\w+~~',$mode,'plugin_noexport');
}
public function render($mode, Doku_Renderer $renderer, $data) {
if($mode == 'xhtml'){
switch ($data[0]){
// Begin of excluding a section from export
case 'on':
$renderer->doc .= '<section class="nepsect">';
break;
// End of excluding a section from export
case 'off':
$renderer->doc .= "</section>";
break;
default:
$renderer->doc .= "no info about ".htmlspecialchars($data[0]);
}
return true;
}
return false;
}
My test article in DokuWiki looks like this:
~~NOEXPORT:ON~~
==== Tests of plugin "noexport" ====
<note>
This plugin is a self developed plugin.
</note>
~~NOEXPORT:OFF~~
=== Description ===
Exclude content of an article from export to TeX and PDF by PTX export tools.
=== Example ===
This text will exported.
~~NOEXPORT:ON~~
This text will **not** exported.
~~NOEXPORT:OFF~~
~~NOEXPORT:ON~~
=== No Export Chapter ===
This chapter will shown in DokuWiki, but will not exported to TeX and PDF by PTC RMsis Exporter.
~~NOEXPORT:OFF~~
This text will exported again.
I will try you add an image of my DokuWiki result soon. (If I will know, how to do this in a discussion)
I excpect, that all content between headline 'No Export Chapter' and text '... RMsis Exporter.' will also have a colored background, but this don't happens. I take some investigations and found out, that this is a problem of mixed text structures in the HTML code.
This is the HTML code we get (Comments added by me):
<p>
<section class="nepsect"> <!-- This is our CSS class for colored section. Rendering OK -->
</p>
<h3 class="sectionedit1" id="tests_of_plugin_noexport">Tests of plugin "noexport"</h3>
<div class="level3">
<p>
<p><div class="noteclassic">
This plugin is a self developed plugin.
</div></p>
</p>
<p>
</section>
</p>
</div>
<h4 id="description">Description</h4>
<div class="level4">
<p>
Exclude content of an article from export to TeX and PDF by PTX export tools.
</p>
</div>
<h4 id="example">Example</h4>
<div class="level4">
<p>
This text will exported.
</p>
<p>
<section class="nepsect"> <!-- Good position! Rendering OK -->
This text will <strong>not</strong> exported.
</section>
</p>
<p>
<section class="nepsect"> <!-- Wrong position! Rendering failed -->
</p>
</div>
<h4 id="no_export_chapter">No Export Chapter</h4>
<div class="level4">
<p>
This chapter will shown in DokuWiki, but will not exported to TeX and PDF by PTC RMsis Exporter.
</section>
</p>
<p>
This text will exported again.
</p>
</div>
As you can see, there is a mismatch of our <section class ...> and the </div>. Our section starts in the division. This division is created by DokuWiki for all text below the headline. But our macro should be outside the division. I change the HTML code manually (see below) and then I get the right result.
Correct HTML code:
<h4 id="example">Example</h4>
<div class="level4">
<p>
This text will exported.
</p>
<p>
<section class="nepsect"> <!-- Good position! Rendering OK -->
This text will <strong>not</strong> exported.
</section>
</p>
</div>
<p>
<section class="nepsect"> <!-- This is the correct position! Rendering OK -->
</p>
<h4 id="no_export_chapter">No Export Chapter</h4>
<div class="level4">
<p>
This chapter will shown in DokuWiki, but will not exported to TeX and PDF by PTC RMsis Exporter.
</section>
</p>
<p>
This text will exported again.
</p>
</div>
So I have two questions:
- What have I do to to get the correct HTML code (<section class ...> behind </div> )?
- How can I avoid this obsolete paragraph tags (<p> and </p>) before and behind my <section class ...> and </section> tags?
Hope to get any ideas and thank you in advance. And sorry about this long text.
Rudi