Lines 6-14
Link Here
|
6 |
|
6 |
|
7 |
CVS Info : |
7 |
CVS Info : |
8 |
|
8 |
|
9 |
$Author: creitzel $ |
9 |
$Author: terry_teague $ |
10 |
$Date: 2002/07/18 18:21:27 $ |
10 |
$Date: 2002/07/08 03:28:41 $ |
11 |
$Revision: 1.48 $ |
11 |
$Revision: 1.46 $ |
12 |
|
12 |
|
13 |
*/ |
13 |
*/ |
14 |
|
14 |
|
Lines 36-41
Link Here
|
36 |
static void PPrintPhp(Out *fout, uint indent, |
36 |
static void PPrintPhp(Out *fout, uint indent, |
37 |
Lexer *lexer, Node *node); |
37 |
Lexer *lexer, Node *node); |
38 |
|
38 |
|
|
|
39 |
/* Tag types to distinguish printing */ |
40 |
typedef enum { |
41 |
SgmlTagStart, |
42 |
SgmlTagEnd |
43 |
}SgmlTagType; |
44 |
|
45 |
extern Bool DescendantOf(Node *element, Dict *tag); |
39 |
|
46 |
|
40 |
#define NORMAL 0 |
47 |
#define NORMAL 0 |
41 |
#define PREFORMATTED 1 |
48 |
#define PREFORMATTED 1 |
Lines 1769-1774
Link Here
|
1769 |
} |
1776 |
} |
1770 |
} |
1777 |
} |
1771 |
|
1778 |
|
|
|
1779 |
void PrintSgmlDefault(Out *fout) |
1780 |
{ |
1781 |
char *str = "SGML cannot contain these elements"; |
1782 |
|
1783 |
fprintf(stderr, str); |
1784 |
} |
1785 |
|
1786 |
void PrintSgmlBodyStart(Out *fout, uint indent) |
1787 |
{ |
1788 |
char *str = "<article>"; |
1789 |
PPrintString(fout, indent, str); |
1790 |
} |
1791 |
|
1792 |
#define DIGIT(c) (c - 48) |
1793 |
#define TOTAL_H 6 |
1794 |
static Bool seen_h[TOTAL_H] = {no, no, no, no, no, no}; |
1795 |
|
1796 |
/* Yuck ugly. FIXME */ |
1797 |
#define SECT(i) (i - startsect) |
1798 |
static startsect = 0; /* We are at level 0(H1) initially */ |
1799 |
|
1800 |
void PrintSgmlBodyEnd(Out *fout, uint indent) |
1801 |
{ int i = TOTAL_H - 1; |
1802 |
char str[10]; |
1803 |
|
1804 |
while(i >= 0) { |
1805 |
if(seen_h[i] == yes) { |
1806 |
if(i == 5) |
1807 |
sprintf(str, "</simpleect>"); |
1808 |
else |
1809 |
sprintf(str, "</sect%d>", SECT(i) + 1); |
1810 |
PPrintString(fout, indent, str); |
1811 |
seen_h[i] = no; |
1812 |
} |
1813 |
--i; |
1814 |
} |
1815 |
|
1816 |
sprintf(str, "</article>"); |
1817 |
PPrintString(fout, indent, str); |
1818 |
} |
1819 |
|
1820 |
char *GetContent(Lexer *lexer, Node *node) |
1821 |
{ Node *content, *temp_node; |
1822 |
char *str, *temp, c; |
1823 |
Bool flag = no; |
1824 |
int i; |
1825 |
|
1826 |
content = node->content; |
1827 |
|
1828 |
/* Find the <a> tag */ |
1829 |
for (temp_node = content; |
1830 |
temp_node && temp_node->tag != tag_a; |
1831 |
temp_node = temp_node->next) |
1832 |
; |
1833 |
|
1834 |
if(temp_node == NULL) { /* There is no <a> .. </a> tag */ |
1835 |
/* Discard all elements which are not text nodes */ |
1836 |
temp_node = content; |
1837 |
for (temp_node = content; |
1838 |
temp_node && temp_node->type != TextNode; |
1839 |
temp_node = temp_node->next) |
1840 |
; |
1841 |
if(temp_node == NULL) { /* There's no TextNode either */ |
1842 |
str = MemAlloc(1); |
1843 |
str[0] = '\0'; |
1844 |
return str; |
1845 |
} |
1846 |
} |
1847 |
content = temp_node; |
1848 |
|
1849 |
if(content->type == TextNode) { |
1850 |
int size = content->end - content->start; |
1851 |
|
1852 |
str = MemAlloc(size + 1); |
1853 |
str[size] = '\0'; |
1854 |
wstrncpy(str, lexer->lexbuf + content->start, size); |
1855 |
} |
1856 |
else if(content->tag == tag_a){ |
1857 |
AttVal *name; |
1858 |
int size; |
1859 |
|
1860 |
name = GetAttrByName(content, "name"); |
1861 |
if(name == NULL) |
1862 |
name = GetAttrByName(content, "href"); |
1863 |
|
1864 |
if(name == NULL) { /* No href or name, let's take empty id */ |
1865 |
size = 0; |
1866 |
str = MemAlloc(size + 1); |
1867 |
str[size] = '\0'; |
1868 |
} |
1869 |
else { |
1870 |
size = wstrlen(name->value); |
1871 |
str = MemAlloc(size + 1); |
1872 |
str[size] = '\0'; |
1873 |
wstrncpy(str, name->value, size); |
1874 |
} |
1875 |
} |
1876 |
|
1877 |
temp = str; |
1878 |
if(str[0] == '#') |
1879 |
flag = yes; |
1880 |
|
1881 |
#define SGML_NAMELEN 44 /* Maximum id namelength */ |
1882 |
|
1883 |
i = 0; |
1884 |
|
1885 |
while(*temp && i < SGML_NAMELEN) { |
1886 |
if(flag) |
1887 |
*temp = *(temp + 1); |
1888 |
if(*temp == ' ') |
1889 |
*temp = '_'; |
1890 |
++temp; |
1891 |
++i; |
1892 |
} |
1893 |
*temp = '\0'; |
1894 |
return str; |
1895 |
} |
1896 |
|
1897 |
void PrintSectTag( Out *fout, uint indent, Lexer *lexer, Node *node, |
1898 |
uint startsect) |
1899 |
{ char sectnum = node->element[1]; |
1900 |
char str[100]; |
1901 |
|
1902 |
char *id = GetContent(lexer, node); |
1903 |
|
1904 |
if(sectnum == '6') /* there's no sect6. We can do variety of |
1905 |
things here. may be <section> .. */ |
1906 |
sprintf(str, "<simplesect id=\"%s\"><title>", id); |
1907 |
else |
1908 |
sprintf(str, "<sect%c id=\"%s\"><title>", SECT(sectnum), id); |
1909 |
PPrintString(fout, indent, str); |
1910 |
MemFree(id); |
1911 |
} |
1912 |
|
1913 |
Bool ImmediateDescendantOfHTags(Node *element) |
1914 |
{ Node *parent = element->parent; |
1915 |
|
1916 |
if (strlen(parent->element) == 2 && |
1917 |
parent->element[0] == 'h' && |
1918 |
IsDigit(parent->element[1])) |
1919 |
return yes; |
1920 |
return no; |
1921 |
} |
1922 |
|
1923 |
void PrintSgmlLink(Out *fout, uint indent, Node *node) |
1924 |
{ AttVal *addr; |
1925 |
char str[500]; /* FIXME allocate dynamically later */ |
1926 |
|
1927 |
addr = GetAttrByName(node, "name"); |
1928 |
if(addr == NULL) { |
1929 |
addr = GetAttrByName(node, "href"); |
1930 |
if(!ImmediateDescendantOfHTags(node)) { |
1931 |
if(addr->value[0] == '#') |
1932 |
sprintf(str, "<link linkend=\"%s\">", addr->value + 1); |
1933 |
else |
1934 |
sprintf(str, "<ulink url=\"%s\">", addr->value); |
1935 |
if( !DescendantOf(node, tag_p) && |
1936 |
node->prev && node->prev->type == TextNode) |
1937 |
PPrintString(fout, indent, "<para>"); |
1938 |
PPrintString(fout, indent, str); |
1939 |
} |
1940 |
} |
1941 |
else { |
1942 |
if(!ImmediateDescendantOfHTags(node)) { |
1943 |
if(!DescendantOf(node, tag_p)) |
1944 |
sprintf(str, "<para id=\"%s\">", addr->value); |
1945 |
else /* We cannnot have a <para> inside another <para> */ |
1946 |
sprintf(str, "<anchor id=\"%s\"/>", addr->value); |
1947 |
PPrintString(fout, indent, str); |
1948 |
} |
1949 |
} |
1950 |
} |
1951 |
|
1952 |
void PrintSgmlLinkEnd(Out *fout, uint indent, Node *node) |
1953 |
{ AttVal *addr; |
1954 |
|
1955 |
addr = GetAttrByName(node, "name"); |
1956 |
if(addr == NULL) { |
1957 |
addr = GetAttrByName(node, "href"); |
1958 |
if(!ImmediateDescendantOfHTags(node)) { |
1959 |
if(addr->value[0] == '#') |
1960 |
PPrintString(fout, indent, "</link>"); |
1961 |
else |
1962 |
PPrintString(fout, indent, "</ulink>"); |
1963 |
if( !DescendantOf(node, tag_p) && |
1964 |
node->prev && node->prev->type == TextNode) |
1965 |
PPrintString(fout, indent, "</para>"); |
1966 |
} |
1967 |
} |
1968 |
else { |
1969 |
if(!ImmediateDescendantOfHTags(node)) { |
1970 |
if(!DescendantOf(node, tag_p)) |
1971 |
PPrintString(fout, indent, "</para>"); |
1972 |
/* else |
1973 |
<anchor .. /> has already been placed. no need to |
1974 |
do any thing */ |
1975 |
} |
1976 |
} |
1977 |
} |
1978 |
|
1979 |
|
1980 |
void PrintSgmlTagString(Out *fout, uint mode, uint indent, |
1981 |
SgmlTagType sgmltag_type, char *str) |
1982 |
{ PPrintChar(str[0], mode | CDATA); |
1983 |
if(sgmltag_type == SgmlTagEnd) |
1984 |
PPrintChar('/', mode); |
1985 |
PPrintString(fout, indent, str + 1); |
1986 |
} |
1987 |
|
1988 |
void PrintSgmlList(Lexer *lexer, Out *fout, |
1989 |
uint mode, uint indent, |
1990 |
Node *node) |
1991 |
{ if(node->tag == tag_ul) |
1992 |
PPrintString(fout, indent, "<itemizedlist>"); |
1993 |
else if(node->tag == tag_ol) |
1994 |
PPrintString(fout, indent, "<orderedlist>"); |
1995 |
else if(node->tag == tag_dl) |
1996 |
PPrintString(fout, indent, "<variablelist>"); |
1997 |
} |
1998 |
|
1999 |
void PrintSgmlListEnd(Lexer *lexer, Out *fout, |
2000 |
uint mode, uint indent, |
2001 |
Node *node) |
2002 |
{ if(node->tag == tag_ul) |
2003 |
PPrintString(fout, indent, "</itemizedlist>"); |
2004 |
else if(node->tag == tag_ol) |
2005 |
PPrintString(fout, indent, "</orderedlist>"); |
2006 |
else if(node->tag == tag_dl) |
2007 |
PPrintString(fout, indent, "</variablelist>"); |
2008 |
} |
2009 |
|
2010 |
void PrintSgmlListItem(Out *fout, uint indent, Node *node) |
2011 |
{ if(node->tag == tag_li) |
2012 |
PPrintString(fout, indent, "<listitem>"); |
2013 |
else if(node->tag == tag_dd) |
2014 |
PPrintString(fout, indent, "<listitem>"); |
2015 |
} |
2016 |
|
2017 |
void PrintSgmlListItemEnd(Out *fout, uint indent, Node *node) |
2018 |
{ if(node->tag == tag_li) |
2019 |
PPrintString(fout, indent, "</listitem>"); |
2020 |
else if(node->tag == tag_dd) |
2021 |
PPrintString(fout, indent, "</listitem></varlistentry>"); |
2022 |
} |
2023 |
|
2024 |
void PrintSgmlImage(Out *fout, uint indent, Node *node) |
2025 |
{ AttVal *addr; |
2026 |
char str[100]; |
2027 |
|
2028 |
addr = GetAttrByName(node, "src"); |
2029 |
/* We can get other attributes like width, height etc.. */ |
2030 |
if(addr != NULL) { |
2031 |
PPrintString(fout, indent, "<inlinemediaobject><imageobject>"); |
2032 |
PCondFlushLine(fout, indent); |
2033 |
sprintf(str, "<imagedata fileref=\"%s\">", addr->value); |
2034 |
PPrintString(fout, indent, str); |
2035 |
PCondFlushLine(fout, indent); |
2036 |
PPrintString(fout, indent, "</imageobject></inlinemediaobject>"); |
2037 |
PCondFlushLine(fout, indent); |
2038 |
} |
2039 |
} |
2040 |
|
2041 |
int CountColumns(Node *node) |
2042 |
{ Node *temp, *row_content; |
2043 |
int ncols = 0; |
2044 |
|
2045 |
temp = node->content; |
2046 |
|
2047 |
/* FIXME */ |
2048 |
/* Perhaps this is not needed, check with HTML standard later */ |
2049 |
while(temp->tag != tag_tr) |
2050 |
temp = temp->next; |
2051 |
|
2052 |
/* This can contain th or td's */ |
2053 |
row_content = temp->content; |
2054 |
while(row_content) { |
2055 |
if(row_content->tag == tag_th || row_content->tag == tag_td) { |
2056 |
AttVal *colspan; |
2057 |
|
2058 |
colspan = GetAttrByName(row_content, "colspan"); |
2059 |
if(colspan) |
2060 |
ncols += atoi(colspan->value); |
2061 |
else |
2062 |
++ncols; |
2063 |
} |
2064 |
else |
2065 |
fprintf(stderr, "PrintSgml: error in table processing\n"); |
2066 |
row_content = row_content->next; |
2067 |
} |
2068 |
return ncols; |
2069 |
} |
2070 |
|
2071 |
void PrintSgmlTable(Out *fout, uint indent, Node *node) |
2072 |
{ int ncols; |
2073 |
char str[100]; |
2074 |
|
2075 |
PPrintString(fout, indent, "<informaltable>"); |
2076 |
ncols = CountColumns(node); |
2077 |
sprintf(str, "<tgroup cols=\"%d\"><tbody>", ncols); |
2078 |
PPrintString(fout, indent, str); |
2079 |
} |
2080 |
|
2081 |
void PrintSgmlTableEnd(Out *fout, uint indent, Node *node) |
2082 |
{ |
2083 |
PPrintString(fout, indent, "</tbody></tgroup></informaltable>"); |
2084 |
} |
2085 |
|
2086 |
Bool DescendantOfAddress(Node *element) |
2087 |
{ |
2088 |
Node *parent; |
2089 |
|
2090 |
for (parent = element->parent; |
2091 |
parent != null; parent = parent->parent) |
2092 |
{ if (parent->element && wstrcasecmp(parent->element, "address") == 0) |
2093 |
return yes; |
2094 |
} |
2095 |
|
2096 |
return no; |
2097 |
} |
2098 |
|
2099 |
void PrintSgmlTag( Out *fout, uint mode, uint indent, Lexer *lexer, Node *node, |
2100 |
SgmlTagType sgmltag_type) |
2101 |
{ static level = -1; |
2102 |
|
2103 |
if(node->tag == tag_html) { |
2104 |
if(sgmltag_type == SgmlTagStart) |
2105 |
PrintSgmlBodyStart(fout, indent); |
2106 |
else if(sgmltag_type == SgmlTagEnd) |
2107 |
PrintSgmlBodyEnd(fout, indent); |
2108 |
} |
2109 |
else if(node->tag == tag_head) |
2110 |
PrintSgmlTagString(fout, mode, indent, sgmltag_type,"<articleinfo>"); |
2111 |
else if(node->tag == tag_title) |
2112 |
PrintSgmlTagString(fout, mode, indent, sgmltag_type,"<title>"); |
2113 |
/* May be we can replace with node->model & CM_LIST */ |
2114 |
else if(node->tag == tag_ul || node->tag == tag_ol || |
2115 |
node->tag == tag_dl) { |
2116 |
if(sgmltag_type == SgmlTagStart) |
2117 |
PrintSgmlList(lexer, fout, mode, indent, node); |
2118 |
else if(sgmltag_type == SgmlTagEnd) |
2119 |
PrintSgmlListEnd(lexer, fout, mode, indent, node); |
2120 |
} |
2121 |
else if(node->tag == tag_dt) { |
2122 |
if(sgmltag_type == SgmlTagStart) |
2123 |
PPrintString(fout, indent, "<varlistentry><term>"); |
2124 |
else if(sgmltag_type == SgmlTagEnd) |
2125 |
PPrintString(fout, indent, "</term>"); |
2126 |
} |
2127 |
else if(node->tag == tag_li || node->tag == tag_dd) { |
2128 |
if(sgmltag_type == SgmlTagStart) |
2129 |
PrintSgmlListItem(fout, indent, node); |
2130 |
else if(sgmltag_type == SgmlTagEnd) |
2131 |
PrintSgmlListItemEnd(fout, indent, node); |
2132 |
} |
2133 |
/* Later we should clean this before coming to PrintSgml */ |
2134 |
else if(node->tag == tag_p && |
2135 |
/* Table <entry> processing */ |
2136 |
!DescendantOf(node, tag_th) && !DescendantOf(node, tag_td) && |
2137 |
!DescendantOfAddress(node)) |
2138 |
PrintSgmlTagString(fout, mode, indent, sgmltag_type, "<para>"); |
2139 |
else if(node->tag == tag_blockquote) |
2140 |
PrintSgmlTagString(fout, mode, indent, sgmltag_type, "<blockquote>"); |
2141 |
else if(node->tag == tag_pre && |
2142 |
/* Table <entry> processing */ |
2143 |
!DescendantOf(node, tag_th) && !DescendantOf(node, tag_td)) |
2144 |
PrintSgmlTagString(fout, mode, indent, sgmltag_type, |
2145 |
"<programlisting>"); |
2146 |
else if(node->tag == tag_a) { |
2147 |
if(sgmltag_type == SgmlTagStart) |
2148 |
PrintSgmlLink(fout, indent, node); |
2149 |
else if(sgmltag_type == SgmlTagEnd) |
2150 |
PrintSgmlLinkEnd(fout, indent, node); |
2151 |
} |
2152 |
/* Table would require more processing */ |
2153 |
else if(node->tag == tag_table) { |
2154 |
if(sgmltag_type == SgmlTagStart) |
2155 |
PrintSgmlTable(fout, indent, node); |
2156 |
else if(sgmltag_type == SgmlTagEnd) |
2157 |
PrintSgmlTableEnd(fout, indent, node); |
2158 |
} |
2159 |
else if(node->tag == tag_tr) |
2160 |
PrintSgmlTagString(fout, mode, indent, sgmltag_type, "<row>"); |
2161 |
else if(node->tag == tag_td || node->tag == tag_th) |
2162 |
PrintSgmlTagString(fout, mode, indent, sgmltag_type, "<entry>"); |
2163 |
else if(node->tag == tag_img) { /* This is a StartEndTag */ |
2164 |
if(sgmltag_type == SgmlTagStart) |
2165 |
PrintSgmlImage(fout, indent, node); |
2166 |
} |
2167 |
|
2168 |
else if(wstrcasecmp(node->element, "cite") == 0) |
2169 |
PrintSgmlTagString(fout, mode, indent, sgmltag_type, |
2170 |
"<citation>"); |
2171 |
/* We should distinguish tag_strong and tag_em later |
2172 |
haven't found proper docbook tag for <strong> */ |
2173 |
else if(node->tag == tag_em || node->tag == tag_strong || |
2174 |
wstrcasecmp(node->element, "address") == 0) { |
2175 |
if(sgmltag_type == SgmlTagStart) { |
2176 |
if(DescendantOf(node, tag_p) || DescendantOf(node, tag_pre)) |
2177 |
PPrintString(fout, indent, "<emphasis>"); |
2178 |
else |
2179 |
PPrintString(fout, indent, "<para><emphasis>"); |
2180 |
} |
2181 |
else if(sgmltag_type == SgmlTagEnd) { |
2182 |
if(DescendantOf(node, tag_p) || DescendantOf(node, tag_pre)) |
2183 |
PPrintString(fout, indent, "</emphasis>"); |
2184 |
else |
2185 |
PPrintString(fout, indent, "</emphasis></para>"); |
2186 |
} |
2187 |
} |
2188 |
else { |
2189 |
if(wstrcasecmp(node->element, "code") == 0 && |
2190 |
!(node->parent->tag == tag_dd || |
2191 |
node->parent->tag == tag_li)) |
2192 |
PrintSgmlTagString(fout, mode, indent, |
2193 |
sgmltag_type, "<literal>"); |
2194 |
else if(strlen(node->element) == 2 && |
2195 |
node->element[0] == 'h' && |
2196 |
IsDigit(node->element[1])) { |
2197 |
if(sgmltag_type == SgmlTagStart) { |
2198 |
int sectnum = DIGIT(node->element[1]) - 1; |
2199 |
char str[10]; |
2200 |
if(seen_h[sectnum] == no) |
2201 |
seen_h[sectnum] = yes; |
2202 |
else { |
2203 |
int i = level; |
2204 |
while(i > sectnum && seen_h[i] == yes) { |
2205 |
if(i == 5) |
2206 |
sprintf(str, "</simplesect>"); |
2207 |
else |
2208 |
sprintf(str, "</sect%d>", SECT(i) + 1); |
2209 |
PPrintString(fout, indent, str); |
2210 |
seen_h[i] = no; |
2211 |
--i; |
2212 |
} |
2213 |
if(sectnum == 5) |
2214 |
sprintf(str, "</simplesect>"); |
2215 |
else |
2216 |
sprintf(str, "</sect%d>", SECT(sectnum) + 1); |
2217 |
PPrintString(fout, indent, str); |
2218 |
} |
2219 |
/* H1 is not the first level |
2220 |
like the curses man2html pages */ |
2221 |
if(level == -1 && sectnum > 0) |
2222 |
startsect = sectnum; |
2223 |
|
2224 |
PrintSectTag(fout, indent, lexer, node, startsect); |
2225 |
level = sectnum; |
2226 |
} |
2227 |
else |
2228 |
PPrintString(fout, indent, "</title>"); |
2229 |
} |
2230 |
} |
2231 |
} |
2232 |
|
2233 |
void PrintSgml( Out *fout, uint mode, uint indent, |
2234 |
Lexer *lexer, Node *node) |
2235 |
{ Node *content; |
2236 |
|
2237 |
if (node == null) |
2238 |
return; |
2239 |
|
2240 |
if (node->type == TextNode) { |
2241 |
if(DescendantOf(node, tag_dd) && !DescendantOf(node, tag_a) && |
2242 |
!DescendantOf(node, tag_p) && |
2243 |
/* We have to descide on this table stuff later |
2244 |
* <entry> processing is complex */ |
2245 |
!DescendantOf(node, tag_td) && !DescendantOf(node, tag_th)) |
2246 |
/* && wstrcasecmp(node->parent->element, "code") != 0) |
2247 |
above line may be needed later to properly convert <code> stuff */ |
2248 |
{ |
2249 |
PPrintString(fout, indent, "<para>"); |
2250 |
PPrintText(fout, mode, indent, lexer, node->start, node->end); |
2251 |
PPrintString(fout, indent, "</para>"); |
2252 |
} |
2253 |
else { |
2254 |
if(DescendantOf(node, tag_style)) |
2255 |
fprintf(stderr, "PrintSgml: skipping style elements\n\n"); |
2256 |
else |
2257 |
PPrintText(fout, mode, indent, lexer, node->start, node->end); |
2258 |
} |
2259 |
} |
2260 |
else if(node->type == CDATATag && EscapeCdata) |
2261 |
PPrintText(fout, mode, indent, lexer, node->start, node->end); |
2262 |
else if (node->type == CommentTag) |
2263 |
PPrintComment(fout, indent, lexer, node); |
2264 |
else if (node->type == RootNode) |
2265 |
{ |
2266 |
for (content = node->content; |
2267 |
content != null; |
2268 |
content = content->next) |
2269 |
PrintSgml(fout, mode, indent, lexer, content); |
2270 |
} |
2271 |
else if (node->type == DocTypeTag) |
2272 |
PPrintDocType(fout, indent, lexer, node); |
2273 |
else if (node->type == CDATATag) |
2274 |
PPrintCDATA(fout, indent, lexer, node); |
2275 |
else if (node->type == SectionTag) |
2276 |
PPrintSection(fout, indent, lexer, node); |
2277 |
else if (node->type == AspTag || |
2278 |
node->type == JsteTag || |
2279 |
node->type == PhpTag ) |
2280 |
PrintSgmlDefault(fout); |
2281 |
else if (node->type == ProcInsTag) |
2282 |
PPrintPI(fout, indent, lexer, node); |
2283 |
else if (node->type == XmlDecl)// && DbXml May be this is needed |
2284 |
PPrintXmlDecl(fout, indent, lexer, node); |
2285 |
else if (node->tag->model & CM_EMPTY || |
2286 |
(node->type == StartEndTag && !xHTML)) |
2287 |
{ |
2288 |
if (!(node->tag->model & CM_INLINE)) |
2289 |
PCondFlushLine(fout, indent); |
2290 |
|
2291 |
if (MakeClean && node->tag == tag_wbr) |
2292 |
PPrintString(fout, indent, " "); |
2293 |
else |
2294 |
PrintSgmlTag(fout, mode, indent, lexer, node, SgmlTagStart); |
2295 |
} |
2296 |
else { |
2297 |
if (node->type == StartEndTag) |
2298 |
node->type = StartTag; |
2299 |
|
2300 |
if (node->tag && node->tag->parser == ParsePre) |
2301 |
{ |
2302 |
PCondFlushLine(fout, indent); |
2303 |
|
2304 |
indent = 0; |
2305 |
PCondFlushLine(fout, indent); |
2306 |
|
2307 |
PrintSgmlTag(fout, mode, indent, lexer, node, SgmlTagStart); |
2308 |
PFlushLine(fout, indent); |
2309 |
|
2310 |
for (content = node->content; |
2311 |
content != null; |
2312 |
content = content->next) |
2313 |
PrintSgml(fout, (mode | PREFORMATTED | NOWRAP), |
2314 |
indent, lexer, content); |
2315 |
|
2316 |
PCondFlushLine(fout, indent); |
2317 |
PrintSgmlTag(fout, mode, indent, lexer, node, SgmlTagEnd); |
2318 |
PFlushLine(fout, indent); |
2319 |
|
2320 |
if (IndentContent == no && node->next != null) |
2321 |
PFlushLine(fout, indent); |
2322 |
} |
2323 |
else if (node->tag->model & CM_INLINE) |
2324 |
{ PrintSgmlTag(fout, mode, indent, lexer, node, SgmlTagStart); |
2325 |
|
2326 |
if (ShouldIndent(node)) |
2327 |
{ |
2328 |
PCondFlushLine(fout, indent); |
2329 |
indent += spaces; |
2330 |
|
2331 |
for (content = node->content; |
2332 |
content != null; |
2333 |
content = content->next) |
2334 |
PrintSgml(fout, mode, indent, lexer, content); |
2335 |
|
2336 |
PCondFlushLine(fout, indent); |
2337 |
indent -= spaces; |
2338 |
PCondFlushLine(fout, indent); |
2339 |
} |
2340 |
else |
2341 |
{ |
2342 |
|
2343 |
for (content = node->content; |
2344 |
content != null; |
2345 |
content = content->next) |
2346 |
PrintSgml(fout, mode, indent, lexer, content); |
2347 |
} |
2348 |
|
2349 |
PrintSgmlTag(fout, mode, indent, lexer, node, SgmlTagEnd); |
2350 |
} |
2351 |
else |
2352 |
{ PCondFlushLine(fout, indent); |
2353 |
if (SmartIndent && node->prev != null) |
2354 |
PFlushLine(fout, indent); |
2355 |
|
2356 |
PrintSgmlTag(fout, mode ,indent, lexer, node, SgmlTagStart); |
2357 |
if (ShouldIndent(node)) |
2358 |
PCondFlushLine(fout, indent); |
2359 |
else if (node->tag->model & CM_HTML || |
2360 |
node->tag == tag_noframes || |
2361 |
(node->tag->model & CM_HEAD && !(node->tag == tag_title))) |
2362 |
PFlushLine(fout, indent); |
2363 |
|
2364 |
if (ShouldIndent(node)) |
2365 |
{ PCondFlushLine(fout, indent); |
2366 |
indent += spaces; |
2367 |
|
2368 |
for (content = node->content; |
2369 |
content != null; |
2370 |
content = content->next) |
2371 |
PrintSgml(fout, mode, indent, lexer, content); |
2372 |
PCondFlushLine(fout, indent); |
2373 |
indent -= spaces; |
2374 |
PCondFlushLine(fout, indent); |
2375 |
} |
2376 |
else |
2377 |
{ Node *last; |
2378 |
last = null; |
2379 |
for (content = node->content; |
2380 |
content != null; |
2381 |
content = content->next) { |
2382 |
/* kludge for naked text before block level tag */ |
2383 |
if (last && !IndentContent && last->type == TextNode && |
2384 |
content->tag && !(content->tag->model & CM_INLINE) ) |
2385 |
{ |
2386 |
/* PFlushLine(fout, indent); */ |
2387 |
PFlushLine(fout, indent); |
2388 |
} |
2389 |
|
2390 |
PrintSgml(fout, mode, |
2391 |
(ShouldIndent(node) ? indent+spaces : indent), |
2392 |
lexer, content); |
2393 |
last = content; |
2394 |
} |
2395 |
} |
2396 |
PrintSgmlTag(fout, mode, indent, lexer, node, SgmlTagEnd); |
2397 |
PFlushLine(fout, indent); |
2398 |
if (IndentContent == no && |
2399 |
node->next != null && |
2400 |
HideEndTags == no && |
2401 |
(node->tag->model & (CM_BLOCK|CM_LIST|CM_DEFLIST|CM_TABLE))) |
2402 |
PFlushLine(fout, indent); |
2403 |
} |
2404 |
} |
2405 |
} |
2406 |
|
1772 |
void PPrintTree(Out *fout, uint mode, uint indent, |
2407 |
void PPrintTree(Out *fout, uint mode, uint indent, |
1773 |
Lexer *lexer, Node *node) |
2408 |
Lexer *lexer, Node *node) |
1774 |
{ |
2409 |
{ |
Lines 2034-2050
Link Here
|
2034 |
PPrintJste(fout, indent, lexer, node); |
2669 |
PPrintJste(fout, indent, lexer, node); |
2035 |
else if (node->type == PhpTag) |
2670 |
else if (node->type == PhpTag) |
2036 |
PPrintPhp(fout, indent, lexer, node); |
2671 |
PPrintPhp(fout, indent, lexer, node); |
2037 |
else if ( node->tag->model & CM_EMPTY |
2672 |
else if (node->tag->model & CM_EMPTY || (node->type == StartEndTag && !xHTML)) |
2038 |
|| (node->type == StartEndTag && !xHTML) ) |
|
|
2039 |
{ |
2673 |
{ |
2040 |
PCondFlushLine(fout, indent); |
2674 |
PCondFlushLine(fout, indent); |
2041 |
PPrintTag(lexer, fout, mode, indent, node); |
2675 |
PPrintTag(lexer, fout, mode, indent, node); |
2042 |
PFlushLine(fout, indent); |
2676 |
PFlushLine(fout, indent); |
2043 |
|
2677 |
|
2044 |
/* CPR: folks don't want so much vertical spacing in XML |
|
|
2045 |
if (node->next) |
2678 |
if (node->next) |
2046 |
PFlushLine(fout, indent); |
2679 |
PFlushLine(fout, indent); |
2047 |
*/ |
|
|
2048 |
} |
2680 |
} |
2049 |
else /* some kind of container element */ |
2681 |
else /* some kind of container element */ |
2050 |
{ |
2682 |
{ |
Lines 2076-2082
Link Here
|
2076 |
|
2708 |
|
2077 |
PPrintTag(lexer, fout, mode, indent, node); |
2709 |
PPrintTag(lexer, fout, mode, indent, node); |
2078 |
|
2710 |
|
2079 |
if ( !mixed && node->content ) |
2711 |
if (!mixed) |
2080 |
PFlushLine(fout, indent); |
2712 |
PFlushLine(fout, indent); |
2081 |
|
2713 |
|
2082 |
for (content = node->content; |
2714 |
for (content = node->content; |
Lines 2084-2099
Link Here
|
2084 |
content = content->next) |
2716 |
content = content->next) |
2085 |
PPrintXMLTree(fout, mode, cindent, lexer, content); |
2717 |
PPrintXMLTree(fout, mode, cindent, lexer, content); |
2086 |
|
2718 |
|
2087 |
if ( !mixed && node->content ) |
2719 |
if (!mixed) |
2088 |
PCondFlushLine(fout, cindent); |
2720 |
PCondFlushLine(fout, cindent); |
2089 |
|
2721 |
|
2090 |
PPrintEndTag(fout, mode, indent, node); |
2722 |
PPrintEndTag(fout, mode, indent, node); |
2091 |
PCondFlushLine(fout, indent); |
2723 |
PCondFlushLine(fout, indent); |
2092 |
|
2724 |
|
2093 |
/* CPR: folks don't want so much vertical spacing in XML |
|
|
2094 |
if (node->next) |
2725 |
if (node->next) |
2095 |
PFlushLine(fout, indent); |
2726 |
PFlushLine(fout, indent); |
2096 |
*/ |
|
|
2097 |
} |
2727 |
} |
2098 |
} |
2728 |
} |
2099 |
|
2729 |
|