csv 入力から pdf ファイルをレンダリングするテンプレートを作成しました。ただし、csv 入力フィールドに改行やインデントを含むユーザー書式が含まれていると、rst2pdf 書式設定エンジンが混乱します。ドキュメント フローを壊さずに、入力テキストの書式設定を維持しながら、一貫してユーザー入力を処理する方法はありますか? 以下のスクリプト例:
from mako.template import Template
from rst2pdf.createpdf import RstToPdf
mytext = """This is the first line
Then there is a second
Then a third
This one could be indented
I'd like it to maintain the formatting."""
template = """
My PDF Document
===============
It starts with a paragraph, but after this I'd like to insert `mytext`.
It should keep the formatting intact, though I don't know what formatting to expect.
${mytext}
"""
mytemplate = Template(template)
pdf = RstToPdf()
pdf.createPdf(text=mytemplate.render(mytext=mytext),output='foo.pdf')
テンプレートに次の関数を追加して|
各行の先頭に挿入しようとしましたが、それもうまくいかないようです。
<%!
def wrap(text):
return text.replace("\\n", "\\n|")
%>
その後${mytext}
、 になり|${mytext | wrap}
ます。これはエラーをスローします:
<string>:10: (WARNING/2) Inline substitution_reference start-string without end-string.