@@ -49,6 +49,8 @@ pub struct Markdown<'a>(pub &'a str);
49
49
/// A unit struct like `Markdown`, that renders the markdown with a
50
50
/// table of contents.
51
51
pub struct MarkdownWithToc < ' a > ( pub & ' a str ) ;
52
+ /// A unit struct like `Markdown`, that renders the markdown escaping HTML tags.
53
+ pub struct MarkdownHtml < ' a > ( pub & ' a str ) ;
52
54
53
55
const DEF_OUNIT : libc:: size_t = 64 ;
54
56
const HOEDOWN_EXT_NO_INTRA_EMPHASIS : libc:: c_uint = 1 << 11 ;
@@ -58,6 +60,7 @@ const HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3;
58
60
const HOEDOWN_EXT_STRIKETHROUGH : libc:: c_uint = 1 << 4 ;
59
61
const HOEDOWN_EXT_SUPERSCRIPT : libc:: c_uint = 1 << 8 ;
60
62
const HOEDOWN_EXT_FOOTNOTES : libc:: c_uint = 1 << 2 ;
63
+ const HOEDOWN_HTML_ESCAPE : libc:: c_uint = 1 << 1 ;
61
64
62
65
const HOEDOWN_EXTENSIONS : libc:: c_uint =
63
66
HOEDOWN_EXT_NO_INTRA_EMPHASIS | HOEDOWN_EXT_TABLES |
@@ -220,7 +223,11 @@ thread_local!(pub static PLAYGROUND: RefCell<Option<(Option<String>, String)>> =
220
223
RefCell :: new( None )
221
224
} ) ;
222
225
223
- pub fn render ( w : & mut fmt:: Formatter , s : & str , print_toc : bool ) -> fmt:: Result {
226
+
227
+ pub fn render ( w : & mut fmt:: Formatter ,
228
+ s : & str ,
229
+ print_toc : bool ,
230
+ html_flags : libc:: c_uint ) -> fmt:: Result {
224
231
extern fn block ( ob : * mut hoedown_buffer , orig_text : * const hoedown_buffer ,
225
232
lang : * const hoedown_buffer , data : * const hoedown_renderer_data ) {
226
233
unsafe {
@@ -383,7 +390,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
383
390
384
391
unsafe {
385
392
let ob = hoedown_buffer_new ( DEF_OUNIT ) ;
386
- let renderer = hoedown_html_renderer_new ( 0 , 0 ) ;
393
+ let renderer = hoedown_html_renderer_new ( html_flags , 0 ) ;
387
394
let mut opaque = MyOpaque {
388
395
dfltblk : ( * renderer) . blockcode . unwrap ( ) ,
389
396
toc_builder : if print_toc { Some ( TocBuilder :: new ( ) ) } else { None }
@@ -553,14 +560,23 @@ impl<'a> fmt::Display for Markdown<'a> {
553
560
let Markdown ( md) = * self ;
554
561
// This is actually common enough to special-case
555
562
if md. is_empty ( ) { return Ok ( ( ) ) }
556
- render ( fmt, md, false )
563
+ render ( fmt, md, false , 0 )
557
564
}
558
565
}
559
566
560
567
impl < ' a > fmt:: Display for MarkdownWithToc < ' a > {
561
568
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
562
569
let MarkdownWithToc ( md) = * self ;
563
- render ( fmt, md, true )
570
+ render ( fmt, md, true , 0 )
571
+ }
572
+ }
573
+
574
+ impl < ' a > fmt:: Display for MarkdownHtml < ' a > {
575
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
576
+ let MarkdownHtml ( md) = * self ;
577
+ // This is actually common enough to special-case
578
+ if md. is_empty ( ) { return Ok ( ( ) ) }
579
+ render ( fmt, md, false , HOEDOWN_HTML_ESCAPE )
564
580
}
565
581
}
566
582
0 commit comments