1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_pre.cpp
3 // Purpose: wxHtml module for <PRE> ... </PRE> tag (code citation)
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
16 #if wxUSE_HTML && wxUSE_STREAMS
21 #include "wx/html/forcelnk.h"
22 #include "wx/html/m_templ.h"
24 #include "wx/html/htmlcell.h"
25 #include "wx/tokenzr.h"
26 #include "wx/encconv.h"
30 // replaces '\t', ' ' and '\n' with HTML markup:
31 static wxString LINKAGEMODE
HtmlizeLinebreaks(const wxString
& str
)
34 out
.reserve(str
.length()); // we'll certainly need at least that
36 const wxString::const_iterator end
= str
.end();
37 for ( wxString::const_iterator i
= str
.begin(); i
!= end
; ++i
)
39 switch ( (*i
).GetValue() )
42 while ( i
!= end
&& *i
!= '>' )
51 // We need to translate any line break into exactly one <br>.
52 // Quoting HTML spec: "A line break is defined to be a carriage
53 // return (
), a line feed (
), or a carriage
54 // return/line feed pair."
57 wxString::const_iterator
j(i
+ 1);
58 if ( j
!= end
&& *j
== '\n' )
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
81 TAG_HANDLER_BEGIN(PRE
, "PRE")
82 TAG_HANDLER_CONSTR(PRE
) { }
86 wxHtmlContainerCell
*c
;
88 const int fixed
= m_WParser
->GetFontFixed();
89 const int italic
= m_WParser
->GetFontItalic();
90 const int underlined
= m_WParser
->GetFontUnderlined();
91 const int bold
= m_WParser
->GetFontBold();
92 const int fsize
= m_WParser
->GetFontSize();
93 const wxHtmlWinParser::WhitespaceMode whitespace
=
94 m_WParser
->GetWhitespaceMode();
96 c
= m_WParser
->GetContainer();
97 m_WParser
->SetWhitespaceMode(wxHtmlWinParser::Whitespace_Pre
);
98 m_WParser
->SetFontUnderlined(false);
99 m_WParser
->SetFontBold(false);
100 m_WParser
->SetFontItalic(false);
101 m_WParser
->SetFontFixed(true);
102 m_WParser
->SetFontSize(3);
103 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
105 m_WParser
->CloseContainer();
106 c
= m_WParser
->OpenContainer();
107 c
->SetWidthFloat(tag
);
108 c
= m_WParser
->OpenContainer();
109 c
->SetAlignHor(wxHTML_ALIGN_LEFT
);
110 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
112 wxString srcMid
= m_WParser
->GetInnerSource(tag
);
114 // setting Whitespace_Pre mode takes care of spaces and TABs, but
115 // not linebreaks, so we have to translate them into <br> by
116 // calling HtmlizeLinebreaks() here
117 ParseInnerSource(HtmlizeLinebreaks(srcMid
));
119 m_WParser
->CloseContainer();
120 m_WParser
->CloseContainer();
121 c
= m_WParser
->OpenContainer();
123 m_WParser
->SetWhitespaceMode(whitespace
);
124 m_WParser
->SetFontUnderlined(underlined
);
125 m_WParser
->SetFontBold(bold
);
126 m_WParser
->SetFontItalic(italic
);
127 m_WParser
->SetFontFixed(fixed
);
128 m_WParser
->SetFontSize(fsize
);
129 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
140 TAGS_MODULE_BEGIN(Pre
)