User Tools

Site Tools


snippets:clipboard_cf

CF_HTML HTML Clipboard format 

Code to convert a standard valid HTML string into CF_HTML, the clipboard representation of HTML

        public static string ConvertToHtmlFragment (string fragment)
        {
            const String MARKER_BLOCK =
                "Version:1.0\r\n" +
                "StartHTML:{0,8}\r\n" +
                "EndHTML:{1,8}\r\n" +
                "StartFragment:{2,8}\r\n" +
                "EndFragment:{3,8}\r\n" +
                "StartSelection:{2,8}\r\n" +
                "EndSelection:{3,8}\r\n" +
                "{4}";
            int prefixLength = String.Format (MARKER_BLOCK, 0, 0, 0, 0, "").Length;
            const String DEFAULT_HTML_BODY =
                "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" +
                "<HTML><HEAD></HEAD><BODY><!--StartFragment-->{0}<!--EndFragment--></BODY></HTML>";
            string html = String.Format (DEFAULT_HTML_BODY, fragment);
            int startFragment = prefixLength + html.IndexOf (fragment);
            int endFragment = startFragment + fragment.Length;
            return String.Format (MARKER_BLOCK, prefixLength, prefixLength + html.Length, startFragment, endFragment, html);
        }
snippets/clipboard_cf.txt · Last modified: 2015/07/26 13:23 by jaap.dehaan