1212//!
1313//! let s = "My *markdown* _text_";
1414//! let mut id_map = IdMap::new();
15- //! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None, 0);
15+ //! let md = Markdown {
16+ //! content: s,
17+ //! links: &[],
18+ //! ids: &mut id_map,
19+ //! error_codes: ErrorCodes::Yes,
20+ //! edition: Edition::Edition2015,
21+ //! playground: &None,
22+ //! heading_level: 0
23+ //! };
1624//! let html = md.into_string();
1725//! // ... something using html
1826//! ```
@@ -69,19 +77,21 @@ pub(crate) fn summary_opts() -> Options {
6977
7078/// When `to_string` is called, this struct will emit the HTML corresponding to
7179/// the rendered version of the contained markdown string.
72- pub struct Markdown < ' a > (
73- pub & ' a str ,
80+ pub struct Markdown < ' a > {
81+ pub content : & ' a str ,
7482 /// A list of link replacements.
75- pub & ' a [ RenderedLink ] ,
83+ pub links : & ' a [ RenderedLink ] ,
7684 /// The current list of used header IDs.
77- pub & ' a mut IdMap ,
85+ pub ids : & ' a mut IdMap ,
7886 /// Whether to allow the use of explicit error codes in doctest lang strings.
79- pub ErrorCodes ,
87+ pub error_codes : ErrorCodes ,
8088 /// Default edition to use when parsing doctests (to add a `fn main`).
81- pub Edition ,
82- pub & ' a Option < Playground > ,
83- pub u32 ,
84- ) ;
89+ pub edition : Edition ,
90+ pub playground : & ' a Option < Playground > ,
91+ /// Offset at which we render headings.
92+ /// E.g. if `heading_level: 1`, then `# something` renders an `<h2>` instead of `<h1>`
93+ pub heading_level : u32 ,
94+ }
8595/// A tuple struct like `Markdown` that renders the markdown with a table of contents.
8696crate struct MarkdownWithToc < ' a > (
8797 crate & ' a str ,
@@ -1010,7 +1020,15 @@ impl LangString {
10101020
10111021impl Markdown < ' _ > {
10121022 pub fn into_string ( self ) -> String {
1013- let Markdown ( md, links, mut ids, codes, edition, playground, level) = self ;
1023+ let Markdown {
1024+ content : md,
1025+ links,
1026+ mut ids,
1027+ error_codes : codes,
1028+ edition,
1029+ playground,
1030+ heading_level,
1031+ } = self ;
10141032
10151033 // This is actually common enough to special-case
10161034 if md. is_empty ( ) {
@@ -1031,7 +1049,7 @@ impl Markdown<'_> {
10311049
10321050 let mut s = String :: with_capacity ( md. len ( ) * 3 / 2 ) ;
10331051
1034- let p = HeadingLinks :: new ( p, None , & mut ids, level ) ;
1052+ let p = HeadingLinks :: new ( p, None , & mut ids, heading_level ) ;
10351053 let p = Footnotes :: new ( p) ;
10361054 let p = LinkReplacer :: new ( p. map ( |( ev, _) | ev) , links) ;
10371055 let p = TableWrapper :: new ( p) ;
0 commit comments