Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

# -*- coding: utf-8 -*- 

""" 

@file 

@brief Converts quotes into :epkg:`rst`. 

""" 

import textwrap 

 

 

def to_rst(quote): 

""" 

Converts a quote defined as a dictionary 

into :epkg:`rst`. 

 

@param quote dictionary 

@return text file 

""" 

rows = [".. quote::"] 

for k, v in quote.items(): 

if k != 'content': 

rows.append(" :{0}: {1}".format(k, v)) 

if 'content' not in quote: 

raise KeyError("Unable to kind key 'content'.") 

 

content = quote['content'].replace("\n\n", '#LINE#').replace('\n', ' ') 

content = content.replace('\r', '').replace('\t', ' ') 

content = ' '.join(content.split()).strip() 

text = "\n".join(textwrap.wrap(content, 60)) 

text = text.replace("`", "").replace("\\textit", "") 

text = text.replace('{', '*').replace('}', '*') 

text = text.replace('#LINE#', '\n\n').strip("\n") 

text = textwrap.indent(text, ' ') 

text = text.replace(" - ", " — ") 

rows.append('') 

rows.append(text) 

rows.append('') 

return "\n".join(rows)