Looking through the code, I am not sure this is easily achievable using ConversionRules
alone. Here's an attempt at modifying the conversion functions directly:
System`Convert`CommonDump`ConvertCell[
Cell[CellGroupData[cells_List, _]], toFormat_, toFormatStream_,
others__] := (
WriteString[toFormatStream, "<div class=\"XXX\">\n"];
Scan[Function[If[System`Convert`CommonDump`CellOpenQ[#],
System`Convert`CommonDump`ConvertCell[#, toFormat,
toFormatStream, others];]], cells];
WriteString[toFormatStream, "</div>\n"];
)
System`Convert`CommonDump`ConvertCell[
Cell[CellGroupData[cells_List, _]], toFormat_, toFormatStream_,
others__] /;
AllTrue[MatchQ[Cell[__, "Item", ___]]]@cells :=
(
WriteString[toFormatStream, "<ul>\n"];
Scan[Function[If[System`Convert`CommonDump`CellOpenQ[#],
System`Convert`CommonDump`ConvertCell[#, toFormat,
toFormatStream, others];]], cells];
WriteString[toFormatStream, "</ul>\n"];
)
You can then export the notebook as you did before:
ExportString[EvaluationNotebook[], "HTML", "CSS" -> None,
"FullDocument" -> False, "GraphicsOutput" -> "PNG",
"ConversionRules" -> {"Title" -> {"<h1>", "</h1>"},
"Section" -> {"<h2>", "</h2>"}, "Subsection" -> {"<h3>", "</h3>"},
"Text" -> {"<p>", "</p>"}, "Input" -> {"<pre>", "</pre>"},
"Item" -> {"<li>", "</li>"}}]
(* "<div class=\"XXX\"><h2>Some section</h2>
<p>Some items:</p>
<ul><li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div><div class=\"XXX\"><h2>Another section</h2>
<p>Some code:</p>
<div class=\"XXX\">
<pre><img \
src=\"HTMLFiles/m-d39f35de-cf25-41ad-8dc9-45e38a941224_1.gif\" \
alt=\"m-d39f35de-cf25-41ad-8dc9-45e38a941224_1.gif\" width=\"49\" \
height=\"15\" style=\"vertical-align:middle\" /></pre><p \
class=\"Output\">
<img src=\"HTMLFiles/m-d39f35de-cf25-41ad-8dc9-45e38a941224_2.gif\" \
alt=\"m-d39f35de-cf25-41ad-8dc9-45e38a941224_2.gif\" width=\"7\" \
height=\"15\" style=\"vertical-align:middle\" />
</p>
</div><div class=\"XXX\"><pre><img \
src=\"HTMLFiles/m-d39f35de-cf25-41ad-8dc9-45e38a941224_3.gif\" \
alt=\"m-d39f35de-cf25-41ad-8dc9-45e38a941224_3.gif\" width=\"735\" \
height=\"73\" style=\"vertical-align:middle\" /></pre><p \
class=\"Output\">
<img src=\"HTMLFiles/m-d39f35de-cf25-41ad-8dc9-45e38a941224_4.gif\" \
alt=\"m-d39f35de-cf25-41ad-8dc9-45e38a941224_4.gif\" width=\"774\" \
height=\"796\" style=\"vertical-align:middle\" />
</p>
</div>
</div>" *)
The notebook I used to test this:
Note that I had to manually group the list items in order for the code to identify the list. The code above works by overriding/extending the rules for how to convert Cell[CellGroupData[...]]
, which is what represents a cell group. I changed the default rule to print <div class="XXX">
before and </div>
after the group. I then added a second rule that matches only when all child cells have style "Item"
, in which case I wrap the contents with <ul>
/</ul>
.
You can similarly handle other types of grouping by adding additional rules. Note that if you want to support nested lists for example, you will have to make the check for lists above more robust.