sphinx-hatena / extensions / confluenceWriter.py

  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
 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
#!/usr/bin/env python
#coding:utf-8
import re
import textwrap

from docutils import nodes, writers

from sphinx import addnodes
from sphinx.locale import admonitionlabels, versionlabels
from sphinx.writers.text import TextWriter, TextTranslator


class ConfluenceWriter(TextWriter):
    def translate(self):
        visitor = ConfluenceTranslator(self.document, self.builder)
        self.document.walkabout(visitor)
        self.output = visitor.body


# # monkey-patch from TextTranslator
# new_wordsep_re = re.compile(
#         r'(\s+|'                                  # any whitespace
#         r'(?<=\s)(?::[a-z-]+:)?`\S+|'             # interpreted text start
#         r'[^\s\w]*\w+[a-zA-Z]-(?=\w+[a-zA-Z])|'   # hyphenated words
#         r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))')   # em-dash
# textwrap.TextWrapper.wordsep_re = new_wordsep_re
# 
# MAXWIDTH = 70
# STDINDENT = 3

def isstring(s):
    return isinstance(s, unicode) or isinstance(s, str)

class InlineFailure(Exception):
    """hoge"""

def inline_failure():
    raise InlineFailure

class Block():
    def __init__(self, parent):

        self.parent = parent
        self.contents = []
        # It is a list of string (with inlined markups) and bloks 

    def name(self):
        return self.__class__.__name__

    def __str__(self):
        return self.name() + '[' + ','.join([str(elem) for elem in self.contents]) + ']'

    def is_first_item(self):
        if self.parent:
            return self is self.parent.contents[0]
        else:
            True

    def append_string(self, elem):
        # if the last elem is string and elem is a string too, concatenate it
        if self.contents and isstring(self.contents[-1]):
            self.contents[-1] += ' ' + elem
        else:
            self.contents.extend([elem])

    def append(self, elem):
        if isstring(elem):
            self.append_string(elem)
        else:
            self.contents.extend([elem])

    def append_inlined(self, elem):
        if isstring(elem):
            self.append_string(elem)
        else:
            self.append_string(elem.try_inline())

    def elem_to_string(self, indent, x):
        if isinstance(x, unicode) or isinstance(x,str):
            return ' ' * indent + re.sub(r'[\n\r]+', ' ', x)
        else:
            return x.to_string(indent)

    def to_string(self, indent):
        return '\n'.join([self.elem_to_string(indent, x) for x in self.contents])

    def try_inline_elem(self, elem): # string is special and thus stupid
        if isstring(elem):
            return elem
        else:
            return elem.try_inline()

    def try_inline_internal(self):
        return ' '.join([self.try_inline_elem(elem) for elem in self.contents])

    # may raise InlineFailure
    def try_inline(self):
        inline_failure()
        
class Title(Block):
    def __init__(self, parent, level):
        Block.__init__(self, parent)
        self.level = level

    def to_string(self, indent):
        line = 'h' + str(self.level) + '. ' + Block.try_inline_internal(self)
        if self.is_first_item(): # does not work ?
            return '\n' + line
        else:
            return '\n' + line

class Par(Block):
    def __init__(self, parent):
        Block.__init__(self, parent)

    def to_string(self, indent):
        if self.is_first_item():
            return Block.to_string(self, indent)
        else:
            return '\n' + Block.to_string(self, indent)

    def try_inline(self):
        if self.is_first_item():
            return self.try_inline_internal()
        else:
            print "HOGE" + str(self.contents)
            inline_failure()

class PAREN(Block):
    def __init__(self, parent, open, close):
        Block.__init__(self, parent)
        self.open = open
        self.close = close

    def to_string(self, indent):
        try:
            return ' ' * indent + self.open + self.try_inline_internal() + self.close
        except InlineFailure:
            return ' ' * indent + self.open + '\n' + Block.to_string(self, indent+2) + '\n' + ' ' * indent + self.close

    def try_inline(self):
        return self.open + self.try_inline_internal() + self.close

class HTML(Block):
    def __init__(self, parent, tag):
        Block.__init__(self, parent)
        self.tagname = tag

    def name(self):
        return self.tagname

    def tag(self):
        return self.tagname

    def to_string(self, indent):
        try:
            return ' ' * indent + '<' + self.tag() + '>' + self.try_inline_internal() + '</' + self.tag() + '>'
        except InlineFailure:
            return ' ' * indent + '<' + self.tag() + '>\n' + Block.to_string(self, indent+2) + '\n' + ' ' * indent + '</' + self.tag() + '>' 

class LItem(Block):
    def __init__(self, parent, listlevels):
        Block.__init__(self, parent)
        self.listlevels = listlevels

    def to_string(self, indent):
        return str(self.listlevels) + ' ' + Block.to_string(self, 0)

class LiteralBlock(Block):
    def __init__(self, parent, lang):
        Block.__init__(self, parent)
        self.lang = lang
        
    def append_string(self, elem):
        self.contents.extend(elem.split('\n'))

    def to_string(self, indent):
        return '{code}' + '\n' + Block.to_string(self, 0) + '\n{code}'

class Verbose(Block):
    def __init__(self, parent, name):
        Block.__init__(self, parent)
        self.name = name

    def to_string(self, indent):
        return ' ' * indent + '<' + self.name + '>\n' + Block.to_string(self, indent+2) + '\n' + ' ' * indent + '</' + self.name + '>'

class ConfluenceTranslator(nodes.NodeVisitor):
    sectionchars = '*=-~"+'

    def __init__(self, document, builder):
        nodes.NodeVisitor.__init__(self, document)

        self.theBlock = Block(None)
        self.block = self.theBlock
        self.sectionlevel = 0
        self.highlightlang = ''

        self.listlevels = ''

    def add_text(self, text):
        self.block.append(text)

    def new_block(self, blockCls, *args):
        b = blockCls(self.block, *args)
        self.block.append(b)
        self.block = b

    def end_block(self):
        parent = self.block.parent
        self.block = parent

    def new_inlined_block(self, blockCls, *args):
        b = blockCls(self.block, *args)
        self.block = b

    def end_inlined_block(self):
        b = self.block
        parent = self.block.parent
        self.block = parent
        self.block.append(b.try_inline())

    def visit_document(self, node):
        pass
    def depart_document(self, node):
        self.body = self.theBlock.to_string(0) + '\n'

        # XXX header/footer?

    def visit_highlightlang(self, node):
        self.highlightlang = node['lang']
    def depart_highlightlang(self, node):
        pass

    def visit_section(self, node):
        self.sectionlevel += 1
    def depart_section(self, node):
        self.sectionlevel -= 1

#    def visit_topic(self, node):
#        self.new_state(0)
#    def depart_topic(self, node):
#        self.end_state()
#
#    visit_sidebar = visit_topic
#    depart_sidebar = depart_topic
#
#    def visit_rubric(self, node):
#        self.new_state(0)
#        self.add_text('-[ ')
#    def depart_rubric(self, node):
#        self.add_text(' ]-')
#        self.end_state()
#
#    def visit_compound(self, node):
#        pass
#    def depart_compound(self, node):
#        pass
#
#    def visit_glossary(self, node):
#        pass
#    def depart_glossary(self, node):
#        pass
#
    def visit_title(self, node):
        self.new_block(Title, self.sectionlevel)
    def depart_title(self, node):
        self.end_block()

#    def visit_subtitle(self, node):
#        pass
#    def depart_subtitle(self, node):
#        pass
#
#    def visit_attribution(self, node):
#        self.add_text('-- ')
#    def depart_attribution(self, node):
#        pass
#
#    def visit_module(self, node):
#        if node.has_key('platform'):
#            self.new_state(0)
#            self.add_text(_('Platform: %s') % node['platform'])
#            self.end_state()
#        raise nodes.SkipNode
#
#    def visit_desc(self, node):
#        pass
#    def depart_desc(self, node):
#        pass
#
#    def visit_desc_signature(self, node):
#        self.new_state(0)
#        if node.parent['desctype'] in ('class', 'exception'):
#            self.add_text('%s ' % node.parent['desctype'])
#    def depart_desc_signature(self, node):
#        # XXX: wrap signatures in a way that makes sense
#        self.end_state(wrap=False, end=None)
#
#    def visit_desc_name(self, node):
#        pass
#    def depart_desc_name(self, node):
#        pass
#
#    def visit_desc_addname(self, node):
#        pass
#    def depart_desc_addname(self, node):
#        pass
#
#    def visit_desc_type(self, node):
#        pass
#    def depart_desc_type(self, node):
#        pass
#
#    def visit_desc_returns(self, node):
#        self.add_text(' -> ')
#    def depart_desc_returns(self, node):
#        pass
#
#    def visit_desc_parameterlist(self, node):
#        self.add_text('(')
#        self.first_param = 1
#    def depart_desc_parameterlist(self, node):
#        self.add_text(')')
#
#    def visit_desc_parameter(self, node):
#        if not self.first_param:
#            self.add_text(', ')
#        else:
#            self.first_param = 0
#        self.add_text(node.astext())
#        raise nodes.SkipNode
#
#    def visit_desc_optional(self, node):
#        self.add_text('[')
#    def depart_desc_optional(self, node):
#        self.add_text(']')
#
#    def visit_desc_annotation(self, node):
#        pass
#    def depart_desc_annotation(self, node):
#        pass
#
#    def visit_refcount(self, node):
#        pass
#    def depart_refcount(self, node):
#        pass
#
#    def visit_desc_content(self, node):
#        self.new_state()
#        self.add_text('\n')
#    def depart_desc_content(self, node):
#        self.end_state()
#
#    def visit_figure(self, node):
#        self.new_state()
#    def depart_figure(self, node):
#        self.end_state()
#
#    def visit_caption(self, node):
#        pass
#    def depart_caption(self, node):
#        pass
#
#    def visit_productionlist(self, node):
#        self.new_state()
#        names = []
#        for production in node:
#            names.append(production['tokenname'])
#        maxlen = max(len(name) for name in names)
#        for production in node:
#            if production['tokenname']:
#                self.add_text(production['tokenname'].ljust(maxlen) + ' ::=')
#                lastname = production['tokenname']
#            else:
#                self.add_text('%s    ' % (' '*len(lastname)))
#            self.add_text(production.astext() + '\n')
#        self.end_state(wrap=False)
#        raise nodes.SkipNode
#
#    def visit_seealso(self, node):
#        self.new_state()
#    def depart_seealso(self, node):
#        self.end_state(first='')
#
#    def visit_footnote(self, node):
#        self._footnote = node.children[0].astext().strip()
#        self.new_state(len(self._footnote) + 3)
#    def depart_footnote(self, node):
#        self.end_state(first='[%s] ' % self._footnote)
#
#    def visit_citation(self, node):
#        if len(node) and isinstance(node[0], nodes.label):
#            self._citlabel = node[0].astext()
#        else:
#            self._citlabel = ''
#        self.new_state(len(self._citlabel) + 3)
#    def depart_citation(self, node):
#        self.end_state(first='[%s] ' % self._citlabel)
#
#    def visit_label(self, node):
#        raise nodes.SkipNode
#
#    # XXX: option list could use some better styling
#
#    def visit_option_list(self, node):
#        pass
#    def depart_option_list(self, node):
#        pass
#
#    def visit_option_list_item(self, node):
#        self.new_state(0)
#    def depart_option_list_item(self, node):
#        self.end_state()
#
#    def visit_option_group(self, node):
#        self._firstoption = True
#    def depart_option_group(self, node):
#        self.add_text('     ')
#
#    def visit_option(self, node):
#        if self._firstoption:
#            self._firstoption = False
#        else:
#            self.add_text(', ')
#    def depart_option(self, node):
#        pass
#
#    def visit_option_string(self, node):
#        pass
#    def depart_option_string(self, node):
#        pass
#
#    def visit_option_argument(self, node):
#        self.add_text(node['delimiter'])
#    def depart_option_argument(self, node):
#        pass
#
#    def visit_description(self, node):
#        pass
#    def depart_description(self, node):
#        pass
#
#    def visit_tabular_col_spec(self, node):
#        raise nodes.SkipNode
#
#    def visit_colspec(self, node):
#        self.table[0].append(node['colwidth'])
#        raise nodes.SkipNode
#
#    def visit_tgroup(self, node):
#        pass
#    def depart_tgroup(self, node):
#        pass
#
#    def visit_thead(self, node):
#        pass
#    def depart_thead(self, node):
#        pass
#
#    def visit_tbody(self, node):
#        self.table.append('sep')
#    def depart_tbody(self, node):
#        pass
#
#    def visit_row(self, node):
#        self.table.append([])
#    def depart_row(self, node):
#        pass
#
#    def visit_entry(self, node):
#        if node.has_key('morerows') or node.has_key('morecols'):
#            raise NotImplementedError('Column or row spanning cells are '
#                                      'not implemented.')
#        self.new_state(0)
#    def depart_entry(self, node):
#        text = '\n'.join('\n'.join(x[1]) for x in self.states.pop())
#        self.stateindent.pop()
#        self.table[-1].append(text)
#
#    def visit_table(self, node):
#        if self.table:
#            raise NotImplementedError('Nested tables are not supported.')
#        self.new_state(0)
#        self.table = [[]]
#    def depart_table(self, node):
#        lines = self.table[1:]
#        fmted_rows = []
#        colwidths = self.table[0]
#        realwidths = colwidths[:]
#        separator = 0
#        # don't allow paragraphs in table cells for now
#        for line in lines:
#            if line == 'sep':
#                separator = len(fmted_rows)
#            else:
#                cells = []
#                for i, cell in enumerate(line):
#                    par = textwrap.wrap(cell, width=colwidths[i])
#                    if par:
#                        maxwidth = max(map(len, par))
#                    else:
#                        maxwidth = 0
#                    realwidths[i] = max(realwidths[i], maxwidth)
#                    cells.append(par)
#                fmted_rows.append(cells)
#
#        def writesep(char='-'):
#            out = ['+']
#            for width in realwidths:
#                out.append(char * (width+2))
#                out.append('+')
#            self.add_text(''.join(out) + '\n')
#
#        def writerow(row):
#            lines = map(None, *row)
#            for line in lines:
#                out = ['|']
#                for i, cell in enumerate(line):
#                    if cell:
#                        out.append(' ' + cell.ljust(realwidths[i]+1))
#                    else:
#                        out.append(' ' * (realwidths[i] + 2))
#                    out.append('|')
#                self.add_text(''.join(out) + '\n')
#
#        for i, row in enumerate(fmted_rows):
#            if separator and i == separator:
#                writesep('=')
#            else:
#                writesep('-')
#            writerow(row)
#        writesep('-')
#        self.table = None
#        self.end_state(wrap=False)
#
#    def visit_acks(self, node):
#        self.new_state(0)
#        self.add_text(', '.join(n.astext() for n in node.children[0].children)
#                      + '.')
#        self.end_state()
#        raise nodes.SkipNode
#
#    def visit_image(self, node):
#        self.add_text(_('[image]'))
#        raise nodes.SkipNode
#
#    def visit_transition(self, node):
#        indent = sum(self.stateindent)
#        self.new_state(0)
#        self.add_text('=' * (MAXWIDTH - indent))
#        self.end_state()
#        raise nodes.SkipNode

            
    def visit_bullet_list(self, node):
        self.listlevels = self.listlevels + '*'
    def depart_bullet_list(self, node):
        self.listlevels = self.listlevels[0:-1]

    def visit_enumerated_list(self, node):
        self.listlevels = self.listlevels + '#'
    def depart_enumerated_list(self, node):
        self.listlevels = self.listlevels[0:-1]

    # Hehehe, our confluence is too old and does not support {html}
    def visit_definition_list(self, node):
        self.listlevels = self.listlevels + '*'
    def depart_definition_list(self, node):
        self.listlevels = self.listlevels[0:-1]

    def visit_list_item(self, node):
        self.new_block(LItem, self.listlevels)
    def depart_list_item(self, node):
        self.end_block()

#    def visit_list_item(self, node):
#        if self.list_counter[-1] == -1:
#            # bullet list
#            self.new_state(2)
#        elif self.list_counter[-1] == -2:
#            # definition list
#            pass
#        else:
#            # enumerated list
#            self.list_counter[-1] += 1
#            self.new_state(len(str(self.list_counter[-1])) + 2)
#    def depart_list_item(self, node):
#        if self.list_counter[-1] == -1:
#            self.end_state(first='* ', end=None)
#        elif self.list_counter[-1] == -2:
#            pass
#        else:
#            self.end_state(first='%s. ' % self.list_counter[-1], end=None)

    def visit_definition_list_item(self, node):
        self._li_has_classifier = len(node) >= 2 and \
                                  isinstance(node[1], nodes.classifier)
        pass
    def depart_definition_list_item(self, node):
        pass

    def visit_term(self, node):
        self.new_block(LItem, self.listlevels)
    def depart_term(self, node):
        self.end_block()

#        if not self._li_has_classifier:
#            self.end_state(end=None)

#    def visit_classifier(self, node):
#        self.add_text(' : ')
#    def depart_classifier(self, node):
#        self.end_state(end=None)

    def visit_definition(self, node):
        self.listlevels = self.listlevels + '*'
        self.new_block(LItem, self.listlevels)
    def depart_definition(self, node):
        self.end_block()
        self.listlevels = self.listlevels[0:-1]

#    def visit_field_list(self, node):
#        pass
#    def depart_field_list(self, node):
#        pass
#
#    def visit_field(self, node):
#        pass
#    def depart_field(self, node):
#        pass
#
#    def visit_field_name(self, node):
#        self.new_state(0)
#    def depart_field_name(self, node):
#        self.add_text(':')
#        self.end_state(end=None)
#
#    def visit_field_body(self, node):
#        self.new_state()
#    def depart_field_body(self, node):
#        self.end_state()
#
#    def visit_centered(self, node):
#        pass
#    def depart_centered(self, node):
#        pass
#
#    def visit_hlist(self, node):
#        pass
#    def depart_hlist(self, node):
#        pass
#
#    def visit_hlistcol(self, node):
#        pass
#    def depart_hlistcol(self, node):
#        pass
#
#    def visit_admonition(self, node):
#        self.new_state(0)
#    def depart_admonition(self, node):
#        self.end_state()
#
#    def _visit_admonition(self, node):
#        self.new_state(2)
#    def _make_depart_admonition(name):
#        def depart_admonition(self, node):
#            self.end_state(first=admonitionlabels[name] + ': ')
#        return depart_admonition
#
#    visit_attention = _visit_admonition
#    depart_attention = _make_depart_admonition('attention')
#    visit_caution = _visit_admonition
#    depart_caution = _make_depart_admonition('caution')
#    visit_danger = _visit_admonition
#    depart_danger = _make_depart_admonition('danger')
#    visit_error = _visit_admonition
#    depart_error = _make_depart_admonition('error')
#    visit_hint = _visit_admonition
#    depart_hint = _make_depart_admonition('hint')
#    visit_important = _visit_admonition
#    depart_important = _make_depart_admonition('important')
#    visit_note = _visit_admonition
#    depart_note = _make_depart_admonition('note')
#    visit_tip = _visit_admonition
#    depart_tip = _make_depart_admonition('tip')
#    visit_warning = _visit_admonition
#    depart_warning = _make_depart_admonition('warning')
#
#    def visit_versionmodified(self, node):
#        self.new_state(0)
#        if node.children:
#            self.add_text(versionlabels[node['type']] % node['version'] + ': ')
#        else:
#            self.add_text(versionlabels[node['type']] % node['version'] + '.')
#    def depart_versionmodified(self, node):
#        self.end_state()
#
    def visit_literal_block(self, node):
        self.new_block(LiteralBlock, self.highlightlang)
    def depart_literal_block(self, node):
        self.end_block()

#    def visit_doctest_block(self, node):
#        self.new_state(0)
#    def depart_doctest_block(self, node):
#        self.end_state(wrap=False)
#
#    def visit_line_block(self, node):
#        self.new_state(0)
#    def depart_line_block(self, node):
#        self.end_state(wrap=False)
#
#    def visit_line(self, node):
#        pass
#    def depart_line(self, node):
#        pass

    def visit_block_quote(self, node):
        self.new_block(Verbose, "block_quote")
    def depart_block_quote(self, node):
        self.end_block()

#    def visit_compact_paragraph(self, node):
#        pass
#    def depart_compact_paragraph(self, node):
#        pass

    def visit_paragraph(self, node):
        if not isinstance(node.parent, nodes.Admonition) or \
               isinstance(node.parent, addnodes.seealso):
            self.new_block(Par)
    def depart_paragraph(self, node):
        if not isinstance(node.parent, nodes.Admonition) or \
               isinstance(node.parent, addnodes.seealso):
            self.end_block()

    def visit_target(self, node):
        self.new_block(Verbose, "target")
    def depart_target(self, node):
        pass

#
#    def visit_index(self, node):
#        raise nodes.SkipNode
#
#    def visit_substitution_definition(self, node):
#        raise nodes.SkipNode
#
#    def visit_pending_xref(self, node):
#        pass
#    def depart_pending_xref(self, node):
#        pass
#
    def visit_reference(self, node):
        pass
    def depart_reference(self, node):
        pass

#    def visit_download_reference(self, node):
#        pass
#    def depart_download_reference(self, node):
#        pass

    def visit_emphasis(self, node):
        self.add_text('_')
    def depart_emphasis(self, node):
        self.add_text('_')

#    def visit_literal_emphasis(self, node):
#        self.add_text('<it>')
#    def depart_literal_emphasis(self, node):
#        self.add_text('</it>')

    def visit_strong(self, node):
        self.add_text('*')
    def depart_strong(self, node):
        self.add_text('*')

#    def visit_abbreviation(self, node):
#        self.add_text('')
#    def depart_abbreviation(self, node):
#        if node.hasattr('explanation'):
#            self.add_text(' (%s)' % node['explanation'])
#
#    def visit_title_reference(self, node):
#        self.add_text('*')
#    def depart_title_reference(self, node):
#        self.add_text('*')

    def visit_literal(self, node):
        self.new_inlined_block(PAREN, '{{', '}}') 
    def depart_literal(self, node):
        self.end_inlined_block()

#    def visit_subscript(self, node):
#        self.add_text('_')
#    def depart_subscript(self, node):
#        pass
#
#    def visit_superscript(self, node):
#        self.add_text('^')
#    def depart_superscript(self, node):
#        pass
#
#    def visit_footnote_reference(self, node):
#        self.add_text('[%s]' % node.astext())
#        raise nodes.SkipNode
#
#    def visit_citation_reference(self, node):
#        self.add_text('[%s]' % node.astext())
#        raise nodes.SkipNode

    def visit_Text(self, node):
        self.add_text(node.astext())
    def depart_Text(self, node):
        pass

#    def visit_generated(self, node):
#        pass
#    def depart_generated(self, node):
#        pass
#
#    def visit_inline(self, node):
#        pass
#    def depart_inline(self, node):
#        pass

    def visit_problematic(self, node):
        self.new_block(Verbose, "problematic")
    def depart_problematic(self, node):
        self.end_block()

#    def visit_system_message(self, node):
#        self.new_state(0)
#        self.add_text('<SYSTEM MESSAGE: %s>' % node.astext())
#        self.end_state()
#        raise nodes.SkipNode

    def visit_comment(self, node):
        raise nodes.SkipNode

    def visit_meta(self, node):
        # only valid for HTML
        raise nodes.SkipNode

#    def visit_raw(self, node):
#        if 'text' in node.get('format', '').split():
#            self.body.append(node.astext())
#        raise nodes.SkipNode

    def unknown_visit(self, node):
        print "WARNING: Not implemented. Skiping " + node.__class__.__name__
        self.new_block(HTML, node.__class__.__name__)

    def unknown_departure(self, node):
        self.end_block()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.