File: formatter.py

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (104 lines) | stat: -rw-r--r-- 2,874 bytes parent folder | download | duplicates (2)
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
## @package formatter
# Module caffe2.python.docs.formatter




from caffe2.python.docs.parser import Parser


class Formatter(object):
    def __init__(self):
        self.content = ""

    def clone(self):
        return self.__class__()

    def dump(self):
        return self.content

    def parseAndAdd(self, text):
        text = Parser(text, self).parse()
        self.addRaw(text)

    def addRaw(self, text):
        raise Exception('Not yet implemented.')

    def addLine(self, text):
        raise Exception('Not yet implemented.')

    def addLinebreak(self):
        raise Exception('Not yet implemented.')

    def addHeader(self, text):
        raise Exception('Not yet implemented.')

    def addEmphasis(self, text):
        raise Exception('Not yet implemented.')

    def addList(self, textList):
        raise Exception('Not yet implemented.')

    def addLink(self, text, url):
        raise Exception('Not yet implemented.')

    def addCode(self, text):
        raise Exception('Not yet implemented.')

    def addCodeLink(self, text):
        raise Exception('Not yet implemented.')

    def addTable(self, table):
        raise Exception('Not yet implemented.')

    def addBreak(self):
        raise Exception('Not yet implemented.')


class Markdown(Formatter):
    def addRaw(self, text):
        self.content += "{text}".format(text=text)

    def addLine(self, text, new_line=False):
        self.content += "{line}{text}\n".format(line=('\n' if new_line else ''),
                                                text=text)

    def addLinebreak(self):
        self.content += "\n"

    def addHeader(self, text, h=1):
        self.addLine("{header} {text}".format(header=h * '#', text=text), True)

    def addEmphasis(self, text, s=1):
        self.addRaw("{stars}{text}{stars}".format(stars=s * '*', text=text))

    def addList(self, textList):
        for text in textList:
            self.addLine("- {text}".format(text=text), True)
        self.addLinebreak()

    def addLink(self, text, url):
        self.addRaw("[{text}]({url})".format(text=text, url=url))

    def addCodeLink(self, path, options=None):
        self.addRaw("({path})".format(path=path))

    def addCode(self, text, inline=False):
        if (inline):
            self.content += "`{text}`".format(text=text)
        else:
            self.addRaw("\n\n```\n{text}```\n\n".format(text=text))

    def addTable(self, table, noTitle=False):
        self.addLinebreak()
        assert(len(table) > 1)
        if noTitle:
            table.insert(0, [' ' for i in range(len(table[0]))])
        self.addLine(' | '.join(table[0]))
        self.addLine(' | '.join(['----' for i in range(len(table[0]))]))
        for row in table[1:]:
            self.addLine(' | '.join(row))
        self.addLinebreak()

    def addBreak(self):
        self.addLine('\n---\n', True)