|
楼主 |
发表于 2005-9-6 11:04:36
|
显示全部楼层
nbx , 现在还是 div + table
但是 css 里指定了剪切...
如下面是 [code]的例子
[php]
<div class="smallfont" style="margin-bottom: 2px;">代码:</div>
<table border="0" cellpadding="6" cellspacing="0">
<tbody><tr>
<td class="alt2" style="border: 1px inset ;">
<pre class="alt2" style="margin: 0px; padding: 4px; overflow: auto; width: auto; height: 498px;">#!/usr/bin/python
import sys, zipfile
from gnosis.xml.objectify import XML_Objectify, EXPAT, \
children, tagname, content
XML_Objectify.expat_kwargs['nspace_sep'] = None
doc_content = zipfile.ZipFile(sys.argv[1]).read('content.xml')
doc = XML_Objectify(doc_content).make_instance()
write = sys.stdout.write
for o in children(doc.office_body):
if tagname(o)=="text_p":
for s in content(o):
if type(s) is unicode and s.strip():
write(" "+s.encode('utf-8').strip())
elif tagname(s)=='text_span':
write(" "+s.PCDATA.encode('utf-8'))
write('\n')
</pre>
</td>
</tr>
</tbody></table>
</div>
[/php]
显示是
- #!/usr/bin/python
- import sys, zipfile
- from gnosis.xml.objectify import XML_Objectify, EXPAT, \
- children, tagname, content
- XML_Objectify.expat_kwargs['nspace_sep'] = None
- doc_content = zipfile.ZipFile(sys.argv[1]).read('content.xml')
- doc = XML_Objectify(doc_content).make_instance()
- write = sys.stdout.write
- for o in children(doc.office_body):
- if tagname(o)=="text_p":
- for s in content(o):
- if type(s) is unicode and s.strip():
- write(" "+s.encode('utf-8').strip())
- elif tagname(s)=='text_span':
- write(" "+s.PCDATA.encode('utf-8'))
- write('\n')
复制代码
===================================================
===================================================
下面是 [php]的
[php]
<div class="smallfont" style="margin-bottom: 2px;">HP代码:</div>
<table border="0" cellpadding="6" cellspacing="0">
<tbody><tr>
<td class="alt2" style="border: 1px inset ;">
<div class="alt2" style="margin: 0px; padding: 4px; overflow: auto; width: auto; height: 498px;">
<code style="white-space: nowrap;">
<!-- php buffer start --><code><font color="#000000">
<font color="#0000bb"> </font><font color="#ff8000">#!/usr/bin/python
<br>
<br></font><font color="#0000bb">import sys</font><font color="#007700">, </font><font color="#0000bb">zipfile
<br>
<br>from gnosis</font><font color="#007700">.</font><font color="#0000bb">xml</font><font color="#007700">.</font><font color="#0000bb">objectify import XML_Objectify</font><font color="#007700">, </font><font color="#0000bb">EXPAT</font><font color="#007700">,
<br> </font><font color="#0000bb">children</font><font color="#007700">, </font><font color="#0000bb">tagname</font><font color="#007700">, </font><font color="#0000bb">content
<br>
<br>XML_Objectify</font><font color="#007700">.</font><font color="#0000bb">expat_kwargs</font><font color="#007700">[</font><font color="#dd0000">'nspace_sep'</font><font color="#007700">] = </font><font color="#0000bb">None
<br>
<br>doc_content </font><font color="#007700">= </font><font color="#0000bb">zipfile</font><font color="#007700">.</font><font color="#0000bb">ZipFile</font><font color="#007700">(</font><font color="#0000bb">sys</font><font color="#007700">.</font><font color="#0000bb">argv</font><font color="#007700">[</font><font color="#0000bb">1</font><font color="#007700">]).</font><font color="#0000bb">read</font><font color="#007700">(</font><font color="#dd0000">'content.xml'</font><font color="#007700">)
<br>
<br></font><font color="#0000bb">doc </font><font color="#007700">= </font><font color="#0000bb">XML_Objectify</font><font color="#007700">(</font><font color="#0000bb">doc_content</font><font color="#007700">).</font><font color="#0000bb">make_instance</font><font color="#007700">()
<br>
<br></font><font color="#0000bb">write </font><font color="#007700">= </font><font color="#0000bb">sys</font><font color="#007700">.</font><font color="#0000bb">stdout</font><font color="#007700">.</font><font color="#0000bb">write
<br>
<br></font><font color="#007700">for </font><font color="#0000bb">o in children</font><font color="#007700">(</font><font color="#0000bb">doc</font><font color="#007700">.</font><font color="#0000bb">office_body</font><font color="#007700">):
<br>
<br> if </font><font color="#0000bb">tagname</font><font color="#007700">(</font><font color="#0000bb">o</font><font color="#007700">)==</font><font color="#dd0000">"text_p"</font><font color="#007700">:
<br>
<br> for </font><font color="#0000bb">s in content</font><font color="#007700">(</font><font color="#0000bb">o</font><font color="#007700">):
<br>
<br> if </font><font color="#0000bb">type</font><font color="#007700">(</font><font color="#0000bb">s</font><font color="#007700">) </font><font color="#0000bb">is unicode </font><font color="#007700">and </font><font color="#0000bb">s</font><font color="#007700">.</font><font color="#0000bb">strip</font><font color="#007700">():
<br>
<br> </font><font color="#0000bb">write</font><font color="#007700">(</font><font color="#dd0000">" "</font><font color="#007700">+</font><font color="#0000bb">s</font><font color="#007700">.</font><font color="#0000bb">encode</font><font color="#007700">(</font><font color="#dd0000">'utf-8'</font><font color="#007700">).</font><font color="#0000bb">strip</font><font color="#007700">())
<br>
<br> </font><font color="#0000bb">elif tagname</font><font color="#007700">(</font><font color="#0000bb">s</font><font color="#007700">)==</font><font color="#dd0000">'text_span'</font><font color="#007700">:
<br>
<br> </font><font color="#0000bb">write</font><font color="#007700">(</font><font color="#dd0000">" "</font><font color="#007700">+</font><font color="#0000bb">s</font><font color="#007700">.</font><font color="#0000bb">CDATA</font><font color="#007700">.</font><font color="#0000bb">encode</font><font color="#007700">(</font><font color="#dd0000">'utf-8'</font><font color="#007700">))
<br>
<br> </font><font color="#0000bb">write</font><font color="#007700">(</font><font color="#dd0000">'\n'</font><font color="#007700">)
<br></font><font color="#0000bb"></font>
</font>
</code><!-- php buffer end -->
</code>
</div>
</td></tr></tbody></table>
</div>
[/php]
显示是
[php]#!/usr/bin/python
import sys, zipfile
from gnosis.xml.objectify import XML_Objectify, EXPAT, \
children, tagname, content
XML_Objectify.expat_kwargs['nspace_sep'] = None
doc_content = zipfile.ZipFile(sys.argv[1]).read('content.xml')
doc = XML_Objectify(doc_content).make_instance()
write = sys.stdout.write
for o in children(doc.office_body):
if tagname(o)=="text_p":
for s in content(o):
if type(s) is unicode and s.strip():
write(" "+s.encode('utf-8').strip())
elif tagname(s)=='text_span':
write(" "+s.PCDATA.encode('utf-8'))
write('\n')
[/php] |
|