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
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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