testDoc.py 8.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#! /usr/bin/python

#~ import pandoc
from pandoc import *

def main ():
	newDocument('title\nof the document', ['author1', 'author2'], '25 june\n2017')
	addTOC()
	
	newPage()
	header ('Test quote Block', 1, '#header1')
	quoteBlock (['text 1', ['text 2', ['text 3'], 'text 4'], 'text 5'])
	
14 15
	#~ rawText ('test header reference [header1]')
	rawText ('"blabla"')
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
	
	pageBreak()
	header ('Test code Block')
	header ('with string', 2)
	code1 = 'if (a > 3) { \n     moveShip(5 * gravity, DOWN); \n}'
	codeBlock (code1)
	
	header ('with list', 2)
	code2 = ['if (a > 3) {', '    moveShip(5 * gravity, DOWN);', '}']
	codeBlock (code2)
	
	header ('fenced with string', 2)
	codeBlockFenced (code1)
	
	newPage()
	header ('Test line Block')
	header ('with string', 2)
	lineBlock1 = 'line 1 \nline 2 \nline 3'
	lineBlock (lineBlock1)

	header ('with list', 2)
	lineBlock2 = ['line 1', 'line 2', 'line 3']
	lineBlock (lineBlock2)
	
	newPage()
	header ('Test list Block')
	header ('bullet list', 2)
	 
	testList1 = ['ab', ['a', ['a', 'b'], 'b', 'c'], 'b', 'c']
	listBlock(testList1)
	
	header ('ordered list', 2)
	testList2 = ['ab', 'bc', 'cd']
	orderedlistBlock(testList2)
	
	newPage()
	header ('horizontal rules')
	horizontalRule ()
	horizontalRule ('*', 4)
	horizontalRule ('_', 20)
	
	newPage()
	header ('tables')
	header ('simple table', 2)
	header ('with header', 3)
	table1_1 = [ \
		[['t1', 'right'],['title2', 'left'],['t3', 'center'], ['t4', 'default']], \
		['12', '12', '123', '12'], \
		['123', '123', '1234', '1234'], \
		['1', '1', '1', '1'] \
		]
	
	table1_2 = [ \
		[['tt1', 'right', 10],['title2', 'left', 1],['t3', 'center', 10], ['t4', 'default', 40]], \
		['12', '12', '123', '12'], \
		['123', '123', '1234', '1234'], \
		['1', '1', '1', '1'] \
		]
	
	table(table1_1, 'table 1_1 caption')
	newLine()
	table(table1_2, 'table 1_2 caption')
	newLine()
	
	
	header ('without header', 3)
	table2 = [ \
		[['', 'right', 10],['', 'left', 5],['', 'center', 2], ['', 'default', 20]], \
		['12', '12', '123', '12'], \
		['123', '123', '1234', '1234'], \
		['1', '1', '1', '1'] \
		]

	table(table2, 'test', ' ')
	
	newPage()
	header ('multiline table', 2)
	
	header ('with header', 3)
	table3_1 = [ \
		[['Centered\nHeader', 'center'],['Default\nAligned', 'default'],['Right\nAligned\ntest', 'right'], ['Left\nAligned', 'left']], \
		['First', 'rowbidule', '12.0', 'Example of a row that\nspans multiple lines.'], \
		['Second', 'row', '5.0', 'Here\'s another one. Note\nthe blank line between\nrows.'], \
		]
	
	table(table3_1)
	
	header ('without header', 3)
	table3_2 = [ \
		[['', 'center'],['', 'default'],['', 'right', 20], ['', 'left', 50]], \
		['First', 'row', '12.0', 'Example of a row that\nspans multiple lines.'], \
		['Second', 'row', '5.0', 'Here\'s another one. Note\nthe blank line between\nrows.'], \
		]

	table(table3_2)
	
	header ('grid table', 2)
	header ('with header', 3)
	table4_1 = [ \
		[['Fruit', 'default'],['Price', 'default'],['Advantages', 'default']], \
		['Bananas', '$1.34', '- built-in wrapper\n- bright color'], \
		['Oranges', '$2.10', '- cures scurvy\n- tasty'], \
		]
		
	table(table4_1, '', ' ', 'grid')
	
	table4_2 = [ \
		[['Fruit', 'left', 20],['Price', 'center'],['Advantages', 'right', 30]], \
		['Bananas', '$1.34', '- built-in wrapper\n- bright color'], \
		['Oranges', '$2.10', '- cures scurvy\n- tasty'], \
		]
		
	table(table4_2, '', ' ', 'grid')
	
	header ('without header', 3)
	table4_3 = [ \
		[['', 'left'],['', 'center'],['', 'right']], \
		['Bananas', '$1.34', '- built-in wrapper\n- bright color'], \
		['Oranges', '$2.10', '- cures scurvy\n- tasty'], \
		]
	#~ table4_3 = [ \
		#~ [['', 'left', 20],['', 'center'],['', 'right', 30]], \
		#~ ['Bananas', '$1.34', '- built-in wrapper\n- bright color'], \
		#~ ['Oranges', '$2.10', '- cures scurvy\n- tasty'], \
		#~ ]
		
	table(table4_3, '', ' ', 'grid')

	header ('pipe table', 2)
	header ('with header', 3)
	table5_1 = [ \
		[['Right', 'right'],['Left', 'left'],['Default', 'default'], ['Center', 'center']], \
		['12', '12', '123', '12'], \
		['123', '123', '123', '123'], \
		['1', '1', '1', '1'] \
		]
		
	table(table5_1, '', ' ', 'pipe')
	
	table5_2 = [ \
		[['Right\ntruc', 'right'],['Left', 'left', 30],['Default', 'default'], ['Center', 'center']], \
		['12', '12', '123', '12'], \
		['123', '123', '123', '123'], \
		['1', '1', '1', '1'] \
		]
		
	table(table5_2, '', ' ', 'pipe')

	header ('without header', 3)
	table5_3 = [ \
		[['', 'right'],['', 'left'],['', 'default'], ['', 'center']], \
		['12', '12', '123', '12'], \
		['123', '123', '123', '123'], \
		['1', '1', '1', '1'] \
		]
		
	table(table5_3, '', ' ', 'pipe')
	
	newPage()
	header ('text formatting')
	header ('emphase', 2)
	rawText('this is an ' + italic('italic') + ' emphase')
	newLine()
	rawText('this is a ' + bold('bold') + ' emphase')
	
	newLine()
	
	header ('strikeout', 2)
	rawText('this is a ' + strikeout('strike out'))
	
	newLine()
	
	header ('power and indice', 2)
	rawText('power : 2' + power('10'))
	newLine()
	rawText('indice : H' + indice('2') + '0')
	
	newLine()
	
	header ('verbatim', 2)
	rawText('verbatim text : ' + verbatim('this is a verbatim text') + '\n')
	rawText('verbatim text : ' + verbatim('this is a `verbatim` text'))

	newLine()
	
	header ('small caps', 2)
	rawText('small caps text : ' + smallCaps('this is a smallcaps text'))

	header ('math', 2)
	## tex math format shall be used with \\ for special char
	formula = '\\sqrt{\\frac{x^2}{3}}'
	rawText('math formula : ' + math(formula))

	newLine()
	
	newPage()
	header ('references')
	header ('automatic link', 2)
	urlLink = url('http://google.com')
	emailLink = email('sam@green.eggs.ham')
	rawText('url : ' + urlLink)
	rawText('email : ' + emailLink)
	
	newLine()
	header ('inline link', 2)
	header ('url', 3)
	inlineLink = url('http://fsf.org', 'inline link', 'click here for a good time!')
	rawText('This is an ' + inlineLink)
	
	header ('email', 3)
	inlineLink = email('sam@green.eggs.ham', 'Write me !')
	rawText(inlineLink)
	
	newLine()
	
	header ('reference link', 2)
	header ('non implicit', 3)
	referenceLink = reference('FSF', 'My Website')
	rawText('See ' + referenceLink)
	newLine()
	
	header ('implicit', 3)
	referenceLink = reference('My Website')
	rawText('See ' + referenceLink)
	newLine()
	
	header ('internal link', 2)
	headerLink = reference('#introduction', 'Introduction')
244
	rawText ('See the ' + headerLink)
245
	newLine()
246
	rawText ('Or')
247 248
	newLine()
	headerLink = reference('Introduction')
249
	rawText ('See the ' + headerLink)
250 251 252 253 254 255 256 257 258 259 260 261
	newLine()
	
	header ('images', 2)
	imageRef = image('la_lune.jpg', 'la lune', 'Voyage to the moon')
	rawText('An image : ' + imageRef)
	newLine()
	imageRef = image('la_lune.jpg', width = '50%')
	rawText('An image : ' + imageRef)
	newLine()
	imageRef = image('Blade Runner')
	rawText('An image : ' + imageRef)
	newLine()
262 263 264
	imageRef = image('logo.png', 'SVG Logo', 'SVG Logo', width = '50%')
	rawText('An image : ' + imageRef)
	newLine()
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317

	header ('definition', 2)
	definedReference('http://fsf.org', 'FSF', 'click here for a good time!')
	definedReference('http://truc.org', 'My Website')
	definedReference('#introduction', 'Introduction')
	definedReference('BladeRunner.gif', 'Blade Runner', 'title', 'width=10cm height=20px')

	newLine()
	
	newPage()
	header('footnote')
	header('reference with label', 2)
	
	f1 = footnote()
	f2 = footnote('longFoot')
		
	rawText('this is a simple footnote ' + f1 + ' and a long one ' + f2)
	newLine()

	header('inline footnote', 2)
	f3 = footnote(text = 'Inlines notes are easier to write, since \nyou don\'t have to pick an identifier and move down to type the \nnote.')
	rawText('Here is an inline note.' + f3)
	newLine()
	
	header('definition', 2)
	definedFootnote('1', 'A simple footnote.')
	definedFootnote('longFoot', 'Here\'s one with multiple blocks.\n\nSubsequent paragraphs are indented to show that they\nbelong to the previous footnote.\n\nThe whole paragraph can be indented, or just the first \nline.  In this way, multi-paragraph footnotes work like \nmulti-paragraph list items.', '\n')
	newLine()
	
	newPage()
	header('citations')
	c1 = citations('See @doe99', 'pp. 33-35', '@smith04')
	rawText('Blah blah ' + c1 + '\n')
	c2 = citations('@doe99', '@smith04')
	rawText('Blah blah ' + c2 + '\n')
	c3 = citations('@doe99', 'pp. 33-35, 38-39')
	rawText('Blah blah ' + c3 + '\n')
	c4 = citations('-@doe99')
	rawText('Blah blah ' + c4 + '\n')
	
	addBibliography('./biblio.bib')
	
	finalizeDocument()
	
	#~ printDocument ()

	#~ serialize ('test.md')

	convert('test.pdf', 'latex')
			
if __name__ == "__main__":
    main ()
    #~ sys.exit (0);                       # exit