I've been struggling on every post to get source code to look good with my blog style. Today I found a decent solution as a live writer plugin: Insert Source Code Snippet. It still requires me to muck with the html a bit though. I may have to make this blog boring and white...
Anyway, to try it out, here's an extension method I recently cooked up to help us AntiXss encode a list of strings to a JSON array.
using System; using System.Collections.Generic; using System.Text; using Microsoft.Security.Application; namespace Microsoft { /// <summary> /// A set of extension methods to make encoding untrusted output easier /// </summary> public static class EncodingExtensions { /// <summary> /// Encodes a list of strings into JavaScript array notation, /// with full AntXss encoding of each string in the array /// </summary> /// <param name="strings">The strings to encode</param> /// <returns>A JavaScript array of strings</returns> public static string JavaScriptEncode(this List<string> strings) { if (strings == null) { throw new ArgumentNullException("strings"); } StringBuilder builder = new StringBuilder(); builder.Append("["); if (strings.Count > 0) { for (int i = 0; i < strings.Count - 1; i++) { builder.AppendFormat("{0},", AntiXss.JavaScriptEncode(strings[i])); } builder.Append(AntiXss.JavaScriptEncode(strings[strings.Count - 1])); } builder.Append("]"); return builder.ToString(); } } }