Jelajahi Sumber

Fixed makedocs code indenting.

Mark Sibly 7 tahun lalu
induk
melakukan
559b3b3ddf

+ 1 - 1
src/mx2cc/mx2cc.monkey2

@@ -22,7 +22,7 @@ Global opts_time:Bool
 
 Global StartDir:String
 
-Const TestArgs:="mx2cc makemods -clean -config=debug pyro-framework"
+Const TestArgs:="mx2cc makedocs monkey"	'mods -clean -config=debug pyro-framework"
  
 'Const TestArgs:="mx2cc makeapp src/mx2cc/test.monkey2"
 

+ 27 - 10
src/mx2cc/newdocs/docsbuffer.monkey2

@@ -29,7 +29,21 @@ Class DocsBuffer
 	
 	Method EmitLine( line:String )
 		
-		line=line.Trim()
+		Local tline:=line.Trim()
+		
+		If tline.StartsWith( "```" )
+			If _pre=-1
+				_lines.Push( tline )
+				_pre=_lines.Length
+			Else
+				FixIndent( _pre,_lines.Length )
+				_lines.Push( tline )
+				_pre=-1
+			Endif
+			Return
+		Endif
+
+		If _pre=-1 line=tline Else Print line
 		
 		If Not line And _lines.Length And Not _lines.Top Return
 		
@@ -37,19 +51,23 @@ Class DocsBuffer
 	End
 	
 	Method EmitLines( lines:String[] )
-				
+		
 		Local i:=0
 		
 		While i<lines.Length
-		
-			Local line:=lines[i].Trim()
+			
+			Local line:=lines[i]
 			i+=1
+
+			Local tline:=line.Trim()
 			
-			If Not line.StartsWith( "@" )
+			If Not tline.StartsWith( "@" )
 				EmitLine( line )
 				Continue
 			Endif
 			
+			line=tline
+			
 			Local j:=line.Find( " " )
 			If j=-1 j=line.Length
 			
@@ -99,17 +117,14 @@ Class DocsBuffer
 				
 				Local i0:=i
 				While i<lines.Length And lines[i].Trim()<>"@end"
-					
 					EmitLine( lines[i] )
 					i+=1
 				Wend
 				
-'				FixIndent( i0,i )
-
 				EmitLine( "```" )
-
+				
 				If i<lines.Length i+=1
-					
+
 			Case "#","##","###","####","#####"
 				
 				Local label:=arg
@@ -196,6 +211,7 @@ Class DocsBuffer
 		_lines.Clear()
 		_label=""
 		_return=""
+		_pre=-1
 		
 		Return markdown
 	End
@@ -208,6 +224,7 @@ Class DocsBuffer
 	Field _label:String
 	Field _params:=New StringStack
 	Field _return:String
+	Field _pre:Int=-1
 	
 	Method FixIndent( i0:Int,i1:Int )
 		

+ 11 - 22
src/mx2cc/newdocs/markdown.monkey2

@@ -20,13 +20,13 @@ Class MarkdownConvertor
 		_buf.Clear()
 		
 		For Local i:=0 Until _lines.Length
-	
 			_lines[i]=_lines[i].TrimEnd()
 		Next
 		
 		While Not AtEnd
 		
-			Local line:=NextLine()
+			Local line:=NextLine().Trim()
+			If Not line Continue
 		
 			If line.StartsWith( "#" )
 			
@@ -40,19 +40,19 @@ Class MarkdownConvertor
 			
 				EmitList( line )
 				
-			Else If line.StartsWith( "```" )
+			Else If line.StartsWith( "<" )
 			
-				EmitCode( line )
+				Emit( line+"\" )
 				
 			Else If line.StartsWith( "---" )
 			
 				Emit( "<hr class="+_cls+">" )
 				
-			Else If line.StartsWith( "<" )
+			Else If line.StartsWith( "```" ) Or line.ToLower().StartsWith( "<pre>" )
 			
-				Emit( line+"\" )
+				EmitCode( line )
 				
-			Else If line
+			Else
 			
 				If _lineNum>1 And _lines[_lineNum-2]=""
 					Emit( "<p class="+_cls+">"+Escape( line ) )
@@ -60,20 +60,8 @@ Class MarkdownConvertor
 					Emit( Escape( line ) )
 				Endif
 
-			Else
-			
-'				If Not _buf.Empty And _buf.Top<>"<p>" Emit( "<p>" )
-				
 			Endif
 				
-'			Else 
-			
-'				If _buf.Empty Or _buf.Top="" Emit( "<p>" )
-			
-'				Emit( Escape( line ) )
-			
-'			Endif
-			
 		Wend
 		
 		Local html:=_buf.Join( "~n" )
@@ -459,12 +447,13 @@ Class MarkdownConvertor
 		Emit( "<pre class="+_cls+"><code class="+_cls+">\" )
 	
 		While Not AtEnd
-		
+			
 			line=NextLine()
-			If line.StartsWith( "```" ) Exit
+			Local tline:=line.Trim()
 			
-			Emit( EscapeHtml( line ) )
+			If tline.StartsWith( "```" ) Or tline.ToLower().StartsWith( "</pre>" ) Exit
 			
+			Emit( EscapeHtml( line ) )
 		Wend
 		
 		Emit( "</code></pre>" )