Create a class library
Add two key references
Using windowslive. Writer. API; using system. Windows. forms;
Using system. Web;
The first referenced DLL file is in the root directory where you install Windows Live writer.
The name is windowslive. Writer. API. dll.
Add a class file.ProgramUsed to process user insertsCode
Public static class contentprocessor {public static string processedcontent {Get; private set;} public static void process (string originalcontent) {processedcontent = (! String. isnullorempty (originalcontent )? String. format ("<fieldset style = \" background-color: # e0eff6; color: # 15428b \ "> <PRE >{0 }</PRE> </div> ", httputility. htmlencode (originalcontent): string. empty );}}
Add a Windows form,
The event added to the OK button is
Private void button#click (Object sender, eventargs e) {contentprocessor. process (this. textbox1.text); this. Close ();}
Contentprocessor. process (this. textbox1.text );
Is the handler called in the previous class file.
Add a class file
[Writerplugin ("plugin", "xland", description = "insert Code plugin", name = "xland", publisherurl = "http://www.cnblogs.com/liulun")] [insertablecontentsource ("insert code ", sidebartext = "insert Code")] public class myplugin: contentsource {public override dialogresult createcontent (iwin32window dialogowner, ref string content) {New processform (). showdialog (); content = Contentprocessor. processedcontent; Return (! String. isnullorempty (content )? Dialogresult. OK: dialogresult. No );}}
Among them, 7c371eef-e350-4aae-af28-91613a9137e3 is a guid.
Other information is the information of the plug-in live writer.
The first sentence in the function is to create a window (the window we just created)
The second sentence is to obtain the input data (the processed data)
The third sentence tells live writer that something needs to be inserted.
The content variable is in live writer, so it must be modified with ref.
After the installation is complete, you only need to put the generated DLL file in the plugins folder under the Live writer installation directory.
ThisArticleIt is written using this plug-in.
Paste a picture to see
Source codeDownload: livewriterplugin.rar
In addition:
I set this style in my blog
Pre {white-space: Pre-wrap;/* css-3 */white-space:-moz-Pre-wrap;/* Mozilla, since 1999 */white-space: -Pre-wrap;/* opera 4-6 */white-space:-o-Pre-wrap;/* opera 7 */} * html pre {word-wrap: break-word;/* Internet Explorer 5.5 + */white-space: normal;/* Internet Explorer 5.5 + */}
the specific setting method is, go to the background of your blog Park, select, and config, and use the CSS customization page.
This setting mainly prevents code from being too wide to break the page.