{"id":18,"date":"2018-05-22T08:26:00","date_gmt":"2018-05-22T08:26:00","guid":{"rendered":"\/colin\/morethanfour\/post\/Windows-Live-Writer-Code-Snippet-and-embedded-styles"},"modified":"2018-05-22T08:26:00","modified_gmt":"2018-05-22T08:26:00","slug":"windows-live-writer-code-snippet-and-embedded-styles","status":"publish","type":"post","link":"https:\/\/spacefold.com\/colin\/morethanfour\/2018\/05\/22\/windows-live-writer-code-snippet-and-embedded-styles\/","title":{"rendered":"Windows Live Writer, Code Snippet, and embedded styles"},"content":{"rendered":"<p>I&#8217;m a long-time fan of Windows Live Writer, which I can&#8217;t link you to because it is no longer available from Microsoft. (Search for Windows Live Essentials 2012 and maybe you&#8217;ll find something.) <\/p>\n<p>Thankfully the project was moved into open-source and a variant of it is available today as Open Live Writer. That&#8217;s cool &#8211; but as of this writing, it does not support plug-ins.<\/p>\n<p>Alas, I rely on a plug-in called &#8220;Code Snippet&#8221; by Leo Vildosola. So I&#8217;m sticking with the original Windows Live Writer for now.<\/p>\n<h3>Embittered Styles<\/h3>\n<p>Code Snippet is great for posting source code and similar monospace text blocks into the blog page. It also has the default option to emit embedded styles into the generated HTML code. This makes for a kind of nasty lowest-common denominator format, like this:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippetNot\" style=\"border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\"><span style=\"color: #006080\">&lt;<\/span><span style=\"color: #0000ff\">pre<\/span> id=\"codeSnippet\" <span style=\"color: #0000ff\">style<\/span>=\"<span style=\"color: #0000ff\">border<\/span>-<span style=\"color: #0000ff\">top<\/span>-<span style=\"color: #0000ff\">style<\/span>: <span style=\"color: #006080\">none;<\/span> <span style=\"color: #0000ff\">font-size<\/span>: <span style=\"color: #006080\">8pt;<\/span> <span style=\"color: #0000ff\">overflow<\/span>: <span style=\"color: #006080\">visible;<\/span> <br><span style=\"color: #0000ff\">border<\/span>-<span style=\"color: #0000ff\">left<\/span>-<span style=\"color: #0000ff\">style<\/span>: <span style=\"color: #006080\">none;<\/span> <span style=\"color: #0000ff\">font-family<\/span>: <span style=\"color: #006080\">'Courier New', courier, monospace;<\/span> <span style=\"color: #0000ff\">width<\/span>: <span style=\"color: #006080\">100%;<\/span> <br><span style=\"color: #0000ff\">border<\/span>-<span style=\"color: #0000ff\">bottom<\/span>-<span style=\"color: #0000ff\">style<\/span>: <span style=\"color: #006080\">none;<\/span> <span style=\"color: #0000ff\">color<\/span>: <span style=\"color: #006080\">black;<\/span> <span style=\"color: #0000ff\">padding<\/span>-<span style=\"color: #0000ff\">bottom<\/span>: <span style=\"color: #006080\">0px;<\/span> <span style=\"color: #0000ff\">direction<\/span>: <span style=\"color: #006080\">ltr;<\/span> <br><span style=\"color: #0000ff\">text-align<\/span>: <span style=\"color: #006080\">left;<\/span> <span style=\"color: #0000ff\">padding<\/span>-<span style=\"color: #0000ff\">top<\/span>: <span style=\"color: #006080\">0px;<\/span> <span style=\"color: #0000ff\">border<\/span>-<span style=\"color: #0000ff\">right<\/span>-<span style=\"color: #0000ff\">style<\/span>: <span style=\"color: #006080\">none;<\/span> <span style=\"color: #0000ff\">padding<\/span>-<span style=\"color: #0000ff\">left<\/span>: <span style=\"color: #006080\">0px;<\/span> <br><span style=\"color: #0000ff\">margin<\/span>: <span style=\"color: #006080\">0em;<\/span> <span style=\"color: #0000ff\">line-height<\/span>: <span style=\"color: #006080\">12pt;<\/span> <span style=\"color: #0000ff\">padding<\/span>-<span style=\"color: #0000ff\">right<\/span>: <span style=\"color: #006080\">0px;<\/span> <span style=\"color: #0000ff\">background-color<\/span>: #f4f4f4\"<span style=\"color: #006080\">&gt;<\/span><\/pre>\n<p><\/div>\n<p>If you&#8217;re not paying attention, you can end up with a lot of blog posts with these &#8220;embittered&#8221; styles and end up with serviceable but not necessarily attractive text blocks. (<em>raises hand<\/em>).<\/p>\n<p>This option can be switched off when authoring new blog posts. See that &#8220;Embed Styles&#8221; check-button in the UI?<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"float: none; margin-left: auto; display: block; margin-right: auto\" alt=\"image\" src=\"http:\/\/www.spacefold.com\/colin\/morethanfour\/wp-content\/uploads\/image_8.png\" width=\"467\" height=\"79\">If you un-select that option, you get this generated instead:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippetNot\" class=\"csharpcode\"><span class=\"kwrd\">&lt;<\/span><span class=\"html\">pre<\/span> <span class=\"attr\">id<\/span><span class=\"kwrd\">=\"codeSnippet\"<\/span> <span class=\"attr\">class<\/span><span class=\"kwrd\">=\"csharpcode\"<\/span><span class=\"kwrd\">&gt;<\/span>This is a test without embedded styling<span class=\"kwrd\">&lt;\/<\/span><span class=\"html\">pre<\/span><span class=\"kwrd\">&gt;<\/span><\/pre>\n<\/div>\n<p>That&#8217;s quite a difference.<\/p>\n<p>Now we get a CLASS attribute instead of the embedded styles, so if we want to improve upon the basic default &lt;pre&gt; tag style, we&#8217;ll obviously need to add a style to our CSS.<\/p>\n<p>Note: no matter what language\/syntax you choose in Code Snippet&#8217;s Language dropdown list, the emitted CLASS value will always be &#8220;csharpcode&#8221;. This could be confusing because you might not be pasting C# code into the snippet, but the CSS class doesn&#8217;t appear to be related.<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" class=\"csharpcode\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"float: none; margin-left: auto; display: block; margin-right: auto\" alt=\"image\" src=\"http:\/\/www.spacefold.com\/colin\/morethanfour\/wp-content\/uploads\/image_9.png\" width=\"618\" height=\"193\"><\/pre>\n<p><\/div>\n<p>OK, we can definitely live with this, and add a style directive to our CSS. But what about all those previous blog posts with text blocks with embedded styles? <\/p>\n<h3>This is !important<\/h3>\n<p>Up until today I always thought that embedded styles trumped CSS, but it turns out there is a qualifier you can add to CSS that forces modern web browsers to use the CSS styles preferentially, even for embedded styles.<\/p>\n<p>That qualifier is &#8220;!important&#8221;.<\/p>\n<p>Now I can beautify my historical blog posts by adding the following to my blog theme&#8217;s style.css:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\" style=\"border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\"><span style=\"color: #008000\">\/* Windows Live Writer - Code Snippet - Fix for emitted embedded styles *\/<\/span><br>#codeSnippet {<br>  <span style=\"color: #0000ff\">background-color<\/span>: aliceblue <span style=\"color: #006080\">!important;<\/span><br>  <span style=\"color: #0000ff\">font-family<\/span>: \"Droid Sans Mono\", Consolas, courier, monospace <span style=\"color: #006080\">!important;<\/span><br>}<\/pre>\n<p><\/div>\n<p>Awesome. <\/p>\n<p><div>References<\/div>\n<ul>\n<li><a title=\"http:\/\/openlivewriter.org\/\" href=\"http:\/\/openlivewriter.org\/\">http:\/\/openlivewriter.org\/<\/a>\n<li><a title=\"http:\/\/lvildosola.blogspot.com\/2009\/03\/code-snippet-plugin-for-windows-live.html\" href=\"http:\/\/lvildosola.blogspot.com\/2009\/03\/code-snippet-plugin-for-windows-live.html\">http:\/\/lvildosola.blogspot.com\/2009\/03\/code-snippet-plugin-for-windows-live.html<\/a>\n<li><a title=\"http:\/\/www.hardcodet.net\/2009\/09\/live-writer-plugins-to-format-content-through-css-classes\" href=\"http:\/\/www.hardcodet.net\/2009\/09\/live-writer-plugins-to-format-content-through-css-classes\">http:\/\/www.hardcodet.net\/2009\/09\/live-writer-plugins-to-format-content-through-css-classes<\/a>\n<li><a title=\"https:\/\/www.w3schools.com\/cssref\/sel_id.asp\" href=\"https:\/\/www.w3schools.com\/cssref\/sel_id.asp\">https:\/\/www.w3schools.com\/cssref\/sel_id.asp<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a long-time fan of Windows Live Writer, which I can&#8217;t link you to because it is no longer available from Microsoft. (Search for Windows Live Essentials 2012 and maybe you&#8217;ll find something.) Thankfully the project was moved into open-source and a variant of it is available today as Open Live Writer. That&#8217;s cool &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-blog","category-blogengine-net","post-preview"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/colin\/morethanfour\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}