1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmDocumentationFormatterHTML.cxx,v $
6 Date: $Date: 2008-03-06 16:34:23 $
7 Version: $Revision: 1.11 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmDocumentationFormatterHTML.h"
18 #include "cmDocumentationSection.h"
20 //----------------------------------------------------------------------------
21 static bool cmDocumentationIsHyperlinkChar(char c
)
23 // This is not a complete list but works for CMake documentation.
24 return ((c
>= 'A' && c
<= 'Z') ||
25 (c
>= 'a' && c
<= 'z') ||
26 (c
>= '0' && c
<= '9') ||
27 c
== '-' || c
== '.' || c
== '/' || c
== '~' || c
== '@' ||
28 c
== ':' || c
== '_' || c
== '&' || c
== '?' || c
== '=');
31 //----------------------------------------------------------------------------
32 static void cmDocumentationPrintHTMLChar(std::ostream
& os
, char c
)
34 // Use an escape sequence if necessary.
54 //----------------------------------------------------------------------------
55 const char* cmDocumentationPrintHTMLLink(std::ostream
& os
, const char* begin
)
57 // Look for the end of the link.
58 const char* end
= begin
;
59 while(cmDocumentationIsHyperlinkChar(*end
))
64 // Print the hyperlink itself.
66 for(const char* c
= begin
; c
!= end
; ++c
)
68 cmDocumentationPrintHTMLChar(os
, *c
);
72 // The name of the hyperlink is the text itself.
73 for(const char* c
= begin
; c
!= end
; ++c
)
75 cmDocumentationPrintHTMLChar(os
, *c
);
79 // Return the position at which to continue scanning the input
85 cmDocumentationFormatterHTML::cmDocumentationFormatterHTML()
86 :cmDocumentationFormatter()
90 void cmDocumentationFormatterHTML
91 ::PrintSection(std::ostream
& os
,
92 const cmDocumentationSection
§ion
,
97 os
<< "<h2><a name=\"section_" << name
<< "\"/>" << name
<< "</h2>\n";
100 const std::vector
<cmDocumentationEntry
> &entries
=
101 section
.GetEntries();
104 for(std::vector
<cmDocumentationEntry
>::const_iterator op
105 = entries
.begin(); op
!= entries
.end(); ++ op
)
109 os
<< " <li><a href=\"#command_"
110 << op
->Name
.c_str() << "\"><b><code>";
111 this->PrintHTMLEscapes(os
, op
->Name
.c_str());
112 os
<< "</code></b></a></li>";
117 for(std::vector
<cmDocumentationEntry
>::const_iterator op
= entries
.begin();
118 op
!= entries
.end();)
123 for(;op
!= entries
.end() && op
->Name
.size(); ++op
)
128 os
<< " <a name=\"command_"<<
129 op
->Name
.c_str() << "\"><b><code>";
130 this->PrintHTMLEscapes(os
, op
->Name
.c_str());
131 os
<< "</code></b></a>: ";
133 this->PrintHTMLEscapes(os
, op
->Brief
.c_str());
137 this->PrintFormatted(os
, op
->Full
.c_str());
146 this->PrintFormatted(os
, op
->Brief
.c_str());
153 void cmDocumentationFormatterHTML::PrintPreformatted(std::ostream
& os
,
157 this->PrintHTMLEscapes(os
, text
);
161 void cmDocumentationFormatterHTML::PrintParagraph(std::ostream
& os
,
165 this->PrintHTMLEscapes(os
, text
);
168 //----------------------------------------------------------------------------
169 void cmDocumentationFormatterHTML::PrintHeader(const char* /*name*/,
172 os
<< "<html><body>\n";
175 //----------------------------------------------------------------------------
176 void cmDocumentationFormatterHTML::PrintFooter(std::ostream
& os
)
178 os
<< "</body></html>\n";
181 //----------------------------------------------------------------------------
182 void cmDocumentationFormatterHTML::PrintHTMLEscapes(std::ostream
& os
,
185 // Hyperlink prefixes.
186 static const char* hyperlinks
[] = {"http://", "ftp://", "mailto:", 0};
188 // Print each character.
189 for(const char* p
= text
; *p
;)
191 // Handle hyperlinks specially to make them active.
192 bool found_hyperlink
= false;
193 for(const char** h
= hyperlinks
; !found_hyperlink
&& *h
; ++h
)
195 if(strncmp(p
, *h
, strlen(*h
)) == 0)
197 p
= cmDocumentationPrintHTMLLink(os
, p
);
198 found_hyperlink
= true;
202 // Print other characters normally.
205 cmDocumentationPrintHTMLChar(os
, *p
++);
210 void cmDocumentationFormatterHTML
211 ::PrintIndex(std::ostream
& os
,
212 std::vector
<const cmDocumentationSection
*>& sections
)
214 os
<< "<h2><a name=\"section_Index\"/>Master Index</h2>\n";
216 for(unsigned int i
=0; i
< sections
.size(); ++i
)
218 std::string name
= sections
[i
]->
219 GetName((this->GetForm()));
220 os
<< " <li><a href=\"#section_"
221 << name
<< "\"<b>" << name
<< "</b></a></li>\n";