Package doconce :: Module epytext
[hide private]
[frames] | no frames]

Source Code for Module doconce.epytext

  1  import re 
  2  from common import remove_code_and_tex, insert_code_and_tex, indent_lines, \ 
  3       default_movie, plain_exercise 
  4   
5 -def old_epytext_code(filestr):
6 # In rst syntax, code blocks are typeset with :: (verbatim) 7 # followed by intended blocks. This function indents everything 8 # inside code (or TeX) blocks. The code here is similar to 9 # rst.rst_code, but a special epytext version was 10 # necessary since epytext is fooled by \n in code/tex blocks. 11 12 # first indent all code/tex blocks: 13 filestr, code_blocks, tex_blocks = remove_code_and_tex(filestr) 14 for i in range(len(code_blocks)): 15 code_blocks[i] = indent_lines(code_blocks[i], True) 16 for i in range(len(tex_blocks)): 17 tex_blocks[i] = indent_lines(tex_blocks[i], True) 18 filestr = insert_code_and_tex(filestr, code_blocks, tex_blocks, 'rst') 19 20 # substitute !bc and !ec appropriately: 21 # (see rst.rst_code for comments if problems) 22 from rst import bc_regex_pattern, bt_regex_pattern 23 c = re.compile(bc_regex_pattern, re.DOTALL) 24 filestr = c.sub(r'\g<1>::\n\n', filestr) 25 filestr = re.sub(r'!ec\n', '\n\n', filestr) 26 c = re.compile(bt_regex_pattern, re.DOTALL) 27 filestr = c.sub(r'\g<1>::\n\n', filestr) 28 filestr = re.sub(r'!et\n', '\n\n', filestr) 29 return filestr
30
31 -def epytext_author(authors_and_institutions, auth2index, 32 inst2index, index2inst, auth2email):
33 text = 'BY: ' 34 ai = [] 35 for author, institutions, email in authors_and_institutions: 36 if institutions is not None: 37 ai.append('%s (%s)' % (author, ', and '.join(institutions))) 38 else: 39 ai.append(author) 40 text += '; '.join(ai) 41 return text
42 43
44 -def define(FILENAME_EXTENSION, 45 BLANKLINE, 46 INLINE_TAGS_SUBST, 47 CODE, 48 LIST, 49 ARGLIST, 50 TABLE, 51 EXERCISE, 52 FIGURE_EXT, 53 CROSS_REFS, 54 INDEX_BIB, 55 INTRO, 56 OUTRO):
57 # all arguments are dicts and accept in-place modifications (extensions) 58 59 FILENAME_EXTENSION['epytext'] = '.epytext' 60 BLANKLINE['epytext'] = '\n' 61 # replacement patterns for substitutions of inline tags 62 INLINE_TAGS_SUBST['epytext'] = { 63 'math': r'\g<begin>M{\g<subst>}\g<end>', 64 #'math2': r'\g<begin>M{\g<latexmath>}\g<end>', # has \ in \sin e.g. so we rather use the puretext version 65 'math2': r'\g<begin>M{\g<puretext>}\g<end>', 66 'emphasize': r'\g<begin>I{\g<subst>}\g<end>', 67 'bold': r'\g<begin>B{\g<subst>}\g<end>', 68 'verbatim': r'\g<begin>C{\g<subst>}\g<end>', 69 'linkURL': r'\g<begin>U{\g<link><\g<url>>}\g<end>', 70 'linkURL2': r'U{\g<link><\g<url>>}', 71 'linkURL3': r'U{\g<link><\g<url>>}', 72 'linkURL2v': r'U{C{\g<link>}<\g<url>>}', 73 'linkURL3v': r'U{C{\g<link>}<\g<url>>}', 74 'plainURL': r'U{\g<url><\g<url>>}', 75 # the replacement string differs, depending on the match object m: 76 'chapter': lambda m: r'\g<subst>\n%s' % ('%'*len(m.group('subst'))), 77 'section': lambda m: r'\g<subst>\n%s' % ('='*len(m.group('subst'))), 78 'subsection': lambda m: r'\g<subst>\n%s' % ('-'*len(m.group('subst'))), 79 'subsubsection': lambda m: r'\g<subst>\n%s' % ('~'*len(m.group('subst'))), 80 'paragraph': r'I{\g<subst>} ', 81 'abstract': r'\nI{\g<type>.} \g<text>\n\g<rest>', 82 'title': r'TITLE: \g<subst>', 83 'date': r'DATE: \g<subst>', 84 'author': epytext_author, 85 'movie': default_movie, 86 } 87 88 from rst import rst_code, rst_table 89 CODE['epytext'] = rst_code 90 TABLE['epytext'] = rst_table 91 from plaintext import plain_ref_and_label, plain_index_bib 92 CROSS_REFS['epytext'] = plain_ref_and_label 93 INDEX_BIB['epytext'] = plain_index_bib 94 EXERCISE['epytext'] = plain_exercise 95 96 LIST['epytext'] = { 97 'itemize': 98 {'begin': '', 'item': '-', 'end': '\n'}, 99 100 'enumerate': 101 {'begin': '', 'item': '%d.', 'end': '\n'}, 102 103 'description': 104 {'begin': '', 'item': '%s', 'end': '\n'}, 105 106 'separator': '', 107 } 108 ARGLIST['epytext'] = { 109 'parameter': '@param', 110 'keyword': '@keyword', 111 'return': '@return', 112 'instance variable': '@ivar', 113 'class variable': '@cvar', 114 'module variable': '@var', 115 }
116