Click here to Skip to main content
15,886,724 members
Articles / Programming Languages / C++
Article

source code to HTML

Rate me:
Please Sign up or sign in to vote.
1.33/5 (15 votes)
11 Aug 2005 21K   9  
This macro convert cpp source code to HTML code

Introduction

I sometimes need to post my cpp source code to the BBS. Because the BBS removes all html tag and encloses pre tag. I need to do following routine work

  • duplicate source code of the selected area 
  • replace html escape charactors ("<", ">", "&")
  • untabify (replace TAB to Equivalent spaces)

So I write a macro for VisualStudio.NET. This is simple but convenient tool for me.

Usage

It's very easy. Select the source code area you want to convert and call this macro. Then converted code was pasted to clipboard.

Code

    Sub Src2Html()
        DTE.UndoContext.Open("ToHTML")
        Try
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocumentSelection
            DTE.Find.MatchCase = True
            DTE.Find.MatchWholeWord = False
            DTE.Find.MatchInHiddenText = False
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
            DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
            DTE.Find.Action = vsFindAction.vsFindActionReplaceAll

            DTE.Find.FindWhat = "&"
            DTE.Find.ReplaceWith = "&amp;"
            DTE.Find.Execute()

            DTE.Find.FindWhat = "<"
            DTE.Find.ReplaceWith = "&lt;"
            DTE.Find.Execute()

            DTE.Find.FindWhat = ">"
            DTE.Find.ReplaceWith = "&gt;"
            DTE.Find.Execute()

            DTE.ActiveDocument.Selection.Untabify()
            DTE.ActiveDocument.Selection.Copy()
        Finally
            DTE.UndoContext.Close()
            DTE.ActiveDocument.Undo()
        End Try

    End Sub

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Japan Japan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --