Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We had a problem when using Reportlab to format some content that was originally html and sometimes the html was too complex. The solution (and I take no credit here, this was from the guys at Reportlab) was to catch the error when it occurred and output it directly into the PDF.</p> <p>That means you get to see the cause of the problem in the right context. You could expand on this to output details of the exception, but in our case since our problem was converting html to rml we just had to display our input:</p> <p>Tthe preppy template contains this:</p> <pre><code>{{script}} #This section contains python functions used within the rml. #we can import any helper code we need within the template, #to save passing in hundreds of helper functions at the top from rml_helpers import blocks {{endscript}} </code></pre> <p>and then later bits of template like:</p> <pre><code> {{if equip.specification}} &lt;condPageBreak height="1in"/&gt; &lt;para style="h2"&gt;Item specification&lt;/para&gt; {{blocks(equip.specification)}} {{endif}} </code></pre> <p>In rml_helpers.py we have:</p> <pre><code>from xml.sax.saxutils import escape from rlextra.radxml.html_cleaner import cleanBlocks from rlextra.radxml.xhtml2rml import xhtml2rml def q(stuff): """Quoting function which works with unicode strings. The data from Zope is Unicode objects. We need to explicitly convert to UTF8; then escape any ampersands. So u"Black &amp; Decker drill" becomes "Black &amp;amp; Decker drill" and any special characters (Euro, curly quote etc) end up suitable for XML. For completeness we'll accept 'None' objects as well and output an empty string. """ if stuff is None: return '' elif isinstance(stuff,unicode): stuff = escape(stuff.encode('utf8')) else: stuff = escape(str(stuff)) return stuff.replace('"','&amp;#34;').replace("'", '&amp;#39;') def blocks(txt): try: txt2 = cleanBlocks(txt) rml = xhtml2rml(txt2) return rml except: return '&lt;para style="big_warning"&gt;Could not process markup&lt;/para&gt;&lt;para style="normal"&gt;%s&lt;/para&gt;' % q(txt) </code></pre> <p>So anything which is too complex for <code>xhtml2rml</code> to handle throws an exception and is replaced in the output by a big warning 'Could not process markup' followed by the markup that caused the error, escaped so it appears as literal.</p> <p>Then all we have to do is to remember to search the output PDF for the error message and fix up the input accordingly.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload