Click here to Skip to main content
Click here to Skip to main content

source code to HTML

, 11 Aug 2005
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

murakami

Japan Japan
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 12 Aug 2005
Article Copyright 2005 by murakami
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid