combined front end and html conversion problems
- To: mathgroup at smc.vnet.net
- Subject: [mg79312] combined front end and html conversion problems
- From: "Chris Chiasson" <chris at chiasson.name>
- Date: Tue, 24 Jul 2007 06:06:43 -0400 (EDT)
This post details problems encountered while trying to implement a style that suppresses its contents when the containing notebook is converted to HTML. I will try to be as concise as possible, but the moderate complexity prevents a simple "steps to repeat: 1, 2, 3" style report. A related post will detail documentation problems I encountered and give some extra information, which I left out here to maintain focus. Execute the following three commands, which represent the generation and HTML conversion of a notebook and its stylesheet. nb0=Notebook[{Cell[BoxData["Lorem"],"BogusStyle"],Cell[BoxData[{"ipsum","\n","dolor"}],"BogusStyle"]},StyleDefinitions->Notebook[{Cell[StyleData[StyleDefinitions->"Default.nb"]],Cell[StyleData["BogusStyle",StyleDefinitions->StyleData["Input"]],Background->LightGray],Cell[StyleData["BogusStyle"],ConversionRules->{"HTML"->{"<bogustag>",Function[Null,"",HoldAllComplete],"</bogustag>\n"}}]}]] NotebookPut@nb0 ExportString[nb0,"HTML"] In the notebook window that comes up, one can see that the "BogusStyle" background color defined in the __first__ "BogusStyle" StyleData Cell in the embedded stylesheet has taken effect. If one highlights a cell and uses CTRL+SHIFT+o to search its options for ConversionRules, one will see that the front end has not "noticed" the ConversionRules option defined in the __second__ "BogusStyle" StyleData Cell in the embedded stylesheet. This behavior is contrary to my understanding of how the style system should work. If I am in error, please let me know. In the text that is displayed as the result of the ExportString command, one may see the resulting HTML document. The ConversionRules->{"HTML"->{"<bogustag>",Function[Null,"",HoldAllComplete],"</bogustag>\n"}} option I gave for "BogusStyle" in the __second__ StyleData Cell instructs the HTML Export code to wrap the contents in "bogustag" tags, to apply the Function[Null,"",HoldAllComplete] pure function, which will take any (sane) input and return an empty string, and finally to put a line feed at the end of the element. That means the output for both cells in the notebook should be: "<bogustag></bogustag>\n". As may be seen, the first cell has been suppressed in exactly the manner described. The second cell, with a first argument of BoxData[{"ipsum","\n","dolor"}], is actually converted to an image tag. As far as I can tell, this is due to a problem with the definition of System`ConvertersDump`AnimationQ. AnimationQ is used in a pattern test to check if the contents of BoxData is, I assume, an animation. In the conversion process, AnimationQ[{"ipsum","\n","dolor"}] gives True. The definition of AnimationQ follows from this command: ??System`ConvertersDump`AnimationQ and gives the following output: System`ConvertersDump`AnimationQ[System`ConvertersDump`expr_]:=Module[{System`ConvertersDump`ani},System`ConvertersDump`ani=System`ConvertersDump`AnimationVariables[System`ConvertersDump`expr];If[ListQ[Unevaluated[System`ConvertersDump`expr]],Length[System`ConvertersDump`ani]===0,Length[System`ConvertersDump`ani]===1&&System`ConvertersDump`ani=!={$Failed}]] The problem code appears to be: Length[System`ConvertersDump`ani]===0 I think it should be: Length[System`ConvertersDump`ani]=!=0 Evaluate the following code to make the correction to the definition of AnimationQ and run the same Export as before: System`ConvertersDump`AnimationQ[System`ConvertersDump`expr_]:=Module[{System`ConvertersDump`ani},System`ConvertersDump`ani=System`ConvertersDump`AnimationVariables[System`ConvertersDump`expr];If[ListQ[Unevaluated[System`ConvertersDump`expr]],Length[System`ConvertersDump`ani]=!=0,Length[System`ConvertersDump`ani]===1&&System`ConvertersDump`ani=!={$Failed}]] ExportString[nb0,"HTML"] One will notice that both cells are now suppressed as described above. Now I turn to my rather peculiar placement of the ConversionRules option in the __second__ "BogusStyle" StyleData Cell of nb0's embedded stylesheet instead of the __first__. Evaluate the following commands: nb1=Notebook[{Cell[BoxData["Lorem"],"BogusStyle"],Cell[BoxData[{"ipsum","\n","dolor"}],"BogusStyle"]},StyleDefinitions->Notebook[{Cell[StyleData[StyleDefinitions->"Default.nb"]],Cell[StyleData["BogusStyle",StyleDefinitions->StyleData["Input"]],Background->LightGray,ConversionRules->{"HTML"->{"<bogustag>",Function[Null,"",HoldAllComplete],"</bogustag>\n"}}]}]] NotebookPut@nb1 ExportString[nb1,"HTML"] In the new notebook window one will notice, via the option inspector (CTRL+SHIFT+o), that the option for ConversionRules is now seen by the front end. The only change from nb0 to nb1 was the movement of that option of the __second__ "BogusStyle" StyleData Cell to the __first__. Additionally, the Export process is no longer able to pick up on the ConversionRules option. Export instead now follows the standard procedure for a block level cell with no special ConversionRules, outputting "p" tags with a class attribute of "BogusStyle". According to my understanding of the style sheet system, my change in location of the ConversionRules option should not matter at all. Finally, there is the question of what happens when both the background color and ConversionRules options are defined in the __second__ "BogusStyle" StyleData Cell. Evaluate the following commands: nb2=Notebook[{Cell[BoxData["Lorem"],"BogusStyle"],Cell[BoxData[{"ipsum","\n","dolor"}],"BogusStyle"]},StyleDefinitions->Notebook[{Cell[StyleData[StyleDefinitions->"Default.nb"]],Cell[StyleData["BogusStyle",StyleDefinitions->StyleData["Input"]]],Cell[StyleData["BogusStyle"],Background->LightGray,ConversionRules->{"HTML"->{"<bogustag>",Function[Null,"",HoldAllComplete],"</bogustag>\n"}}]}]] NotebookPut@nb2 ExportString[nb2,"HTML"] One will notice that the front end can see neither the ConversionRules nor the Background options for the cells and that the Export is correct. Again, the change in the location of the options should not matter at all. Here is a definition of AnimationQ that may be placed in one's Kernel\init.m file to always overload the inbuilt version: System`ConvertersDump`Workarounds`overloadAnimationQ=True System`ConvertersDump`AnimationQ[expr_]/;System`ConvertersDump`Workarounds`overloadAnimationQ:=Module[{ani},ani=System`ConvertersDump`AnimationVariables[expr];If[ListQ[Unevaluated[expr]],Length[ani]=!=0,Length[ani]===1&&ani=!={$Failed}]] Corrections are welcome. -- http://chris.chiasson.name/