|
1 | 1 | import os |
2 | 2 | import string |
3 | 3 | from docutils.core import publish_string |
| 4 | +from docutils.utils import SystemMessage |
| 5 | +import debug |
4 | 6 |
|
5 | 7 | from django.template import Template as DjangoTemplate, TemplateDoesNotExist, TemplateEncodingError |
6 | 8 | from django.template.loader import BaseLoader |
@@ -40,16 +42,23 @@ class RSTTemplate(PlainTemplate): |
40 | 42 |
|
41 | 43 | def render(self, context): |
42 | 44 | interpolated_string = super(RSTTemplate, self).render(context) |
43 | | - return publish_string(source=interpolated_string, |
44 | | - writer_name='html', |
45 | | - settings_overrides={ |
46 | | - 'input_encoding': 'unicode', |
47 | | - 'output_encoding': 'unicode', |
48 | | - 'embed_stylesheet': False, |
49 | | - 'xml_declaration': False, |
50 | | - 'template': RST_TEMPLATE, |
51 | | - }) |
52 | | - |
| 45 | + try: |
| 46 | + return publish_string(source=interpolated_string, |
| 47 | + writer_name='html', |
| 48 | + settings_overrides={ |
| 49 | + 'input_encoding': 'unicode', |
| 50 | + 'output_encoding': 'unicode', |
| 51 | + 'embed_stylesheet': False, |
| 52 | + 'xml_declaration': False, |
| 53 | + 'template': RST_TEMPLATE, |
| 54 | + 'halt_level': 2, |
| 55 | + }) |
| 56 | + except SystemMessage, e: |
| 57 | + e.message = e.message.replace('<string>:', 'line ') |
| 58 | + args = list(e.args) |
| 59 | + args[0] = args[0].replace('<string>:', 'line ') |
| 60 | + e.args = tuple(args) |
| 61 | + raise e |
53 | 62 |
|
54 | 63 | class Loader(BaseLoader): |
55 | 64 |
|
|
0 commit comments