Package com.uwyn.jhighlight.renderer
Class XhtmlRenderer
java.lang.Object
com.uwyn.jhighlight.renderer.XhtmlRenderer
- All Implemented Interfaces:
Renderer
- Direct Known Subclasses:
CppXhtmlRenderer,GroovyXhtmlRenderer,JavaXhtmlRenderer,XmlXhtmlRenderer
Provides an abstract base class to perform source code to XHTML syntax
highlighting.
- Since:
- 1.0
- Version:
- $Revision: 3108 $
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringgetCssClass(int style) Looks up the CSS class identifier that corresponds to the syntax style.protected StringReturns all the CSS class definitions that should appear within thestyleXHTML tag.protected abstract MapReturns a map of all the CSS styles that the renderer requires, together with default definitions for them.protected abstract ExplicitStateHighlighterReturns the language-specific highlighting lexer that should be usedprotected StringReturns the XHTML footer that nicely finishes the file after the highlighted source code.protected StringgetXhtmlHeader(String name) Returns the XHTML header that preceedes the highlighted source code.protected StringgetXhtmlHeaderFragment(String name) Returns the XHTML header that preceedes the highlighted source code for a fragment.voidhighlight(String name, InputStream in, OutputStream out, String encoding, boolean fragment) Transforms source code that's provided through anInputStreamto highlighted syntax in XHTML and writes it back to anOutputStream.Transforms source code that's provided through aStringto highlighted syntax in XHTML and returns it as aString.
-
Constructor Details
-
XhtmlRenderer
public XhtmlRenderer()
-
-
Method Details
-
highlight
public void highlight(String name, InputStream in, OutputStream out, String encoding, boolean fragment) throws IOException Transforms source code that's provided through anInputStreamto highlighted syntax in XHTML and writes it back to anOutputStream.If the highlighting has to become a fragment, no CSS styles will be generated.
For complete documents, there's a collection of default styles that will be included. It's possible to override these by changing the provided
jhighlight.propertiesfile. It's best to look at this file in the JHighlight archive and modify the styles that are there already.- Specified by:
highlightin interfaceRenderer- Parameters:
name- The name of the source file.in- The input stream that provides the source code that needs to be transformed.out- The output stream to which to resulting XHTML should be written.encoding- The encoding that will be used to read and write the text.fragment-trueif the generated XHTML should be a fragment; orfalseif it should be a complete page- Throws:
IOException- Since:
- 1.0
- See Also:
-
highlight
public String highlight(String name, String in, String encoding, boolean fragment) throws IOException Transforms source code that's provided through aStringto highlighted syntax in XHTML and returns it as aString.If the highlighting has to become a fragment, no CSS styles will be generated.
- Specified by:
highlightin interfaceRenderer- Parameters:
name- The name of the source file.in- The input string that provides the source code that needs to be transformed.encoding- The encoding that will be used to read and write the text.fragment-trueif the generated XHTML should be a fragment; orfalseif it should be a complete page orfalseif it should be a complete document- Returns:
- the highlighted source code as XHTML in a string
- Throws:
IOException- Since:
- 1.0
- See Also:
-
getDefaultCssStyles
Returns a map of all the CSS styles that the renderer requires, together with default definitions for them.- Returns:
- The map of CSS styles.
- Since:
- 1.0
-
getCssClass
Looks up the CSS class identifier that corresponds to the syntax style.- Parameters:
style- The syntax style.- Returns:
- The requested CSS class identifier; or
nullif the syntax style isn't supported. - Since:
- 1.0
-
getHighlighter
Returns the language-specific highlighting lexer that should be used- Returns:
- The requested highlighting lexer.
- Since:
- 1.0
-
getCssClassDefinitions
Returns all the CSS class definitions that should appear within thestyleXHTML tag.This should support all the classes that the
getCssClass(int)method returns.- Returns:
- The CSS class definitions
- Since:
- 1.0
- See Also:
-
getXhtmlHeader
Returns the XHTML header that preceedes the highlighted source code.It will integrate the CSS class definitions and use the source's name to indicate in XHTML which file has been highlighted.
- Parameters:
name- The name of the source file.- Returns:
- The constructed XHTML header.
- Since:
- 1.0
-
getXhtmlHeaderFragment
Returns the XHTML header that preceedes the highlighted source code for a fragment.- Parameters:
name- The name of the source file.- Returns:
- The constructed XHTML header.
- Since:
- 1.0
-