C# 클래스 Loyc.Syntax.Les.Les3PrettyPrinter

A variant of Les3Printer that adds syntax highlighting in one of three ways: as console output, as HTML output, or as LesColorCode control codes.
Create an instance by invoking the constructor, then call PrintToConsole for console output, PrintToHtml for HTML output, or Les3Printer.Print(IEnumerable{ILNode}) for just control codes.
상속: Les3Printer
파일 보기 프로젝트 열기: qwertie/ecsharp 1 사용 예제들

공개 메소드들

메소드 설명
GetDefaultCssClassTable ( ) : string[]

The lookup table of strings for control codes (LesColorCode values) to HTML classes.

For example, GetDefaultCssClassTable()[(int)LesColorCode.Number] indicates the default CSS class to use for numbers. If the entry for a given code is null, no span element is emitted, which shortens the output. The default class names are shared with the Pygments syntax highlighting system. A list of the CSS classes available in Pygments is available at this link. Only a small subset of these classes are used in this table. Here is some suitable CSS:

 .highlight { background-color: #f8f8f8; color: #111; } .highlight .c  { color: #5A5; } /* Comment */ .highlight .n  { color: #111; } /* Name (omitted by default) */ .highlight .m  { color: #909; } /* Number */ .highlight .s  { color: #B44; } /* String */ .highlight .l  { color: #B04; } /* Literal (other) */ .highlight .kc { color: #41F; } /* Keyword.Constant */ .highlight .o  { color: #940; } /* Operator */ .highlight .p  { color: #111; } /* Punctuation (omitted by default) */ .highlight .kp { color: #33A; } /* Keyword.Pseudo (@attribute) */ .highlight .nb { color: #007; } /* Name.Builtin (#specialId) */ .highlight .k  { color: #11F; } /* Keyword (.dotId) */ .highlight .x  { color: #D00; } /* Other */ .highlight .pi { color: #B50; } /* Parenthesis Inner (()) */ 
Note: LesTokenCode.Opener and LesTokenCode.Closer are handled specially. An opener and its matching closer (e.g. '(' and ')') are always given the same color, but nested parens/brackets are given alternating colors (CSS classes), with the entry for LesTokenCode.Opener used for outer parens and the entry for LesTokenCode.Closer used for inner parens. The default class name is "pi" for inner parentheses; no class name is used for outer parens. "pi" is not a standard name, so if you're using a standard Pygment stylesheet you should add an extra line, e.g.
 .highlight .p { color: #111; } /* Punctuation (includes , ; { }) */ .highlight .pi { color: #B50; } /* Parenthesis Inner */ 
Les3PrettyPrinter ( IMessageSink sink = null, ILNodePrinterOptions options = null ) : System

Creates an instance of this class, which produces plain LES augmented with control codes.

Les3PrettyPrinter ( StringBuilder target, IMessageSink sink, ILNodePrinterOptions options ) : System

Creates an instance of this class, which produces plain LES augmented with control codes.

PrintToConsole ( IEnumerable nodes, bool endWithNewline = true ) : void
PrintToConsole ( ILNode node, bool endWithNewline = true ) : void
PrintToConsoleCore ( StringBuilder input, bool endWithNewline = true ) : void
PrintToHtml ( IEnumerable nodes, StringBuilder output = null, bool addPreCode = true ) : StringBuilder
PrintToHtml ( IEnumerable nodes, StringBuilder output = null, bool addPreCode = true, IMessageSink sink = null, ILNodePrinterOptions options = null ) : StringBuilder

Prints an LNode as LESv3 with HTML syntax highlighting elements.

PrintToHtml ( ILNode node, StringBuilder output = null, bool addPreCode = true ) : StringBuilder
PrintToHtmlCore ( StringBuilder input, StringBuilder output = null, bool addPreCode = true, string newline = "\n", string colorCodesToCssClasses = null ) : StringBuilder

Converts a StringBuilder with LesColorCode control codes to HTML with Pygments CSS class codes.

보호된 메소드들

메소드 설명
ColorCodeForId ( Symbol name ) : LesColorCode
StartToken ( LesColorCode kind ) : void

메소드 상세

ColorCodeForId() 보호된 메소드

protected ColorCodeForId ( Symbol name ) : LesColorCode
name Symbol
리턴 LesColorCode

GetDefaultCssClassTable() 공개 정적인 메소드

The lookup table of strings for control codes (LesColorCode values) to HTML classes.
For example, GetDefaultCssClassTable()[(int)LesColorCode.Number] indicates the default CSS class to use for numbers. If the entry for a given code is null, no span element is emitted, which shortens the output. The default class names are shared with the Pygments syntax highlighting system. A list of the CSS classes available in Pygments is available at this link. Only a small subset of these classes are used in this table. Here is some suitable CSS:
 .highlight { background-color: #f8f8f8; color: #111; } .highlight .c  { color: #5A5; } /* Comment */ .highlight .n  { color: #111; } /* Name (omitted by default) */ .highlight .m  { color: #909; } /* Number */ .highlight .s  { color: #B44; } /* String */ .highlight .l  { color: #B04; } /* Literal (other) */ .highlight .kc { color: #41F; } /* Keyword.Constant */ .highlight .o  { color: #940; } /* Operator */ .highlight .p  { color: #111; } /* Punctuation (omitted by default) */ .highlight .kp { color: #33A; } /* Keyword.Pseudo (@attribute) */ .highlight .nb { color: #007; } /* Name.Builtin (#specialId) */ .highlight .k  { color: #11F; } /* Keyword (.dotId) */ .highlight .x  { color: #D00; } /* Other */ .highlight .pi { color: #B50; } /* Parenthesis Inner (()) */ 
Note: LesTokenCode.Opener and LesTokenCode.Closer are handled specially. An opener and its matching closer (e.g. '(' and ')') are always given the same color, but nested parens/brackets are given alternating colors (CSS classes), with the entry for LesTokenCode.Opener used for outer parens and the entry for LesTokenCode.Closer used for inner parens. The default class name is "pi" for inner parentheses; no class name is used for outer parens. "pi" is not a standard name, so if you're using a standard Pygment stylesheet you should add an extra line, e.g.
 .highlight .p { color: #111; } /* Punctuation (includes , ; { }) */ .highlight .pi { color: #B50; } /* Parenthesis Inner */ 
public static GetDefaultCssClassTable ( ) : string[]
리턴 string[]

Les3PrettyPrinter() 공개 메소드

Creates an instance of this class, which produces plain LES augmented with control codes.
public Les3PrettyPrinter ( IMessageSink sink = null, ILNodePrinterOptions options = null ) : System
sink IMessageSink
options ILNodePrinterOptions
리턴 System

Les3PrettyPrinter() 공개 메소드

Creates an instance of this class, which produces plain LES augmented with control codes.
public Les3PrettyPrinter ( StringBuilder target, IMessageSink sink, ILNodePrinterOptions options ) : System
target StringBuilder
sink IMessageSink
options ILNodePrinterOptions
리턴 System

PrintToConsole() 공개 메소드

public PrintToConsole ( IEnumerable nodes, bool endWithNewline = true ) : void
nodes IEnumerable
endWithNewline bool
리턴 void

PrintToConsole() 공개 메소드

public PrintToConsole ( ILNode node, bool endWithNewline = true ) : void
node ILNode
endWithNewline bool
리턴 void

PrintToConsoleCore() 공개 정적인 메소드

public static PrintToConsoleCore ( StringBuilder input, bool endWithNewline = true ) : void
input StringBuilder
endWithNewline bool
리턴 void

PrintToHtml() 공개 메소드

public PrintToHtml ( IEnumerable nodes, StringBuilder output = null, bool addPreCode = true ) : StringBuilder
nodes IEnumerable
output StringBuilder
addPreCode bool
리턴 StringBuilder

PrintToHtml() 공개 정적인 메소드

Prints an LNode as LESv3 with HTML syntax highlighting elements.
public static PrintToHtml ( IEnumerable nodes, StringBuilder output = null, bool addPreCode = true, IMessageSink sink = null, ILNodePrinterOptions options = null ) : StringBuilder
nodes IEnumerable Syntax trees to print.
output StringBuilder Output StringBuilder for HTML code.
addPreCode bool Whether to wrap the output in "<pre class='highlight'><code>" tags.
sink IMessageSink
options ILNodePrinterOptions Options to control the style for code printing.
리턴 StringBuilder

PrintToHtml() 공개 메소드

public PrintToHtml ( ILNode node, StringBuilder output = null, bool addPreCode = true ) : StringBuilder
node ILNode
output StringBuilder
addPreCode bool
리턴 StringBuilder

PrintToHtmlCore() 공개 정적인 메소드

Converts a StringBuilder with LesColorCode control codes to HTML with Pygments CSS class codes.
public static PrintToHtmlCore ( StringBuilder input, StringBuilder output = null, bool addPreCode = true, string newline = "\n", string colorCodesToCssClasses = null ) : StringBuilder
input StringBuilder Input containing control characters.
output StringBuilder Output StringBuilder for HTML code. If null, a new one is created.
addPreCode bool Whether to wrap the output in "<pre class='highlight'><code>" tags.
newline string What to write to output when '\n' is encountered.
colorCodesToCssClasses string CSS class table for span tags, /// see .
리턴 StringBuilder

StartToken() 보호된 메소드

protected StartToken ( LesColorCode kind ) : void
kind LesColorCode
리턴 void