string url = "<a href=\"" + someObj.getUrl() + "\" target=\"_blank\">";
 
// single line comments
// second single line
override protected void OnLoad(EventArgs e)
{
	if(Attributes["class"] != null)
	{
		//_year.CssClass = _month.CssClass = _day.CssClass = Attributes["class"];
	}
	base.OnLoad(e);
}

사용하기

SyntaxHighlighter는 개발자가 자신의 웹사이트에 코드를 표시하는데 도움이 됩니다.
위에 보이십니까?!

 [ SyntaxHighlighter 다운로드 페이지로 이동 ]

설치하기 

SyntaxHighlighter 2.1 (현재 최신버전) 

2.1버전에서의 새로운 기능을 소개합니다. SyntaxHighlighter 2.1버전에서는 전통적인 방식인 <pre /> 태그 외에도, <script type="syntaxhighlighter" /> 에 class 속성을 가지는 특별한 형식이 추가 되었습니다. 이 형식은 CSS style 속성과 동일합니다. 단지, 필수 매개변수인 brush 의 값이 필요합니다.

다음에 예제가 있습니다.(CDATA 태그가 반드시 기재되어야 합니다.):

<script type="syntaxhighlighter" class="brush: js"><![CDATA[
    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        // it works!
    }
]]></script>

위의 코드가 다음과 같이 렌더링 됩니다 :

    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        // it works!
    }

이 방법의 장점은 당신이 즐겨 사용하는 텍스트 에디터에서 복사/붙여넣기 방법으로 코드를 CDATA 내부에 붙여넣기만 하면 더이상 작업할 필요없이 바로 적용됩니다.

최소설치 및 실행 방법 

이런식으로 최소설치 할 수 있습니다.(사용자의 디렉토리 구조에 따라 다를수 있습니다.):

<!-- Include required JS files -->
<script type="text/javascript" src="syntaxhighlighter/src/shCore.js"></script>
<!-- At least one brush, here we choose JS. You need to include a brush for every language you want to highlight -->
<script type="text/javascript" src="syntaxhighlighter/scripts/shBrushJScript.js"></script>
 
<!-- Include *at least* the core style and default theme -->
<link href="syntaxhighlighter/styles/shCore.css" rel="stylesheet" type="text/css" />
<link href="syntaxhighlighter/styles/shThemeDefault.css" rel="stylesheet" type="text/css" />

highlight 콘텐츠가 더 필요하지만 이것만으로도 대부분의 코드가 커버 됩니다.

마지막으로 highlighter를 실행하기 위해서 다음 JS를 사용자 페이지에 포함시킵니다.

<script type="text/javascript">
     SyntaxHighlighter.all()
</script>

SyntaxHighlighter 2.0

SyntaxHighlighter는 특별한 형식의 class 속성을 가지고 있는 <pre /> 태그를 찾습니다. 이 속성의 형식은 CSS style 의 속성과 동일합니다. 단지, brush 변수 값으로 brush alias값이 필요합니다.

아래 예제를 살펴봅겠습니다:

<pre class="brush: js">
    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        // it works!
    }
</pre>

다음과 같이 렌더링 됩니다.:

    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        // it works!
    }

Escaping `<` and `>`

Because the browsers interpret <anything ... as opening tags, this causes a very common issue of invalid rendering of the code. It is impossible to use left angle bracket "<" characters unescaped in 2.0. Please make sure to replace all instances of `<` with `&lt;` before pasting the code on the page. This will insure correct rendering. Alternatively use <script/> introduced in 2.1 if you can.

If you are looking for instructions on how to set up SyntaxHighlighter, please refer to the installation page. SyntaxHighlighter 2.0 can be configured in 3 different ways.



SyntaxHighlighter 환경설정

SyntaxHighlighter.config has configuration values that are common to all highlighted elements on the page and don't make much sense within context of a single highlighted element. Below are these values:

Name Value Description
bloggerMode false Blogger integration. If you are hosting on blogger.com, you must turn this on.
clipboardSwf null Facilitates clipboard functionality. It needs to be enabled by specifying location of the "clipboard.swf" file via the clipboardSwf configuration value. If the value isn't specified, clipboard icon won't show.
strings Object Allows you to change default messages, see here for more details.
stripBrs false If your software adds <br /> tags at the end of each line, this option allows you to ignore those.
toolbarItemWidth 16 Width of an icon in the toolbar. If you are customizing the toolbar and need to change width of the icons, you have to change toolbarItemWidth configuration property.
toolbarItemHeight 16 Height of an icon in the toolbar.
tagName "pre" Facilitates using a different tag.

Example

	SyntaxHighlighter.config.bloggerMode = true;
	SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
	...
	SyntaxHighlighter.all();



SyntaxHighlighter 기본설정 

SyntaxHighlighter.defaults holds all default values for each highlighted element on the page. These options are local to each highlighter element and could be changed individually via parameters described in the next section. The list below represent a full list of options that SyntaxHighlighter 2.0 supports:

Name Value Description
auto-links true Allows you to turn detection of links in the highlighted element on and off. If the option is turned off, URLs won't be clickable. Click here for a demo.
class-name '' Allows you to add a custom class (or multiple classes) to every highlighter element that will be created on the page. Click here for a demo.
collapse false Allows you to force highlighted elements on the page to be collapsed by default. Click here for a demo.
first-line 1 Allows you to change the first (starting) line number. Click here for a demo.
gutter true Allows you to turn gutter with line numbers on and off. Click here for a demo.
highlight null Allows you to highlight one or more lines to focus user's attention. When specifying as a parameter, you have to pass an array looking value, like [1, 2, 3] or just an number for a single line.

If you are changing SyntaxHighlighter.defaults['highlight'], you can pass a number or an array of numbers. Click here for a demo.

html-script false Allows you to highlight a mixture of HTML/XML code and a script which is very common in web development. Setting this value to true requires that you have shBrushXml.js loaded and that the brush you are using supports this feature. Click here for a demo.
light false Allows you to disable toolbar and gutter with a single property. Click here for a demo.
smart-tabs true Allows you to turn smart tabs feature on and off. Click here for a demo.
tab-size 4 Allows you to adjust tab size. Click here for a demo.
toolbar true Toggles toolbar on/off. Click here for a demo.
wrap-lines true Allows you to turn line wrapping feature on and off. Click here for a demo.

Example

	SyntaxHighlighter.defaults['gutter'] = false;
	SyntaxHighlighter.defaults['smart-tabs'] = false;
	...
	SyntaxHighlighter.all();



Parameters

Parameters allow you to customize a single highlighted element to your liking. Key/value pairs are specified in the format similar to CSS, but instead of the style node attribute, they go together with the brush declaration into the class attribute.

Example

<pre class="brush: js; ruler: true; first-line: 10; highlight: [2, 4, 6]">...</pre>

In such fashion, you can change any default value from the SyntaxHighlighter.defaults.

About

SyntaxHighlighter uses separate syntax files called brushes to define its highlighting functionality.

Brush name Brush aliases File name
ActionScript3 as3, actionscript3 shBrushAS3.js
Bash/shell bash, shell shBrushBash.js
C# c-sharp, csharp shBrushCSharp.js
C++ cpp, c shBrushCpp.js
CSS css shBrushCss.js
Delphi delphi, pas, pascal shBrushDelphi.js
Diff diff, patch shBrushDiff.js
Groovy groovy shBrushGroovy.js
JavaScript js, jscript, javascript shBrushJScript.js
Java java shBrushJava.js
JavaFX jfx, javafx shBrushJavaFX.js
Perl perl, pl shBrushPerl.js
PHP php shBrushPhp.js
Plain Text plain, text shBrushPlain.js
PowerShell ps, powershell shBrushPowerShell.js
Python py, python shBrushPython.js
Ruby rails, ror, ruby shBrushRuby.js
Scala scala shBrushScala.js
SQL sql shBrushSql.js
Visual Basic vb, vbnet shBrushVb.js
XML xml, xhtml, xslt, html, xhtml shBrushXml.js

'유용한 팁' 카테고리의 다른 글

아름다운 CSS 타이포그라피 10선  (0) 2009.12.05
Posted by 피곤키오
,