C# Class 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.
Inheritance: Les3Printer
显示文件 Open project: qwertie/ecsharp Class Usage Examples

Public Methods

Method Description
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.

Protected Methods

Method Description
ColorCodeForId ( Symbol name ) : LesColorCode
StartToken ( LesColorCode kind ) : void

Method Details

ColorCodeForId() protected method

protected ColorCodeForId ( Symbol name ) : LesColorCode
name Symbol
return LesColorCode

GetDefaultCssClassTable() public static method

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[]
return string[]

Les3PrettyPrinter() public method

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
return System

Les3PrettyPrinter() public method

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
return System

PrintToConsole() public method

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

PrintToConsole() public method

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

PrintToConsoleCore() public static method

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

PrintToHtml() public method

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

PrintToHtml() public static method

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.
return StringBuilder

PrintToHtml() public method

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

PrintToHtmlCore() public static method

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 .
return StringBuilder

StartToken() protected method

protected StartToken ( LesColorCode kind ) : void
kind LesColorCode
return void