Skip to content

Commit cb965a9

Browse files
committed
fix for issue #55.
1 parent e667bff commit cb965a9

2 files changed

Lines changed: 115 additions & 1 deletion

File tree

tests/test_github_issues.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,114 @@ def test_github_issue_52():
199199
'</td>\n\t\t\t<td style="text-align:center;">Second Header </td>'
200200
'\n\t\t</tr>\n\t</table>')
201201
assert result == expect
202+
203+
def test_github_issue_55():
204+
"""Incorrect handling of quote entities in extended pre block"""
205+
test = ('pre.. this is the first line\n\nbut "quotes" in an extended pre '
206+
'block need to be handled properly.')
207+
result = textile.textile(test)
208+
expect = ('<pre>this is the first line\n\nbut &quot;quotes&quot; in an '
209+
'extended pre block need to be handled properly.</pre>')
210+
assert result == expect
211+
212+
# supplied input
213+
test = ('''pre.. import org.slf4j.Logger;
214+
import org.slf4j.LoggerFactory;
215+
import ru.onyma.job.Context;
216+
import ru.onyma.job.RescheduleTask;
217+
218+
import java.util.concurrent.ScheduledExecutorService;
219+
import java.util.concurrent.TimeUnit;
220+
221+
/**
222+
* @author ustits
223+
*/
224+
public abstract class MainService<T> extends RescheduleTask implements Context<T> {
225+
226+
private static final Logger log = LoggerFactory.getLogger(MainService.class);
227+
private final ScheduledExecutorService scheduler;
228+
229+
private boolean isFirstRun = true;
230+
private T configs;
231+
232+
public MainService(final ScheduledExecutorService scheduler) {
233+
super(scheduler);
234+
this.scheduler = scheduler;
235+
}
236+
237+
@Override
238+
public void setConfig(final T configs) {
239+
this.configs = configs;
240+
if (isFirstRun) {
241+
scheduler.schedule(this, 0, TimeUnit.SECONDS);
242+
isFirstRun = false;
243+
}
244+
}
245+
246+
@Override
247+
public void stop() {
248+
super.stop();
249+
scheduler.shutdown();
250+
try {
251+
scheduler.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
252+
} catch (InterruptedException ie) {
253+
log.warn("Unable to wait for syncs termination", ie);
254+
Thread.currentThread().interrupt();
255+
}
256+
}
257+
258+
protected final T getConfigs() {
259+
return configs;
260+
}
261+
}''')
262+
result = textile.textile(test)
263+
expect = ('''<pre>import org.slf4j.Logger;
264+
import org.slf4j.LoggerFactory;
265+
import ru.onyma.job.Context;
266+
import ru.onyma.job.RescheduleTask;
267+
268+
import java.util.concurrent.ScheduledExecutorService;
269+
import java.util.concurrent.TimeUnit;
270+
271+
/**
272+
* @author ustits
273+
*/
274+
public abstract class MainService&lt;T&gt; extends RescheduleTask implements Context&lt;T&gt; {
275+
276+
private static final Logger log = LoggerFactory.getLogger(MainService.class);
277+
private final ScheduledExecutorService scheduler;
278+
279+
private boolean isFirstRun = true;
280+
private T configs;
281+
282+
public MainService(final ScheduledExecutorService scheduler) {
283+
super(scheduler);
284+
this.scheduler = scheduler;
285+
}
286+
287+
@Override
288+
public void setConfig(final T configs) {
289+
this.configs = configs;
290+
if (isFirstRun) {
291+
scheduler.schedule(this, 0, TimeUnit.SECONDS);
292+
isFirstRun = false;
293+
}
294+
}
295+
296+
@Override
297+
public void stop() {
298+
super.stop();
299+
scheduler.shutdown();
300+
try {
301+
scheduler.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
302+
} catch (InterruptedException ie) {
303+
log.warn(&quot;Unable to wait for syncs termination&quot;, ie);
304+
Thread.currentThread().interrupt();
305+
}
306+
}
307+
308+
protected final T getConfigs() {
309+
return configs;
310+
}
311+
}</pre>''')
312+
assert result == expect

textile/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,10 @@ def block(self, text):
506506
block.outer_atts)
507507
line = "\t{0}".format(line)
508508
else:
509-
line = self.graf(line)
509+
if block.tag == 'pre':
510+
line = self.shelve(encode_html(line, quotes=True))
511+
else:
512+
line = self.graf(line)
510513

511514
line = self.doPBr(line)
512515
line = line.replace('<br>', '<br />')

0 commit comments

Comments
 (0)