HTML Tidy  5.9.15
The HTACG Tidy HTML Project
pprint.h
Go to the documentation of this file.
1 #ifndef __PPRINT_H__
2 #define __PPRINT_H__
3 
4 /**************************************************************************//**
5  * @file
6  * Pretty Print the parse tree.
7  *
8  * Pretty printer for HTML and XML documents.
9  * - Block-level and unknown elements are printed on new lines and
10  * their contents indented with a user configured amount of spaces/tabs.
11  * - Inline elements are printed inline.
12  * - Inline content is wrapped on spaces (except in attribute values or
13  * preformatted text, after start tags and before end tags.
14  *
15  * @author HTACG, et al (consult git log)
16  *
17  * @copyright
18  * Copyright (c) 1998-2021 World Wide Web Consortium (Massachusetts
19  * Institute of Technology, European Research Consortium for Informatics
20  * and Mathematics, Keio University) and HTACG.
21  * @par
22  * All Rights Reserved.
23  * @par
24  * See `tidy.h` for the complete license.
25  *
26  * @date Additional updates: consult git log
27  *
28  ******************************************************************************/
29 
30 #include "forward.h"
31 
32 /** @addtogroup internal_api */
33 /** @{ */
34 
35 
36 /***************************************************************************//**
37  ** @defgroup print_h HTML and XML Pretty Printing
38  **
39  ** These functions and structures form the internal API for document
40  ** printing.
41  **
42  ** @{
43  ******************************************************************************/
44 
45 
46 /**
47  * This typedef represents the current pretty-printing mode, and instructs
48  * the printer behavior per the content currently being output.
49  */
50 typedef enum {
51  NORMAL = 0u, /**< Normal output. */
52  PREFORMATTED = 1u, /**< Preformatted output. */
53  COMMENT = 2u, /**< Comment. */
54  ATTRIBVALUE = 4u, /**< An attribute's value. */
55  NOWRAP = 8u, /**< Content that should not be wrapped. */
56  CDATA = 16u /**< CDATA content. */
58 
59 
60 /**
61  * A record of the state of a single line, capturing the indent
62  * level, in-attribute, and in-string state of a line. Instances
63  * of this record are used by the pretty-printing buffer.
64  *
65  * The pretty printer keeps at most two lines of text in the
66  * buffer before flushing output. We need to capture the
67  * indent state (indent level) at the _beginning_ of _each_
68  * line, not the end of just the second line.
69  *
70  * We must also keep track "In Attribute" and "In String"
71  * states at the _end_ of each line,
72  */
73 typedef struct _TidyIndent
74 {
75  int spaces; /**< Indent level of the line. */
76  int attrValStart; /**< Attribute in-value state. */
77  int attrStringStart; /**< Attribute in-string state. */
78 } TidyIndent;
79 
80 
81 /**
82  * The pretty-printing buffer.
83  */
84 typedef struct _TidyPrintImpl
85 {
86  TidyAllocator *allocator; /**< Allocator */
87 
88  uint *linebuf; /**< The line buffer proper. */
89  uint lbufsize; /**< Current size of the buffer. */
90  uint linelen; /**< Current line length. */
91  uint wraphere; /**< Point in the line to wrap text. */
92  uint line; /**< Current line. */
93 
94  uint ixInd; /**< Index into the indent[] array. */
95  TidyIndent indent[2]; /**< Two lines worth of indent state */
97 
98 
99 /**
100  * Allocates and initializes the pretty-printing buffer for a Tidy document.
101  */
102 TY_PRIVATE void TY_(InitPrintBuf)( TidyDocImpl* doc );
103 
104 
105 /**
106  * Deallocates and free a Tidy document's pretty-printing buffer.
107  */
108 TY_PRIVATE void TY_(FreePrintBuf)( TidyDocImpl* doc );
109 
110 
111 /**
112  * Flushes the current buffer to the actual output sink.
113  */
114 TY_PRIVATE void TY_(PFlushLine)( TidyDocImpl* doc, uint indent );
115 
116 
117 /**
118  * Print just the content of the HTML body element, which is useful when
119  * want to reuse material from other documents.
120  * -- Sebastiano Vigna <vigna@dsi.unimi.it>
121  */
122 TY_PRIVATE void TY_(PrintBody)( TidyDocImpl* doc );
123 
124 
125 /**
126  * Print the HTML document tree for the given document using the given node
127  * as the root of the document. Note that you can print an entire document
128  * node as body using PPrintTree()
129  */
130 TY_PRIVATE void TY_(PPrintTree)( TidyDocImpl* doc, uint mode, uint indent, Node *node );
131 
132 
133 /**
134  * Print the XML document tree for the given document using the given node
135  * as the root of the document.
136  */
137 TY_PRIVATE void TY_(PPrintXMLTree)( TidyDocImpl* doc, uint mode, uint indent, Node *node );
138 
139 
140 /** @} end print_h group */
141 /** @} end internal_api group */
142 
143 #endif /* __PPRINT_H__ */
#define TY_PRIVATE
Definition: forward.h:29
#define TY_(str)
Definition: forward.h:23
uint * linebuf
The line buffer proper.
Definition: pprint.h:88
int spaces
Indent level of the line.
Definition: pprint.h:75
uint ixInd
Index into the indent[] array.
Definition: pprint.h:94
int attrStringStart
Attribute in-string state.
Definition: pprint.h:77
TidyAllocator * allocator
Allocator.
Definition: pprint.h:86
uint wraphere
Point in the line to wrap text.
Definition: pprint.h:91
uint linelen
Current line length.
Definition: pprint.h:90
uint lbufsize
Current size of the buffer.
Definition: pprint.h:89
int attrValStart
Attribute in-value state.
Definition: pprint.h:76
uint line
Current line.
Definition: pprint.h:92
PrettyPrintMode
This typedef represents the current pretty-printing mode, and instructs the printer behavior per the ...
Definition: pprint.h:50
@ ATTRIBVALUE
An attribute's value.
Definition: pprint.h:54
@ NORMAL
Normal output.
Definition: pprint.h:51
@ PREFORMATTED
Preformatted output.
Definition: pprint.h:52
@ CDATA
CDATA content.
Definition: pprint.h:56
@ COMMENT
Comment.
Definition: pprint.h:53
@ NOWRAP
Content that should not be wrapped.
Definition: pprint.h:55
A record of the state of a single line, capturing the indent level, in-attribute, and in-string state...
Definition: pprint.h:74
The pretty-printing buffer.
Definition: pprint.h:85
unsigned int uint
Definition: tidyplatform.h:576