Simple Windows Live writer code plug-in (including source code)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.