Needs Improvement

Colin Coller's Blog
Posts: 10 | Comments: 68 | TrackBacks: ?

November 30, 2004

CopySourceAsHtml (Updated)

I've released CopySourceAsHtml version 1.2.2 with changes suggested by Daniel Moth.

CopySourceAsHtml 1.2.2 Installer (287 KB) (built and tested on VS.NET 2003)
CopySourceAsHtml 1.2.2 Source (36 KB)

I've also set up a GotDotNet workspace for the project, in case anyone wants an older version of the tool.

CSAH now generates lighter HTML in all cases and much, much, much lighter HTML if word wrapping is disabled. For example, this block of code that previously weighed in at ~20KB now weighs in at ~10KB. That's good news if you're bandwidth-conscious.

I also fixed a few minor bugs that nobody reported.

Cheers,

Colin

11:34 PM | Colin

Comments

# RE: CopySourceAsHtml (Updated)

Very cool! I'll check it out once again. I love this tool!

12:56 AM | Haacked

# RE: CopySourceAsHtml (Updated)

Great tool! Have just started converting all my blog code with it.

Have posted a couple of suggestions on GotDotNet already, however just came an issue, would post in the workspaces but they are down again.

If you only copy a single method with XML comments and paste it into notepad the colours are mixed up, however pasting it directly into Word looks find.

The following code causes a problem:

///
///
/// Returns a value indicating whether the specified path is properly formatted.
///
///
///
/// A containing the path to check.
///
///
/// if is properly formatted; otherwise, .
///
public static bool IsPathValid(string path)
{
if (path == null || path.Trim().Length == 0)
return false;
try
{
Path.GetFullPath(path);
return true;
}
catch (ArgumentException)
{
}
catch (SecurityException)
{
}
catch (NotSupportedException)
{
}
catch (PathTooLongException)
{
}
return false;
}

04:36 AM | David M. Kean

# RE: CopySourceAsHtml (Updated)

David:

Thanks for the feedback!

Make sure you have "embed styles" checked. If you don't, CSAH will generate an inline stylesheet for every block you copy, and the names of the styles may conflict between blocks. For example, if you copy the XML comments above, the inline stylesheet will look like this:

.cf { font-family: Courier New; ... }
.cln { color: teal; }
.cb1 { color: gray; }
.cb2 { color: green; }

If you copy the method body above, the inline stylesheet will look like this:

.cf { font-family: Courier New; ... }
.cln { color: teal; }
.cb1 { color: blue; }

Note that the name cb1 is used for two different styles. If you paste both blocks into the same document, the browser will be left to resolve the conflict, and will most likely display one of the blocks incorrectly. The more blocks, the more potential conflict.

I'm thinking about keeping a history of which names have been used for which styles, so I don't give two different styles the same name, but for now all bloggers should have "embed styles" checked. :)

Colin

09:39 AM | Colin

# RE: CopySourceAsHtml (Updated)

First off, thanks for this really cool tool Colin!
A few thought I would like to share with you:

- Perhaps it might be an idea to cut bandwidth even more by using CSS to indent >= 4 space blocks. So that instead of      you can suffice with . This has the advantage of a few kilobytes less in large code segments, and a few nanosec shorter processing time in generating the code, :)
One disadvantage may be that the code can't be copy/pasted with spaces intact anymore. Therefor it might be only handy for where only display is needed, and not intended to be copied. (Although VS.NET autoformats it on paste anyway...) so making it an option might still be okay.

- I am using CSAH 1.2.2 now. As you said in your blog of version 1.2.1, CSAH would use the color setting of the IDE. Unfortunately this doesn't work for me, as I am using (like many others I assume) VisualAssistX. Check this page for an example of what I mean: http://android42.net/blogs/csahdemo.html
Is it maybe a good idea to support VisualAssistX as well? Or is this perhaps not possible?

Thanks for the great work!

Yves Janse

03:06 AM | Yves Janse