1818// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919// THE SOFTWARE.
2020
21+ // This is a copy of pulldown_cmark's html.rs, modified to work in GTK.
22+
2123//! HTML renderer that takes an iterator of events as input.
2224
2325use std:: borrow:: Cow ;
@@ -75,79 +77,17 @@ impl<'a, 'b, I: Iterator<Item=Event<'a>>> Ctx<'b, I> {
7577
7678 fn start_tag ( & mut self , tag : Tag < ' a > , numbers : & mut HashMap < Cow < ' a , str > , usize > ) {
7779 match tag {
78- Tag :: Paragraph => {
79- self . fresh_line ( ) ;
80- self . buf . push_str ( "<p>" ) ;
81- }
82- Tag :: Rule => {
83- self . fresh_line ( ) ;
84- self . buf . push_str ( "<hr />\n " )
85- }
8680 Tag :: Header ( level) => {
8781 self . fresh_line ( ) ;
88- self . buf . push_str ( "<h" ) ;
89- self . buf . push ( ( b'0' + level as u8 ) as char ) ;
90- self . buf . push ( '>' ) ;
91- }
92- Tag :: Table ( alignments) => {
93- self . table_alignments = alignments;
94- self . buf . push_str ( "<table>" ) ;
95- }
96- Tag :: TableHead => {
97- self . table_state = TableState :: Head ;
98- self . buf . push_str ( "<thead><tr>" ) ;
99- }
100- Tag :: TableRow => {
101- self . table_cell_index = 0 ;
102- self . buf . push_str ( "<tr>" ) ;
103- }
104- Tag :: TableCell => {
105- match self . table_state {
106- TableState :: Head => self . buf . push_str ( "<th" ) ,
107- TableState :: Body => self . buf . push_str ( "<td" ) ,
108- }
109- match self . table_alignments . get ( self . table_cell_index ) {
110- Some ( & Alignment :: Left ) => self . buf . push_str ( " align=\" left\" " ) ,
111- Some ( & Alignment :: Center ) => self . buf . push_str ( " align=\" center\" " ) ,
112- Some ( & Alignment :: Right ) => self . buf . push_str ( " align=\" right\" " ) ,
113- _ => ( ) ,
114- }
115- self . buf . push_str ( ">" ) ;
116- }
117- Tag :: BlockQuote => {
118- self . fresh_line ( ) ;
119- self . buf . push_str ( "<blockquote>\n " ) ;
82+ self . buf . push_str ( "<big>" ) ;
12083 }
12184 Tag :: CodeBlock ( info) => {
12285 self . fresh_line ( ) ;
123- let lang = info. split ( ' ' ) . next ( ) . unwrap ( ) ;
124- if lang. is_empty ( ) {
125- self . buf . push_str ( "<pre><code>" ) ;
126- } else {
127- self . buf . push_str ( "<pre><code class=\" language-" ) ;
128- escape_html ( self . buf , lang, false ) ;
129- self . buf . push_str ( "\" >" ) ;
130- }
131- }
132- Tag :: List ( Some ( 1 ) ) => {
133- self . fresh_line ( ) ;
134- self . buf . push_str ( "<ol>\n " ) ;
135- }
136- Tag :: List ( Some ( start) ) => {
137- self . fresh_line ( ) ;
138- let _ = write ! ( self . buf, "<ol start=\" {}\" >\n " , start) ;
86+ self . buf . push_str ( "<tt>" ) ;
13987 }
140- Tag :: List ( None ) => {
141- self . fresh_line ( ) ;
142- self . buf . push_str ( "<ul>\n " ) ;
143- }
144- Tag :: Item => {
145- self . fresh_line ( ) ;
146- self . buf . push_str ( "<li>" ) ;
147- }
148- Tag :: Emphasis => self . buf . push_str ( "<em>" ) ,
149- Tag :: Strong => self . buf . push_str ( "<strong>" ) ,
150- Tag :: Code => self . buf . push_str ( "<code>" ) ,
88+ Tag :: Emphasis => self . buf . push_str ( "<i>" ) ,
89+ Tag :: Strong => self . buf . push_str ( "<b>" ) ,
90+ Tag :: Code => self . buf . push_str ( "<tt>" ) ,
15191 Tag :: Link ( dest, title) => {
15292 self . buf . push_str ( "<a href=\" " ) ;
15393 escape_href ( self . buf , & dest) ;
@@ -157,67 +97,19 @@ impl<'a, 'b, I: Iterator<Item=Event<'a>>> Ctx<'b, I> {
15797 }
15898 self . buf . push_str ( "\" >" ) ;
15999 }
160- Tag :: Image ( dest, title) => {
161- self . buf . push_str ( "<img src=\" " ) ;
162- escape_href ( self . buf , & dest) ;
163- self . buf . push_str ( "\" alt=\" " ) ;
164- self . raw_text ( numbers) ;
165- if !title. is_empty ( ) {
166- self . buf . push_str ( "\" title=\" " ) ;
167- escape_html ( self . buf , & title, false ) ;
168- }
169- self . buf . push_str ( "\" />" )
170- }
171- Tag :: FootnoteDefinition ( name) => {
172- self . fresh_line ( ) ;
173- let len = numbers. len ( ) + 1 ;
174- self . buf . push_str ( "<div class=\" footnote-definition\" id=\" " ) ;
175- escape_html ( self . buf , & * name, false ) ;
176- self . buf . push_str ( "\" ><sup class=\" footnote-definition-label\" >" ) ;
177- let number = numbers. entry ( name) . or_insert ( len) ;
178- self . buf . push_str ( & * format ! ( "{}" , number) ) ;
179- self . buf . push_str ( "</sup>" ) ;
180- }
100+ _ => ( )
181101 }
182102 }
183103
184104 fn end_tag ( & mut self , tag : Tag ) {
185105 match tag {
186- Tag :: Paragraph => self . buf . push_str ( "</p>\n " ) ,
187- Tag :: Rule => ( ) ,
188- Tag :: Header ( level) => {
189- self . buf . push_str ( "</h" ) ;
190- self . buf . push ( ( b'0' + level as u8 ) as char ) ;
191- self . buf . push_str ( ">\n " ) ;
192- }
193- Tag :: Table ( _) => {
194- self . buf . push_str ( "</tbody></table>\n " ) ;
195- }
196- Tag :: TableHead => {
197- self . buf . push_str ( "</tr></thead><tbody>\n " ) ;
198- self . table_state = TableState :: Body ;
199- }
200- Tag :: TableRow => {
201- self . buf . push_str ( "</tr>\n " ) ;
202- }
203- Tag :: TableCell => {
204- match self . table_state {
205- TableState :: Head => self . buf . push_str ( "</th>" ) ,
206- TableState :: Body => self . buf . push_str ( "</td>" ) ,
207- }
208- self . table_cell_index += 1 ;
209- }
210- Tag :: BlockQuote => self . buf . push_str ( "</blockquote>\n " ) ,
211- Tag :: CodeBlock ( _) => self . buf . push_str ( "</code></pre>\n " ) ,
212- Tag :: List ( Some ( _) ) => self . buf . push_str ( "</ol>\n " ) ,
213- Tag :: List ( None ) => self . buf . push_str ( "</ul>\n " ) ,
214- Tag :: Item => self . buf . push_str ( "</li>\n " ) ,
215- Tag :: Emphasis => self . buf . push_str ( "</em>" ) ,
216- Tag :: Strong => self . buf . push_str ( "</strong>" ) ,
217- Tag :: Code => self . buf . push_str ( "</code>" ) ,
106+ Tag :: Header ( level) => self . buf . push_str ( "</big>" ) ,
107+ Tag :: CodeBlock ( _) => self . buf . push_str ( "</tt>\n " ) ,
108+ Tag :: Emphasis => self . buf . push_str ( "</i>" ) ,
109+ Tag :: Strong => self . buf . push_str ( "</b>" ) ,
110+ Tag :: Code => self . buf . push_str ( "</tt>" ) ,
218111 Tag :: Link ( _, _) => self . buf . push_str ( "</a>" ) ,
219- Tag :: Image ( _, _) => ( ) , // shouldn't happen, handled in start
220- Tag :: FootnoteDefinition ( _) => self . buf . push_str ( "</div>\n " ) ,
112+ _ => ( )
221113 }
222114 }
223115
0 commit comments