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

source code to HTML

By , 11 Aug 2005
 

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

About the Author

murakami
Japan Japan
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 12 Aug 2005
Article Copyright 2005 by murakami
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid