Commits

Robert Mařík committed b236564

Handling <sage>...</sage> moved completely to tex2sws.py

Comments (0)

Files changed (2)

                         e.setAttribute('href', newlink)
 
         # Ignore headers/footers by starting with body tag
+        # Move nested <sage>...</sage> tags to <body>...</body> 
         # Collect text between compute cells
         # Identify text cells with <sage>,</sage> tag
         # as produced by custom configuration file for tex4ht
         bodies = tree.getElementsByTagName('body')
         thebody = bodies[0]
+        for e in tree.getElementsByTagName('sage').__reversed__():
+            if e.parentNode.tagName != 'body':
+                f = e
+                while f.parentNode.tagName != 'body':
+                    f = f.parentNode 
+                f.parentNode.insertBefore(e,f.nextSibling)
         cells = []
         content = []
         for e in thebody.childNodes:
 
 \Preamble{xhtml,jsmath,charset=UTF-8,info}
 
-\def\tempc#1{\ScriptEnv{#1}{\ifvmode \IgnorePar \else \break\fi
-  \EndP\HCode{<sage>\Hnewline}\NoFonts}
+\def\tempc#1#2{\ScriptEnv{#1}{\ifvmode \IgnorePar \else \break\fi
+  \EndP\HCode{\Hnewline<sage>\Hnewline}\HCode{#2\Hnewline}\NoFonts}
 {\ifvmode \IgnorePar \fi
   \EndP\HCode{</sage>}\EndNoFonts\csname par\endcsname\ShowPar}
 }
-\tempc{sageverbatim}
-\tempc{sageblock}
-\tempc{sagesilent}
+\tempc{sageverbatim}{}
+\tempc{sageblock}{}
+\tempc{sagesilent}{\%hide}
 
 
 \Css{/* jsMath suggested additions for spacing control */}
 \newtoks\sagetextoks
 \def\sage#1{\orisage{#1}\savesage{#1}}%
 \def\sagestr#1{\orisagestr{#1}\savesage{#1}}%
-\def\savesage#1{\expandafter\global\expandafter\sagetextoks
-  \expandafter{\the\sagetextoks \HCode{<sage>\Hnewline
-    }\HCode{#1\Hnewline}\HCode{</sage>\Hnewline
-    }}}
+%\def\savesage#1{\expandafter\global\expandafter\sagetextoks
+%  \expandafter{\the\sagetextoks \HCode{<sage>\Hnewline
+%    }\HCode{#1\Hnewline}\HCode{</sage>\Hnewline
+%    }}}
+\def\savesage#1{\HCode{<sage>\Hnewline #1\Hnewline</sage>\Hnewline}}
 
 % PNG graphics is O.K.
 \Configure{graphics*} 
 
 \makeatother
 
-% \ifprintsagetoks is false in center environment, Sage does not parse 
-% worksheet correctly, if <sage>...</sage> is inside <div>....</div>
-%
-% TODO: catch all <sage>...</sage> blocks and move in tex2sws.py to the 
-% upper-most level in xml hierarchy
-\newif\ifprintsagetoks
-\printsagetokstrue
-
-\def\printsagetoks{\ifprintsagetoks\the\sagetextoks\global\sagetextoks{}\fi}
-
-% environment center from html4.4t with added \prinsagetoks....
-% before and after this environment
-\ConfigureEnv{center}
-  {\ifvmode \IgnorePar\fi \EndP}{\ShowPar
-}
-  {\EndP\IgnorePar\printsagetoks\printsagetoksfalse
-   \HCode{<div class="\getClass{center}"\Hnewline>}\ShowPar\endgraf
-   \afterGetClass{center}}
-  {\IgnorePar\EndP\HCode{</div>}\printsagetokstrue\printsagetoks}
-
-
-\Configure{HtmlPar}
-{\EndP\printsagetoks\HCode{\Hnewline<p class="noindent">}} 
-{\EndP\printsagetoks\HCode{\Hnewline<p class="indent">}} 
-{\HCode{</p>\Hnewline}\printsagetoks}
-{\HCode{</p>\Hnewline}\printsagetoks}
-% ----------------------- End configuring \sage, \sagestr, \sageplot
-
-
 
 % ----------------------- Configuring inline math
 % The following lines keep dollars as delimiters of mathematics