Package org.w3c.tidy
Class PPrint
- java.lang.Object
-
- org.w3c.tidy.PPrint
-
public class PPrint extends java.lang.Object
Pretty print parse tree. Block-level and unknown elements are printed on new lines and their contents indented 2 spaces Inline elements are printed inline. Inline content is wrapped on spaces (except in attribute values or preformatted text, after start tags and before end tags.- Version:
- $Revision: 1122 $ ($Author: aditsu $)
-
-
Field Summary
Fields Modifier and Type Field Description private static short
ATTRIBVALUE
position: attribute value.private static short
CDATA
position: cdata.private static java.lang.String
CDATA_END
End cdata token.private static java.lang.String
CDATA_START
Start cdata token.private static short
COMMENT
position: comment.private Configuration
configuration
current configuration.private int
count
Total slides count.private static java.lang.String
CSS_COMMENT_END
CSS comment end.private static java.lang.String
CSS_COMMENT_START
CSS comment start.private static java.lang.String
DEFAULT_COMMENT_END
Default comment end.private static java.lang.String
DEFAULT_COMMENT_START
Default comment start.private boolean
inAttVal
private boolean
inString
private static java.lang.String
JS_COMMENT_END
Javascript comment end.private static java.lang.String
JS_COMMENT_START
Javascript comment start.private int
lbufsize
private int[]
linebuf
private int
linelen
private static short
NORMAL
position: normal.private static short
NOWRAP
position: nowrap.private static short
PREFORMATTED
position: preformatted text.private int
slide
Current slide number.private Node
slidecontent
private static java.lang.String
VB_COMMENT_END
VB comment end.private static java.lang.String
VB_COMMENT_START
VB comment start.private int
wraphere
-
Constructor Summary
Constructors Constructor Description PPrint(Configuration configuration)
Instantiates a new PPrint.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
addAsciiString(java.lang.String str, int index)
Adds an ascii String.private void
addC(int c, int index)
void
addTransitionEffect(Lexer lexer, Node root, double duration)
Add meta element for page transition effect, this works on IE but not NS.private static boolean
afterSpace(Node node)
Line can be wrapped immediately after inline start tag provided if follows a text node ending in a space, or it parent is an inline element that that rule applies to.void
condFlushLine(Out fout, int indent)
int
countSlides(Node node)
Split parse tree by h2 elements and output to separate files.void
createSlides(Lexer lexer, Node root)
Creates slides from h2.(package private) int
cWrapLen(int ind)
void
flushLine(Out fout, int indent)
static int
getUTF8(byte[] str, int start, int[] ch)
return one less than the number of bytes used by the UTF-8 byte sequence.(package private) static boolean
hasCDATA(Lexer lexer, Node node)
Does the current node contain a CDATA section?private boolean
insideHead(Node node)
Is the current node inside HEAD?private void
printAsp(Out fout, int indent, Node node)
note ASP and JSTE share <% ...private void
printAttribute(Out fout, int indent, Node node, AttVal attr)
private void
printAttrs(Out fout, int indent, Node node, AttVal attr)
private void
printAttrValue(Out fout, int indent, java.lang.String value, int delim, boolean wrappable)
(package private) void
printBody(Out fout, Lexer lexer, Node root, boolean xml)
Print just the content of the body element.private void
printCDATA(Out fout, int indent, Node node)
private void
printChar(int c, short mode)
private void
printComment(Out fout, int indent, Node node)
private void
printDocType(Out fout, int indent, Lexer lexer, Node node)
private void
printEndTag(short mode, int indent, Node node)
private void
printJste(Out fout, int indent, Node node)
JSTE also supports <# ...private void
printNavBar(Out fout, int indent)
private void
printPhp(Out fout, int indent, Node node)
PHP is based on XML processing instructions.private void
printPI(Out fout, int indent, Node node)
private void
printScriptStyle(Out fout, short mode, int indent, Lexer lexer, Node node)
Print script and style elements.private void
printSection(Out fout, int indent, Node node)
void
printSlide(Out fout, short mode, int indent, Lexer lexer)
Called from printTree to print the content of a slide from the node slidecontent.private void
printString(java.lang.String str)
private void
printTag(Lexer lexer, Out fout, short mode, int indent, Node node)
private void
printText(Out fout, short mode, int indent, byte[] textarray, int start, int end)
The line buffer is uint not char so we can hold Unicode values unencoded.void
printTree(Out fout, short mode, int indent, Lexer lexer, Node node)
private void
printXmlDecl(Out fout, int indent, Node node)
Pretty print the xml declaration.void
printXMLTree(Out fout, short mode, int indent, Lexer lexer, Node node)
static int
putUTF8(byte[] buf, int start, int c)
store char c as UTF-8 encoded byte stream.private boolean
shouldIndent(Node node)
Should tidy indent the give tag?private int
textEndsWithNewline(Lexer lexer, Node node)
Is text node and already ends w/ a newline? Used to pretty print CDATA/PRE text content.private void
wrapAttrVal(Out fout, int indent, boolean inString)
private void
wrapLine(Out fout, int indent)
-
-
-
Field Detail
-
NORMAL
private static final short NORMAL
position: normal.- See Also:
- Constant Field Values
-
PREFORMATTED
private static final short PREFORMATTED
position: preformatted text.- See Also:
- Constant Field Values
-
COMMENT
private static final short COMMENT
position: comment.- See Also:
- Constant Field Values
-
ATTRIBVALUE
private static final short ATTRIBVALUE
position: attribute value.- See Also:
- Constant Field Values
-
NOWRAP
private static final short NOWRAP
position: nowrap.- See Also:
- Constant Field Values
-
CDATA
private static final short CDATA
position: cdata.- See Also:
- Constant Field Values
-
CDATA_START
private static final java.lang.String CDATA_START
Start cdata token.- See Also:
- Constant Field Values
-
CDATA_END
private static final java.lang.String CDATA_END
End cdata token.- See Also:
- Constant Field Values
-
JS_COMMENT_START
private static final java.lang.String JS_COMMENT_START
Javascript comment start.- See Also:
- Constant Field Values
-
JS_COMMENT_END
private static final java.lang.String JS_COMMENT_END
Javascript comment end.- See Also:
- Constant Field Values
-
VB_COMMENT_START
private static final java.lang.String VB_COMMENT_START
VB comment start.- See Also:
- Constant Field Values
-
VB_COMMENT_END
private static final java.lang.String VB_COMMENT_END
VB comment end.- See Also:
- Constant Field Values
-
CSS_COMMENT_START
private static final java.lang.String CSS_COMMENT_START
CSS comment start.- See Also:
- Constant Field Values
-
CSS_COMMENT_END
private static final java.lang.String CSS_COMMENT_END
CSS comment end.- See Also:
- Constant Field Values
-
DEFAULT_COMMENT_START
private static final java.lang.String DEFAULT_COMMENT_START
Default comment start.- See Also:
- Constant Field Values
-
DEFAULT_COMMENT_END
private static final java.lang.String DEFAULT_COMMENT_END
Default comment end.- See Also:
- Constant Field Values
-
linebuf
private int[] linebuf
-
lbufsize
private int lbufsize
-
linelen
private int linelen
-
wraphere
private int wraphere
-
inAttVal
private boolean inAttVal
-
inString
private boolean inString
-
slide
private int slide
Current slide number.
-
count
private int count
Total slides count.
-
slidecontent
private Node slidecontent
-
configuration
private Configuration configuration
current configuration.
-
-
Constructor Detail
-
PPrint
public PPrint(Configuration configuration)
Instantiates a new PPrint.- Parameters:
configuration
- configuration
-
-
Method Detail
-
cWrapLen
int cWrapLen(int ind)
- Parameters:
ind
-- Returns:
-
getUTF8
public static int getUTF8(byte[] str, int start, int[] ch)
return one less than the number of bytes used by the UTF-8 byte sequence. The Unicode char is returned in ch.- Parameters:
str
- points to the UTF-8 byte sequencestart
- starting offset in strch
- initialized to 1st byte, passed as an array to allow modification- Returns:
- one less that the number of bytes used by UTF-8 char
-
putUTF8
public static int putUTF8(byte[] buf, int start, int c)
store char c as UTF-8 encoded byte stream.- Parameters:
buf
-start
-c
-- Returns:
-
addC
private void addC(int c, int index)
-
addAsciiString
private int addAsciiString(java.lang.String str, int index)
Adds an ascii String.- Parameters:
str
- String to be addedindex
- actual line lenght- Returns:
- final line length
-
wrapLine
private void wrapLine(Out fout, int indent)
- Parameters:
fout
-indent
-
-
wrapAttrVal
private void wrapAttrVal(Out fout, int indent, boolean inString)
- Parameters:
fout
-indent
-inString
-
-
flushLine
public void flushLine(Out fout, int indent)
- Parameters:
fout
-indent
-
-
condFlushLine
public void condFlushLine(Out fout, int indent)
- Parameters:
fout
-indent
-
-
printChar
private void printChar(int c, short mode)
- Parameters:
c
-mode
-
-
printText
private void printText(Out fout, short mode, int indent, byte[] textarray, int start, int end)
The line buffer is uint not char so we can hold Unicode values unencoded. The translation to UTF-8 is deferred to the outc routine called to flush the line buffer.- Parameters:
fout
-mode
-indent
-textarray
-start
-end
-
-
printString
private void printString(java.lang.String str)
- Parameters:
str
-
-
printAttrValue
private void printAttrValue(Out fout, int indent, java.lang.String value, int delim, boolean wrappable)
- Parameters:
fout
-indent
-value
-delim
-wrappable
-
-
printAttribute
private void printAttribute(Out fout, int indent, Node node, AttVal attr)
- Parameters:
fout
-indent
-node
-attr
-
-
printAttrs
private void printAttrs(Out fout, int indent, Node node, AttVal attr)
- Parameters:
fout
-indent
-node
-attr
-
-
afterSpace
private static boolean afterSpace(Node node)
Line can be wrapped immediately after inline start tag provided if follows a text node ending in a space, or it parent is an inline element that that rule applies to. This behaviour was reverse engineered from Netscape 3.0- Parameters:
node
- current Node- Returns:
true
if the current char follows a space
-
printTag
private void printTag(Lexer lexer, Out fout, short mode, int indent, Node node)
- Parameters:
lexer
-fout
-mode
-indent
-node
-
-
printEndTag
private void printEndTag(short mode, int indent, Node node)
- Parameters:
mode
-indent
-node
-
-
printComment
private void printComment(Out fout, int indent, Node node)
- Parameters:
fout
-indent
-node
-
-
printDocType
private void printDocType(Out fout, int indent, Lexer lexer, Node node)
- Parameters:
fout
-indent
-lexer
-node
-
-
printXmlDecl
private void printXmlDecl(Out fout, int indent, Node node)
Pretty print the xml declaration.- Parameters:
fout
-indent
-node
-
-
printAsp
private void printAsp(Out fout, int indent, Node node)
note ASP and JSTE share <% ... %> syntax.- Parameters:
fout
-indent
-node
-
-
printJste
private void printJste(Out fout, int indent, Node node)
JSTE also supports <# ... #> syntax- Parameters:
fout
-indent
-node
-
-
printPhp
private void printPhp(Out fout, int indent, Node node)
PHP is based on XML processing instructions.- Parameters:
fout
-indent
-node
-
-
printCDATA
private void printCDATA(Out fout, int indent, Node node)
- Parameters:
fout
-indent
-node
-
-
printSection
private void printSection(Out fout, int indent, Node node)
- Parameters:
fout
-indent
-node
-
-
insideHead
private boolean insideHead(Node node)
Is the current node inside HEAD?- Parameters:
node
- Node- Returns:
true
if node is inside an HEAD tag
-
textEndsWithNewline
private int textEndsWithNewline(Lexer lexer, Node node)
Is text node and already ends w/ a newline? Used to pretty print CDATA/PRE text content. If it already ends on a newline, it is not necessary to print another before printing end tag.- Parameters:
lexer
- Lexernode
- text node- Returns:
- text indent
-
hasCDATA
static boolean hasCDATA(Lexer lexer, Node node)
Does the current node contain a CDATA section?- Parameters:
lexer
- Lexernode
- Node- Returns:
true
if node contains a CDATA section
-
printScriptStyle
private void printScriptStyle(Out fout, short mode, int indent, Lexer lexer, Node node)
Print script and style elements. For XHTML, wrap the content as follows:JavaScript: //<![CDATA[ content //]]> VBScript: '<![CDATA[ content ']]> CSS: /*<![CDATA[* / content /*]]>* / other: <![CDATA[ content ]]>
- Parameters:
fout
-mode
-indent
-lexer
-node
-
-
shouldIndent
private boolean shouldIndent(Node node)
Should tidy indent the give tag?- Parameters:
node
- actual node- Returns:
true
if line should be indented
-
printBody
void printBody(Out fout, Lexer lexer, Node root, boolean xml)
Print just the content of the body element. Useful when you want to reuse material from other documents.- Parameters:
fout
-lexer
-root
-xml
-
-
printTree
public void printTree(Out fout, short mode, int indent, Lexer lexer, Node node)
- Parameters:
fout
-mode
-indent
-lexer
-node
-
-
printXMLTree
public void printXMLTree(Out fout, short mode, int indent, Lexer lexer, Node node)
- Parameters:
fout
-mode
-indent
-lexer
-node
-
-
countSlides
public int countSlides(Node node)
Split parse tree by h2 elements and output to separate files. Counts number of h2 children (if any) belonging to node.- Parameters:
node
- root node- Returns:
- number of slides (number of h2 elements)
-
printNavBar
private void printNavBar(Out fout, int indent)
- Parameters:
fout
-indent
-
-
printSlide
public void printSlide(Out fout, short mode, int indent, Lexer lexer)
Called from printTree to print the content of a slide from the node slidecontent. On return slidecontent points to the node starting the next slide or null. The variables slide and count are used to customise the navigation bar.- Parameters:
fout
-mode
-indent
-lexer
-
-
addTransitionEffect
public void addTransitionEffect(Lexer lexer, Node root, double duration)
Add meta element for page transition effect, this works on IE but not NS.- Parameters:
lexer
-root
-duration
-
-
-