| @@ 336-367 (lines=32) @@ | ||
| 333 | 'title': m.group(3), |
|
| 334 | } |
|
| 335 | ||
| 336 | def parse_def_footnotes(self, m): |
|
| 337 | key = _keyify(m.group(1)) |
|
| 338 | if key in self.def_footnotes: |
|
| 339 | # footnote is already defined |
|
| 340 | return |
|
| 341 | ||
| 342 | self.def_footnotes[key] = 0 |
|
| 343 | ||
| 344 | self.tokens.append({ |
|
| 345 | 'type': 'footnote_start', |
|
| 346 | 'key': key, |
|
| 347 | }) |
|
| 348 | ||
| 349 | text = m.group(2) |
|
| 350 | ||
| 351 | if '\n' in text: |
|
| 352 | lines = text.split('\n') |
|
| 353 | whitespace = None |
|
| 354 | for line in lines[1:]: |
|
| 355 | space = len(line) - len(line.lstrip()) |
|
| 356 | if space and (not whitespace or space < whitespace): |
|
| 357 | whitespace = space |
|
| 358 | newlines = [lines[0]] |
|
| 359 | for line in lines[1:]: |
|
| 360 | newlines.append(line[whitespace:]) |
|
| 361 | text = '\n'.join(newlines) |
|
| 362 | ||
| 363 | self.parse(text, self.footnote_rules) |
|
| 364 | ||
| 365 | self.tokens.append({ |
|
| 366 | 'type': 'footnote_end', |
|
| 367 | 'key': key, |
|
| 368 | }) |
|
| 369 | ||
| 370 | def parse_table(self, m): |
|
| @@ 323-354 (lines=32) @@ | ||
| 320 | 'title': m.group(3), |
|
| 321 | } |
|
| 322 | ||
| 323 | def parse_def_footnotes(self, m): |
|
| 324 | key = _keyify(m.group(1)) |
|
| 325 | if key in self.def_footnotes: |
|
| 326 | # footnote is already defined |
|
| 327 | return |
|
| 328 | ||
| 329 | self.def_footnotes[key] = 0 |
|
| 330 | ||
| 331 | self.tokens.append({ |
|
| 332 | 'type': 'footnote_start', |
|
| 333 | 'key': key, |
|
| 334 | }) |
|
| 335 | ||
| 336 | text = m.group(2) |
|
| 337 | ||
| 338 | if '\n' in text: |
|
| 339 | lines = text.split('\n') |
|
| 340 | whitespace = None |
|
| 341 | for line in lines[1:]: |
|
| 342 | space = len(line) - len(line.lstrip()) |
|
| 343 | if space and (not whitespace or space < whitespace): |
|
| 344 | whitespace = space |
|
| 345 | newlines = [lines[0]] |
|
| 346 | for line in lines[1:]: |
|
| 347 | newlines.append(line[whitespace:]) |
|
| 348 | text = '\n'.join(newlines) |
|
| 349 | ||
| 350 | self.parse(text, self.footnote_rules) |
|
| 351 | ||
| 352 | self.tokens.append({ |
|
| 353 | 'type': 'footnote_end', |
|
| 354 | 'key': key, |
|
| 355 | }) |
|
| 356 | ||
| 357 | def parse_table(self, m): |
|