2013-09-18 22:18:38 -07:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-10-03 10:24:40 -07:00
|
|
|
//! Markdown formatting for rustdoc
|
|
|
|
//!
|
|
|
|
//! This module implements markdown formatting through the sundown C-library
|
|
|
|
//! (bundled into the rust runtime). This module self-contains the C bindings
|
|
|
|
//! and necessary legwork to render markdown, and exposes all of the
|
|
|
|
//! functionality through a unit-struct, `Markdown`, which has an implementation
|
2014-01-30 00:46:37 +11:00
|
|
|
//! of `fmt::Show`. Example usage:
|
2013-10-03 10:24:40 -07:00
|
|
|
//!
|
2014-01-24 21:00:31 -08:00
|
|
|
//! ```rust,ignore
|
|
|
|
//! use rustdoc::html::markdown::Markdown;
|
|
|
|
//!
|
2013-10-03 10:24:40 -07:00
|
|
|
//! let s = "My *markdown* _text_";
|
|
|
|
//! let html = format!("{}", Markdown(s));
|
|
|
|
//! // ... something using html
|
|
|
|
//! ```
|
|
|
|
|
2014-03-21 18:05:05 -07:00
|
|
|
#![allow(non_camel_case_types)]
|
2014-02-10 15:36:31 +01:00
|
|
|
|
2013-12-22 11:23:04 -08:00
|
|
|
use std::cast;
|
2013-09-18 22:18:38 -07:00
|
|
|
use std::fmt;
|
2013-11-10 22:46:32 -08:00
|
|
|
use std::io;
|
2013-12-22 11:23:04 -08:00
|
|
|
use std::libc;
|
2014-03-04 11:24:20 -08:00
|
|
|
use std::local_data;
|
2014-02-08 02:46:55 -08:00
|
|
|
use std::mem;
|
2013-12-22 11:23:04 -08:00
|
|
|
use std::str;
|
2014-03-08 18:11:52 -05:00
|
|
|
use std::slice;
|
2014-03-04 11:24:20 -08:00
|
|
|
use collections::HashMap;
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2014-03-08 01:13:17 +11:00
|
|
|
use html::toc::TocBuilder;
|
2014-02-20 01:14:51 -08:00
|
|
|
use html::highlight;
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
/// A unit struct which has the `fmt::Show` trait implemented. When
|
2013-10-03 10:24:40 -07:00
|
|
|
/// formatted, this struct will emit the HTML corresponding to the rendered
|
|
|
|
/// version of the contained markdown string.
|
2014-03-31 19:01:01 -07:00
|
|
|
pub struct Markdown<'a>(pub &'a str);
|
2014-03-08 01:13:17 +11:00
|
|
|
/// A unit struct like `Markdown`, that renders the markdown with a
|
|
|
|
/// table of contents.
|
2014-03-31 19:01:01 -07:00
|
|
|
pub struct MarkdownWithToc<'a>(pub &'a str);
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2013-09-23 16:55:48 -07:00
|
|
|
static OUTPUT_UNIT: libc::size_t = 64;
|
2013-09-23 17:52:57 -07:00
|
|
|
static MKDEXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 0;
|
|
|
|
static MKDEXT_TABLES: libc::c_uint = 1 << 1;
|
|
|
|
static MKDEXT_FENCED_CODE: libc::c_uint = 1 << 2;
|
|
|
|
static MKDEXT_AUTOLINK: libc::c_uint = 1 << 3;
|
|
|
|
static MKDEXT_STRIKETHROUGH: libc::c_uint = 1 << 4;
|
2013-09-23 16:55:48 -07:00
|
|
|
|
|
|
|
type sd_markdown = libc::c_void; // this is opaque to us
|
|
|
|
|
2013-12-22 11:23:04 -08:00
|
|
|
struct sd_callbacks {
|
2014-03-04 11:24:20 -08:00
|
|
|
blockcode: Option<extern "C" fn(*buf, *buf, *buf, *libc::c_void)>,
|
|
|
|
blockquote: Option<extern "C" fn(*buf, *buf, *libc::c_void)>,
|
|
|
|
blockhtml: Option<extern "C" fn(*buf, *buf, *libc::c_void)>,
|
|
|
|
header: Option<extern "C" fn(*buf, *buf, libc::c_int, *libc::c_void)>,
|
|
|
|
other: [libc::size_t, ..22],
|
2013-12-22 11:23:04 -08:00
|
|
|
}
|
2013-09-23 16:55:48 -07:00
|
|
|
|
|
|
|
struct html_toc_data {
|
|
|
|
header_count: libc::c_int,
|
|
|
|
current_level: libc::c_int,
|
|
|
|
level_offset: libc::c_int,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct html_renderopt {
|
|
|
|
toc_data: html_toc_data,
|
|
|
|
flags: libc::c_uint,
|
|
|
|
link_attributes: Option<extern "C" fn(*buf, *buf, *libc::c_void)>,
|
|
|
|
}
|
|
|
|
|
2013-12-22 11:23:04 -08:00
|
|
|
struct my_opaque {
|
|
|
|
opt: html_renderopt,
|
|
|
|
dfltblk: extern "C" fn(*buf, *buf, *buf, *libc::c_void),
|
2014-03-08 01:13:17 +11:00
|
|
|
toc_builder: Option<TocBuilder>,
|
2013-12-22 11:23:04 -08:00
|
|
|
}
|
|
|
|
|
2013-09-23 16:55:48 -07:00
|
|
|
struct buf {
|
|
|
|
data: *u8,
|
|
|
|
size: libc::size_t,
|
|
|
|
asize: libc::size_t,
|
|
|
|
unit: libc::size_t,
|
|
|
|
}
|
|
|
|
|
|
|
|
// sundown FFI
|
Add generation of static libraries to rustc
This commit implements the support necessary for generating both intermediate
and result static rust libraries. This is an implementation of my thoughts in
https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html.
When compiling a library, we still retain the "lib" option, although now there
are "rlib", "staticlib", and "dylib" as options for crate_type (and these are
stackable). The idea of "lib" is to generate the "compiler default" instead of
having too choose (although all are interchangeable). For now I have left the
"complier default" to be a dynamic library for size reasons.
Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an
rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a
dynamic object. I chose this for size reasons, but also because you're probably
not going to be embedding the rustc compiler anywhere any time soon.
Other than the options outlined above, there are a few defaults/preferences that
are now opinionated in the compiler:
* If both a .dylib and .rlib are found for a rust library, the compiler will
prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option
* If generating a "lib", the compiler will generate a dynamic library. This is
overridable by explicitly saying what flavor you'd like (rlib, staticlib,
dylib).
* If no options are passed to the command line, and no crate_type is found in
the destination crate, then an executable is generated
With this change, you can successfully build a rust program with 0 dynamic
dependencies on rust libraries. There is still a dynamic dependency on
librustrt, but I plan on removing that in a subsequent commit.
This change includes no tests just yet. Our current testing
infrastructure/harnesses aren't very amenable to doing flavorful things with
linking, so I'm planning on adding a new mode of testing which I believe belongs
as a separate commit.
Closes #552
2013-11-15 14:03:29 -08:00
|
|
|
#[link(name = "sundown", kind = "static")]
|
2013-09-23 16:55:48 -07:00
|
|
|
extern {
|
|
|
|
fn sdhtml_renderer(callbacks: *sd_callbacks,
|
|
|
|
options_ptr: *html_renderopt,
|
|
|
|
render_flags: libc::c_uint);
|
|
|
|
fn sd_markdown_new(extensions: libc::c_uint,
|
|
|
|
max_nesting: libc::size_t,
|
|
|
|
callbacks: *sd_callbacks,
|
|
|
|
opaque: *libc::c_void) -> *sd_markdown;
|
|
|
|
fn sd_markdown_render(ob: *buf,
|
|
|
|
document: *u8,
|
|
|
|
doc_size: libc::size_t,
|
|
|
|
md: *sd_markdown);
|
|
|
|
fn sd_markdown_free(md: *sd_markdown);
|
|
|
|
|
|
|
|
fn bufnew(unit: libc::size_t) -> *buf;
|
2014-02-20 01:14:51 -08:00
|
|
|
fn bufputs(b: *buf, c: *libc::c_char);
|
2013-09-23 16:55:48 -07:00
|
|
|
fn bufrelease(b: *buf);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-30 16:31:24 +11:00
|
|
|
/// Returns Some(code) if `s` is a line that should be stripped from
|
|
|
|
/// documentation but used in example code. `code` is the portion of
|
|
|
|
/// `s` that should be used in tests. (None for lines that should be
|
|
|
|
/// left as-is.)
|
|
|
|
fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> {
|
|
|
|
let trimmed = s.trim();
|
|
|
|
if trimmed.starts_with("# ") {
|
|
|
|
Some(trimmed.slice_from(2))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 11:24:20 -08:00
|
|
|
local_data_key!(used_header_map: HashMap<~str, uint>)
|
|
|
|
|
2014-03-08 01:13:17 +11:00
|
|
|
pub fn render(w: &mut io::Writer, s: &str, print_toc: bool) -> fmt::Result {
|
2013-12-22 11:23:04 -08:00
|
|
|
extern fn block(ob: *buf, text: *buf, lang: *buf, opaque: *libc::c_void) {
|
|
|
|
unsafe {
|
|
|
|
let my_opaque: &my_opaque = cast::transmute(opaque);
|
2014-03-08 18:11:52 -05:00
|
|
|
slice::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
|
2013-12-23 17:30:49 +01:00
|
|
|
let text = str::from_utf8(text).unwrap();
|
2013-12-30 16:31:24 +11:00
|
|
|
let mut lines = text.lines().filter(|l| stripped_filtered_line(*l).is_none());
|
2014-03-22 19:18:37 -04:00
|
|
|
let text = lines.collect::<~[&str]>().connect("\n");
|
2013-12-22 11:23:04 -08:00
|
|
|
|
|
|
|
let buf = buf {
|
|
|
|
data: text.as_bytes().as_ptr(),
|
|
|
|
size: text.len() as libc::size_t,
|
|
|
|
asize: text.len() as libc::size_t,
|
|
|
|
unit: 0,
|
|
|
|
};
|
2014-02-20 01:14:51 -08:00
|
|
|
let rendered = if lang.is_null() {
|
|
|
|
false
|
|
|
|
} else {
|
2014-03-08 18:11:52 -05:00
|
|
|
slice::raw::buf_as_slice((*lang).data,
|
2014-02-20 01:14:51 -08:00
|
|
|
(*lang).size as uint, |rlang| {
|
|
|
|
let rlang = str::from_utf8(rlang).unwrap();
|
|
|
|
if rlang.contains("notrust") {
|
|
|
|
(my_opaque.dfltblk)(ob, &buf, lang, opaque);
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
if !rendered {
|
2014-03-02 13:30:28 +11:00
|
|
|
let output = highlight::highlight(text, None).to_c_str();
|
2014-02-20 01:14:51 -08:00
|
|
|
output.with_ref(|r| {
|
|
|
|
bufputs(ob, r)
|
|
|
|
})
|
|
|
|
}
|
2013-12-22 11:23:04 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 11:24:20 -08:00
|
|
|
extern fn header(ob: *buf, text: *buf, level: libc::c_int,
|
2014-03-08 01:13:17 +11:00
|
|
|
opaque: *libc::c_void) {
|
2014-03-04 11:24:20 -08:00
|
|
|
// sundown does this, we may as well too
|
|
|
|
"\n".with_c_str(|p| unsafe { bufputs(ob, p) });
|
|
|
|
|
|
|
|
// Extract the text provided
|
|
|
|
let s = if text.is_null() {
|
|
|
|
~""
|
|
|
|
} else {
|
|
|
|
unsafe {
|
|
|
|
str::raw::from_buf_len((*text).data, (*text).size as uint)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Transform the contents of the header into a hyphenated string
|
|
|
|
let id = s.words().map(|s| {
|
|
|
|
match s.to_ascii_opt() {
|
|
|
|
Some(s) => s.to_lower().into_str(),
|
|
|
|
None => s.to_owned()
|
|
|
|
}
|
2014-03-22 19:18:37 -04:00
|
|
|
}).collect::<~[~str]>().connect("-");
|
2014-03-04 11:24:20 -08:00
|
|
|
|
2014-03-08 01:13:17 +11:00
|
|
|
let opaque = unsafe {&mut *(opaque as *mut my_opaque)};
|
|
|
|
|
2014-03-04 11:24:20 -08:00
|
|
|
// Make sure our hyphenated ID is unique for this page
|
|
|
|
let id = local_data::get_mut(used_header_map, |map| {
|
|
|
|
let map = map.unwrap();
|
|
|
|
match map.find_mut(&id) {
|
|
|
|
None => {}
|
|
|
|
Some(a) => { *a += 1; return format!("{}-{}", id, *a - 1) }
|
|
|
|
}
|
|
|
|
map.insert(id.clone(), 1);
|
|
|
|
id.clone()
|
|
|
|
});
|
|
|
|
|
2014-03-08 01:13:17 +11:00
|
|
|
let sec = match opaque.toc_builder {
|
|
|
|
Some(ref mut builder) => {
|
|
|
|
builder.push(level as u32, s.clone(), id.clone())
|
|
|
|
}
|
|
|
|
None => {""}
|
|
|
|
};
|
|
|
|
|
2014-03-04 11:24:20 -08:00
|
|
|
// Render the HTML
|
2014-03-12 23:09:03 +11:00
|
|
|
let text = format!(r#"<h{lvl} id="{id}" class='section-link'><a
|
2014-03-08 01:24:54 +11:00
|
|
|
href="\#{id}">{sec_len,plural,=0{}other{{sec} }}{}</a></h{lvl}>"#,
|
2014-03-08 01:13:17 +11:00
|
|
|
s, lvl = level, id = id,
|
|
|
|
sec_len = sec.len(), sec = sec);
|
|
|
|
|
2014-03-04 11:24:20 -08:00
|
|
|
text.with_c_str(|p| unsafe { bufputs(ob, p) });
|
|
|
|
}
|
|
|
|
|
2013-09-23 16:55:48 -07:00
|
|
|
// This code is all lifted from examples/sundown.c in the sundown repo
|
|
|
|
unsafe {
|
|
|
|
let ob = bufnew(OUTPUT_UNIT);
|
2013-09-23 17:52:57 -07:00
|
|
|
let extensions = MKDEXT_NO_INTRA_EMPHASIS | MKDEXT_TABLES |
|
|
|
|
MKDEXT_FENCED_CODE | MKDEXT_AUTOLINK |
|
|
|
|
MKDEXT_STRIKETHROUGH;
|
2013-09-23 16:55:48 -07:00
|
|
|
let options = html_renderopt {
|
|
|
|
toc_data: html_toc_data {
|
|
|
|
header_count: 0,
|
|
|
|
current_level: 0,
|
|
|
|
level_offset: 0,
|
|
|
|
},
|
|
|
|
flags: 0,
|
|
|
|
link_attributes: None,
|
|
|
|
};
|
2014-02-08 02:46:55 -08:00
|
|
|
let mut callbacks: sd_callbacks = mem::init();
|
2013-09-23 16:55:48 -07:00
|
|
|
|
|
|
|
sdhtml_renderer(&callbacks, &options, 0);
|
2014-03-08 01:13:17 +11:00
|
|
|
let mut opaque = my_opaque {
|
2013-12-22 11:23:04 -08:00
|
|
|
opt: options,
|
2014-03-04 11:24:20 -08:00
|
|
|
dfltblk: callbacks.blockcode.unwrap(),
|
2014-03-08 01:13:17 +11:00
|
|
|
toc_builder: if print_toc {Some(TocBuilder::new())} else {None}
|
2013-12-22 11:23:04 -08:00
|
|
|
};
|
2014-03-04 11:24:20 -08:00
|
|
|
callbacks.blockcode = Some(block);
|
|
|
|
callbacks.header = Some(header);
|
2013-09-23 17:52:57 -07:00
|
|
|
let markdown = sd_markdown_new(extensions, 16, &callbacks,
|
2014-03-08 01:13:17 +11:00
|
|
|
&mut opaque as *mut my_opaque as *libc::c_void);
|
2013-09-23 16:55:48 -07:00
|
|
|
|
2013-12-18 02:37:30 +11:00
|
|
|
|
|
|
|
sd_markdown_render(ob, s.as_ptr(), s.len() as libc::size_t, markdown);
|
2013-09-23 16:55:48 -07:00
|
|
|
sd_markdown_free(markdown);
|
|
|
|
|
2014-03-08 01:13:17 +11:00
|
|
|
let mut ret = match opaque.toc_builder {
|
|
|
|
Some(b) => write!(w, "<nav id=\"TOC\">{}</nav>", b.into_toc()),
|
|
|
|
None => Ok(())
|
|
|
|
};
|
2013-09-23 16:55:48 -07:00
|
|
|
|
2014-03-08 01:13:17 +11:00
|
|
|
if ret.is_ok() {
|
2014-03-08 18:11:52 -05:00
|
|
|
ret = slice::raw::buf_as_slice((*ob).data, (*ob).size as uint, |buf| {
|
2014-03-08 01:13:17 +11:00
|
|
|
w.write(buf)
|
|
|
|
});
|
|
|
|
}
|
2013-09-23 16:55:48 -07:00
|
|
|
bufrelease(ob);
|
2014-01-30 11:30:21 -08:00
|
|
|
ret
|
2013-09-23 16:55:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-22 11:23:04 -08:00
|
|
|
pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
|
|
|
|
extern fn block(_ob: *buf, text: *buf, lang: *buf, opaque: *libc::c_void) {
|
|
|
|
unsafe {
|
2014-02-14 23:30:10 -08:00
|
|
|
if text.is_null() { return }
|
2014-03-08 19:39:01 -08:00
|
|
|
let (should_fail, no_run, ignore) = if lang.is_null() {
|
|
|
|
(false, false, false)
|
2014-02-14 23:30:10 -08:00
|
|
|
} else {
|
2014-03-08 18:11:52 -05:00
|
|
|
slice::raw::buf_as_slice((*lang).data,
|
2013-12-22 11:23:04 -08:00
|
|
|
(*lang).size as uint, |lang| {
|
2013-12-23 17:30:49 +01:00
|
|
|
let s = str::from_utf8(lang).unwrap();
|
2014-03-08 19:39:01 -08:00
|
|
|
(s.contains("should_fail"),
|
|
|
|
s.contains("no_run"),
|
|
|
|
s.contains("ignore") || s.contains("notrust"))
|
2014-02-14 23:30:10 -08:00
|
|
|
})
|
|
|
|
};
|
|
|
|
if ignore { return }
|
2014-03-08 18:11:52 -05:00
|
|
|
slice::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
|
2014-03-07 14:31:41 +11:00
|
|
|
let tests = &mut *(opaque as *mut ::test::Collector);
|
2013-12-23 17:30:49 +01:00
|
|
|
let text = str::from_utf8(text).unwrap();
|
2013-12-30 16:31:24 +11:00
|
|
|
let mut lines = text.lines().map(|l| stripped_filtered_line(l).unwrap_or(l));
|
2014-03-22 19:18:37 -04:00
|
|
|
let text = lines.collect::<~[&str]>().connect("\n");
|
2014-03-08 19:39:01 -08:00
|
|
|
tests.add_test(text, should_fail, no_run);
|
2013-12-22 11:23:04 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2014-03-07 14:31:41 +11:00
|
|
|
extern fn header(_ob: *buf, text: *buf, level: libc::c_int, opaque: *libc::c_void) {
|
|
|
|
unsafe {
|
|
|
|
let tests = &mut *(opaque as *mut ::test::Collector);
|
|
|
|
if text.is_null() {
|
|
|
|
tests.register_header("", level as u32);
|
|
|
|
} else {
|
2014-03-08 18:11:52 -05:00
|
|
|
slice::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
|
2014-03-07 14:31:41 +11:00
|
|
|
let text = str::from_utf8(text).unwrap();
|
|
|
|
tests.register_header(text, level as u32);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-22 11:23:04 -08:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let ob = bufnew(OUTPUT_UNIT);
|
|
|
|
let extensions = MKDEXT_NO_INTRA_EMPHASIS | MKDEXT_TABLES |
|
|
|
|
MKDEXT_FENCED_CODE | MKDEXT_AUTOLINK |
|
|
|
|
MKDEXT_STRIKETHROUGH;
|
|
|
|
let callbacks = sd_callbacks {
|
2014-03-04 11:24:20 -08:00
|
|
|
blockcode: Some(block),
|
|
|
|
blockquote: None,
|
|
|
|
blockhtml: None,
|
2014-03-07 14:31:41 +11:00
|
|
|
header: Some(header),
|
2014-02-08 02:46:55 -08:00
|
|
|
other: mem::init()
|
2013-12-22 11:23:04 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
let tests = tests as *mut ::test::Collector as *libc::c_void;
|
|
|
|
let markdown = sd_markdown_new(extensions, 16, &callbacks, tests);
|
|
|
|
|
|
|
|
sd_markdown_render(ob, doc.as_ptr(), doc.len() as libc::size_t,
|
|
|
|
markdown);
|
|
|
|
sd_markdown_free(markdown);
|
|
|
|
bufrelease(ob);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 11:24:20 -08:00
|
|
|
/// By default this markdown renderer generates anchors for each header in the
|
|
|
|
/// rendered document. The anchor name is the contents of the header spearated
|
|
|
|
/// by hyphens, and a task-local map is used to disambiguate among duplicate
|
|
|
|
/// headers (numbers are appended).
|
|
|
|
///
|
|
|
|
/// This method will reset the local table for these headers. This is typically
|
|
|
|
/// used at the beginning of rendering an entire HTML page to reset from the
|
|
|
|
/// previous state (if any).
|
|
|
|
pub fn reset_headers() {
|
|
|
|
local_data::set(used_header_map, HashMap::new())
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:46:37 +11:00
|
|
|
impl<'a> fmt::Show for Markdown<'a> {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let Markdown(md) = *self;
|
2013-09-23 16:55:48 -07:00
|
|
|
// This is actually common enough to special-case
|
2014-01-30 11:30:21 -08:00
|
|
|
if md.len() == 0 { return Ok(()) }
|
2014-03-08 01:13:17 +11:00
|
|
|
render(fmt.buf, md.as_slice(), false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> fmt::Show for MarkdownWithToc<'a> {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let MarkdownWithToc(md) = *self;
|
|
|
|
render(fmt.buf, md.as_slice(), true)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|