If I'm going to have a blog about coding I'll probably want to post source code now and then. But I couldn't find a VB.NET source -> HTML formatter anywhere, so I'm writing a little online utility to facilitate a relatively painless/intuitive "copy & paste" from the IDE into HTML for posting/blogging.
It's still beta-ish, just worked on it for an hour or so last night. Here's a sample of it's output, it's my current XNA game's Draw method, copied & pasted from the IDE into the processor, then from the processor into this blog's HTML editor:
Protected Overrides Sub Draw(ByVal gameTime As Microsoft.Xna.Framework.GameTime)
XNALib.GraphicsDeviceManager.GraphicsDevice.Clear(ClearOptions.Target, Me.objFrameColor, 1.0F, 0)
ScreenManager.Root.Draw(gameTime)
MyBase.Draw(gameTime)
XNALib.RenderDebugOptions()
'calculate fps data
Me.intFrames += 1
Me.objOneSecond += gameTime.ElapsedGameTime
'update this information every [gametime] elapsed second
If Me.objOneSecond.TotalSeconds >= 1 Then
Me.strActualFPS = Math.Round((Me.intFrames / Me.objOneSecond.TotalSeconds) * Me.objOneSecond.TotalSeconds, 1).ToString
Me.objOneSecond -= Me.objOneSecond
Me.intFrames = 0
End If
If XNALib.ShowFPS Then
'render
XNALib.SpriteDrawer.Begin()
XNALib.SpriteDrawer.DrawString(XNALib.Fonts("dialog"), Me.strActualFPS & " fps", Vector2.One, New Color(0, 0, 0, 175))
XNALib.SpriteDrawer.DrawString(XNALib.Fonts("dialog"), Me.strActualFPS & " fps", Vector2.Zero, Color.Red)
XNALib.SpriteDrawer.End()
End If
End Sub
XNALib.GraphicsDeviceManager.GraphicsDevice.Clear(ClearOptions.Target, Me.objFrameColor, 1.0F, 0)
ScreenManager.Root.Draw(gameTime)
MyBase.Draw(gameTime)
XNALib.RenderDebugOptions()
'calculate fps data
Me.intFrames += 1
Me.objOneSecond += gameTime.ElapsedGameTime
'update this information every [gametime] elapsed second
If Me.objOneSecond.TotalSeconds >= 1 Then
Me.strActualFPS = Math.Round((Me.intFrames / Me.objOneSecond.TotalSeconds) * Me.objOneSecond.TotalSeconds, 1).ToString
Me.objOneSecond -= Me.objOneSecond
Me.intFrames = 0
End If
If XNALib.ShowFPS Then
'render
XNALib.SpriteDrawer.Begin()
XNALib.SpriteDrawer.DrawString(XNALib.Fonts("dialog"), Me.strActualFPS & " fps", Vector2.One, New Color(0, 0, 0, 175))
XNALib.SpriteDrawer.DrawString(XNALib.Fonts("dialog"), Me.strActualFPS & " fps", Vector2.Zero, Color.Red)
XNALib.SpriteDrawer.End()
End If
End Sub
Not half bad, considering I was drinking and watching TV while I wrote it. Basically it just sets the font and the spaces to be non-breaking, re-colors keywords, comments and literal strings to the default Visual Studio 2005 IDE colors. No biggie, but oddly enough I couldn't find a (free) tool that does this anywhere online.
It's just about good as-is, before I "release" it I do need to teach it the difference between keywords and properties (i.e., MyClass.End isn't quite right, which you can see did in fact happen on the 3rd to last line in the above sample).
And before I put it out there I want to add some quick options, like whether or not to restrict the dimensions of the output div container, whether or not the container scrolls, and maybe even toss in BBCode support.
Basic doesn't really have that many tokenization characters, maybe half a dozen or so and that's it. So this was pretty easy to tackle. I'm not a C# programmer and I dunno how how many tokenization chars they have, but if it's not too crazy I could add C# support.
The utility won't beautify your code like the IDE does, it just recovers formatting lost in the copy & paste process from the IDE to the web using whatever you paste into it verbatim.
0 comments:
Post a Comment