Commit 34c9190b authored by ussrhero's avatar ussrhero
Browse files

added markdown formatter for auto created documentation

parent e44c8541
......@@ -37,6 +37,46 @@ class CodeplexFormatter:
def anchor( self, link ):
return "{anchor:" + link + "}" + self.endl()
class MarkdownFormatter:
def endl( self ):
return "\n"
def header1( self, s ):
return "# " + s + self.endl()
def header2( self, s ):
return "## " + s + self.endl()
def header3( self, s ):
return "### " + s + self.endl()
def header4( self, s ):
return "#### " + s + self.endl()
def bulletItem( self, s ):
return "* " + s + self.endl()
def escapeMarkup( self, s ):
return self.endl() + "```" + self.endl() + s + self.endl() + "```" + self.endl()
def link( self, text, link ):
return "[" + text + "](#" + link + ")"
def anchor( self, link ):
return "<a name=\"" + link + "\"></a>" + self.endl()
def escapeSymbols(self, text):
output = ""
escapeSyms = ['_']
for s in text:
if s in escapeSyms:
output += "\\" + s
else:
output += s
return output
......@@ -58,12 +98,15 @@ def buildDoc( ioStream, formatter, apiInfo ):
for func in apiInfo.funcs:
ioStream.write( formatter.bulletItem( formatter.link( func.__name__, func.__name__ ) ) )
ioStream.write( formatter.endl() )
ioStream.write( formatter.header2( "Classes" ) )
for cls in apiInfo.classes:
ioStream.write( formatter.bulletItem( formatter.link( cls.__name__, cls.__name__ ) ) )
ioStream.write( formatter.endl() )
for func in apiInfo.funcs:
ioStream.write( formatter.anchor( func.__name__ ) )
......@@ -89,32 +132,34 @@ def buildDoc( ioStream, formatter, apiInfo ):
ioStream.write( formatter.header4( "Properties:") )
for p in cls.properties:
ioStream.write( formatter.bulletItem( formatter.link( p[0], cls.__name__ + "." + p[0]) ) )
ioStream.write( formatter.endl() )
if cls.methods:
methods = filter( lambda m: m.__doc__ != None, cls.methods )
if methods:
ioStream.write( formatter.header4( "Methods:") )
for m in cls.methods:
if m.__doc__ != None:
ioStream.write( formatter.bulletItem( formatter.link( m.__name__, cls.__name__ + "." + m.__name__) ) )
for m in methods:
ioStream.write( formatter.bulletItem( formatter.link( formatter.escapeSymbols(m.__name__), cls.__name__ + "." + m.__name__)) )
ioStream.write( formatter.endl() )
if cls.enum:
ioStream.write( formatter.header4( "Values:") )
for v in cls.enum.items():
ioStream.write( formatter.bulletItem( "%s: %d" % v ) )
ioStream.write( formatter.endl() )
if cls.properties:
for p in cls.properties:
if p[1].__doc__ != None:
ioStream.write( formatter.anchor( cls.__name__ + "." + p[0] ) )
ioStream.write( formatter.header4( formatter.escapeMarkup( "Property " + cls.__name__ + "." + p[0] ) ) )
ioStream.write( formatter.header4( "Property " + cls.__name__ + "." + p[0] ) )
ioStream.write( formatter.escapeMarkup( p[1].__doc__ ) + formatter.endl() )
if cls.methods:
for m in cls.methods:
if m.__doc__ != None:
ioStream.write( formatter.anchor( cls.__name__ + "." + m.__name__ ) )
ioStream.write( formatter.header4( formatter.escapeMarkup( "Method " + cls.__name__ + "." + m.__name__ ) ) )
ioStream.write( formatter.escapeMarkup( m.__doc__ ) + formatter.endl() )
if methods:
for m in methods:
ioStream.write( formatter.anchor( cls.__name__ + "." + m.__name__ ) )
ioStream.write( formatter.header4( formatter.escapeSymbols("Method " + cls.__name__ + "." + m.__name__ )) )
ioStream.write( formatter.escapeMarkup( m.__doc__ ) + formatter.endl() )
def main():
......@@ -133,7 +178,8 @@ def main():
apiInfo = ModuleInfo( module )
formatter = CodeplexFormatter()
#formatter = CodeplexFormatter()
formatter = MarkdownFormatter()
buildDoc( wikiIo, formatter, apiInfo )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment