namespace CoderBlog.Plugin.SyntaxHighlighter
{
publicclass Languages
{
private Dictionary<
string,
string> m_Brushes =
new Dictionary<
string,
string>(StringComparer.OrdinalIgnoreCase);
///<summary> /// Constructor. When a Languages class is created, /// a list of predefined languages ("brushes") is created. ///</summary> public Languages()
{
InitializeBrushes();
}
///<summary> /// Returns if a programming language is supported by the formatter. /// If there is a brush for it, a language is supported. ///</summary> ///<param name="language">The programming language name to test.</param> ///<returns><c>true</c> if the provided language is supported, /// otherwise, <c>false.</c></returns> publicbool IsSupported(
string language)
{
if (
string.IsNullOrEmpty(language))
{
thrownew ArgumentNullException(
"language");
}
string key = language.Trim();
return m_Brushes.ContainsKey(key);
}
///<summary> /// Returns the brush CSS file for a programming language. ///</summary> ///<param name="language">The programming language name.</param> ///<returns>The name of a brush CSS file, or <c>null</c> /// if the language is not supported.</returns> publicstring GetStylesheetFile(
string language)
{
if (
string.IsNullOrEmpty(language))
{
thrownew ArgumentNullException(
"language");
}
///<summary> /// Adds a user-defined language brush to the set of supported languages. ///</summary> ///<param name="language">The name of the language, as given as the first word in a code block</param> ///<param name="stylesheetFile">Name of the additional language ("brush") javascript file /// within the syntax hightlighter directory.</param> publicvoid AddLanguage(
string language,
string stylesheetFile)
{
if (
string.IsNullOrEmpty(language))
{
thrownew ArgumentNullException(
"language");
}
if (
string.IsNullOrEmpty(stylesheetFile))
{
thrownew ArgumentNullException(
"stylesheetFile");
}
m_Brushes[language.ToLowerInvariant()] = stylesheetFile;
}
///<summary> /// Initializes the list of supported language names and associates them /// with a brush style sheet. ///</summary> privatevoid InitializeBrushes()
{
m_Brushes.Add(
"as3",
"shBrushAS3.js");
m_Brushes.Add(
"actionscript3",
"shBrushAS3.js");
m_Brushes.Add(
"bash",
"shBrushBash.js");
m_Brushes.Add(
"shell",
"shBrushBash.js");
m_Brushes.Add(
"cf",
"shBrushColdFusion.js");
m_Brushes.Add(
"coldfusion",
"shBrushColdFusion.js");
m_Brushes.Add(
"c-sharp",
"shBrushCSharp.js");
m_Brushes.Add(
"csharp",
"shBrushCSharp.js");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using CoderBlog.PluginFramework;
#region 扩展方法,以下注释我也不一一说明啦,英文都很简单,大家自己看看吧
///<summary> /// Appends the reference to a CSS style sheet to the formatted text. ///</summary> ///<param name="textBuilder"><see cref="StringBuilder"/> that creates the formatted text.</param> ///<param name="styleSheetName">File name of the style sheet.</param> protectedinternalvirtualvoid AppendStyleSheet(StringBuilder textBuilder,
string styleSheetName)
{
textBuilder.Append(
"<link href='");
textBuilder.Append(ClientScriptBaseUrl);
textBuilder.Append(
"styles/");
textBuilder.Append(styleSheetName);
textBuilder.Append(
"' rel='stylesheet' type='text/css'/>\n");
}
///<summary> /// Appends the reference to a client-side script to the formatted text. ///</summary> ///<param name="textBuilder"><see cref="StringBuilder"/> that creates the formatted text.</param> ///<param name="scriptName">File name of the script.</param> protectedinternalvirtualvoid AppendClientScript(StringBuilder textBuilder,
string scriptName)
{
textBuilder.Append(
"<script src='");
textBuilder.Append(ClientScriptBaseUrl);
textBuilder.Append(
"scripts/");
textBuilder.Append(scriptName);
textBuilder.Append(
"' type='text/javascript'></script>\n");
}
///<summary> /// Appends the reference to a programming language specific /// script ("brush") to the formatted text ///</summary> ///<param name="textBuilder"><see cref="StringBuilder"/> that creates the formatted text.</param> ///<param name="language">The language.</param> protectedinternalvirtualvoid AppendBrushScript(StringBuilder textBuilder,
string language)
{
string scriptFile = Languages.GetStylesheetFile(language);
AppendClientScript(textBuilder, scriptFile);
}
///<summary> /// Appends the reference to the theme-specific style sheet. ///</summary> ///<param name="textBuilder"><see cref="StringBuilder"/> that creates the formatted text.</param> protectedinternalvirtualvoid AppendThemeStylesheet(StringBuilder textBuilder)
{
string stylesheet =
string.Format(
"shTheme{0}.css", Theme);
AppendStyleSheet(textBuilder, stylesheet);
}
#endregion
#region IFormatterProvider Members
///<summary> /// Called by the postbar engine in order to format text. ///</summary> ///<param name="raw">The unformatted text.</param> ///<param name="context">Contextual information for the transformation - /// like the user name, HTTP context, or purpose of the formatter run.</param> ///<returns>Formatted text.</returns> ///<remarks> ///<para> /// This formatter detects blocks of source code. The first word within a source code /// block is considered a hint on in which language the block is - if this first word /// is one of the supported languages. ///</para> ///<para> /// Postbar formats code blocks with a "pre" tag - this is done in phase 1 of the transformation; /// this is why we run in phase 2. THe Syntax Highlighter scripts also use the "pre" tag, /// augmented with a CSS class that defines the language ("brush", as it cals it). /// Now all we need to do is:<br/> /// * Look for "pre" tags /// * Get the first word behind it. /// * If this first word is a suported language, use it; otherwise ignore and use the /// default language. /// * Add the CSS class for the brush. /// to the "pre" tag. /// * Da capo al fine. /// * Inject links to the Syntax Highlighter CSS and script files. Each language /// has its own CSS file; in order to make things more efficient we only add files /// that are actually needed because the language was found in a script block. ///</para> ///</remarks> publicvirtualstring Format(
string raw, ContextInfo context)
{
// Only format the post content if (context.FormatContext.CompareTo(FormattingContext.PostContent) !=
0)
return raw;
// Buckets for the remainders of unformatted text, and already formatted text. string sourceText = raw;
StringBuilder targetText =
new StringBuilder();
// Find any part of the unformatted text that is enclosed in in a "pre" tags. // ScrewTurn formats code blocks into preformatted HTML tags. string openingTag =
@"<pre>";
string closingTag =
@"</pre>";
Regex regex =
new Regex(openingTag +
".+?" + closingTag, RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match match = regex.Match(sourceText);
while (match.Success)
{
// Push the text before the found code block into the target text // without alteration if (match.Index >
0)
{
targetText.Append(sourceText.Substring(
0, match.Index));
}
// Remove the part before the found code block, and the code block, from the remaining // source text sourceText = sourceText.Substring(match.Index + match.Length);
// Get the content of the found code block string content = match.Value;
// The RegEx match still contains the opening and closing tags. Remove them so we get only the // text within the tag. int openingTagLen = openingTag.Length;
int closingTagLen = closingTag.Length;
int contentLen = content.Length - closingTagLen - openingTagLen;
content = content.Substring(openingTagLen, contentLen);
// Get the first word of the code block. If it matched one of the highlighter // languages, use it as a hint on how to format the code block and remove it from the document. var wordSeparators =
newchar[] {
'',
'\n',
'\r' };
string firstWord = content
.Split(wordSeparators, StringSplitOptions.RemoveEmptyEntries)
.FirstOrDefault();
// If a first word could be extracted (the block can as well be empty...), // and the language is supported, then... string language;
if (!
string.IsNullOrEmpty(firstWord) && Languages.IsSupported(firstWord))
{
// ... set the language for this block... language = firstWord;
// ... and remove the first word from the code block content. int firstWordIndex = content.IndexOf(firstWord);
content = content.Substring(firstWordIndex + firstWord.Length);
}
else {
// If no langauge could be found, use the default language. language = DefaultLanguage;
}
// Track the languages found on the page so we can include the correct set of script files. if (!foundLanguages.Contains(language))
{
foundLanguages.Add(language);
}
// Add an opening "pre" tag with a language ("brush") definition... targetText.AppendFormat(
"<pre class='brush: {0}'>\n",
language.ToLowerInvariant());
// ... the content... targetText.Append(content);
// ... and a closing tag. targetText.Append(
"</pre>");
// Get the next code block. match = regex.Match(sourceText);
}
// Append rest of source text to target. targetText.Append(sourceText);
// Return the formatted text. return targetText.ToString();
}
///<summary> /// Format the post title . /// the title is not modified by this plugin. ///</summary> ///<param name="title">The post title.</param> ///<param name="context">The context information.</param> ///<returns>The original title.</returns> publicstring FormatPostTitle(
string title, ContextInfo context)
{
return title;
}
///<summary> /// Format the page head, if any. ///</summary> ///<param name="head">The head content</param> ///<param name="context">The context information.</param> ///<returns>The formatted head</returns> publicstring FormatPageHead(
string head, ContextInfo context)
{
return head;
}
///<summary> /// Format the page foot, if any. /// Just return the js script registration in the head ///</summary> ///<param name="foot">The foot content</param> ///<param name="context">The context information.</param> ///<returns>The original foot</returns> publicstring FormatPageFoot(
string foot, ContextInfo context)
{
StringBuilder targetText =
new StringBuilder();
targetText.AppendLine(
"\n<!-- START GreenIcicle code syntax highlighter, modified by Winson for PostBar -->\n");
AppendStyleSheet(targetText,
"shCore.css");
AppendThemeStylesheet(targetText);
AppendClientScript(targetText,
"shCore.js");
foreach (var language
in foundLanguages)
{
AppendBrushScript(targetText, language);
}
// Add script that hooks up the Flash-based clipboard helper, and the activate the // syntax highlighter. targetText.Append(
"<script language='javascript'>\nSyntaxHighlighter.config.clipboardSwf = '");
targetText.Append(ClientScriptBaseUrl);
targetText.Append(
"scripts/clipboard.swf'\nSyntaxHighlighter.all();\n</script>");
targetText.AppendLine(
"\n<!-- END GreenIcicle code syntax highlighter, modified by Winson for PostBar -->\n");
foot += targetText.ToString();
return foot;
}
///<summary> /// Initializes the plugin. This is the very first method called on the /// class. ///</summary> ///<param name="host">Provides access to the wiki's API</param> ///<param name="config">Configuration string for the plugin.</param> publicvoid Init(IHost host,
string config)
{
this.host = host;
ConfigurationString = config;
}
///<summary> /// Shuts the plugin down. Very last method called on the clas. ///</summary> publicvoid Shutdown()
{
// Nothing to do to shut the formatter down }
///<summary> /// Plugin information ///</summary> publicvirtual PluginInfo Information
{
get {
return info;
}
}
///<summary> /// HTML text displayed as help for configuring the plugin ///</summary> publicvirtualstring ConfigHelpHtml
{
get {
return@" <div> <b>选项:</b><br/> <ul> <li><b>ScriptUrl</b> 加载JS和CSS文件的路径,可以是网络地址。</li> <li><b>Theme</b> 语法高亮插件所使用的主题,不设置将使用默认主题。</li> <li><b>DefaultLang</b> 默认语言,即当不设置高亮语言时,所有默认输出的语言类型,如不设置此项,默认语言为 text</li> <li><b>CustomLang</b> 添加自定义语言,指定其对应的CSS文件</li> </ul> <b>例子:</b><br/> 加载JS和CSS文件的路径为本地路径,使用 Django 主题,默认语言为 C#,添加自定义语言为 MyNewLang1 和 MyNewLang2 并指定其JS语法文件为 MyNewlang1.js 和 MyNewlang2.js,两者间使用分号:隔开,如要添加多个自定义语言,需使用|以分隔开, 配置如下:<br> ScriptUrl=~/Plugins/SyntaxHighlighter/;<br> Theme=Django;<br> DefaultLang=csharp;<br> CustomLang=MyNewLang1:MyNewlang1.js|MyNewLang2:MyNewlang2.js; </div> ";
}
}
继承 extends 多态
继承是面向对象最经常使用的特征之一:继承语法是通过继承发、基类的域和方法 //继承就是从现有的类中生成一个新的类,这个新类拥有现有类的所有extends是使用继承的关键字:
在A类中定义属性和方法;
class A{
//定义属性
int age;
//定义方法
public void go
hive DDL语法汇总
1、对表重命名
hive> ALTER TABLE table_name RENAME TO new_table_name;
2、修改表备注
hive> ALTER TABLE table_name SET TBLPROPERTIES ('comment' = new_comm