Skip to content

Commit 7c26590

Browse files
author
tjk
committed
Update docs to reflect new push_html signature
1 parent 582973c commit 7c26590

File tree

7 files changed

+374
-184
lines changed

7 files changed

+374
-184
lines changed

lib/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ Here's a simple example of converting Markdown to HTML using default settings:
3131

3232
```rust
3333
use pulldown_html_ext::{HtmlConfig, push_html};
34+
use pulldown_cmark::Parser;
3435

3536
let config = HtmlConfig::default();
3637
let markdown = "# Hello\nThis is *markdown*";
37-
let html = push_html(markdown, &config);
38+
let mut output = String::new();
39+
let parser = Parser::new(markdown);
40+
let html = push_html(&mut output, parser, &config);
3841
```
3942

4043
## Configuration

lib/docs/examples/basic-usage.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ This guide provides practical examples of common use cases for `pulldown-html-ex
77
Convert a basic Markdown document to HTML:
88

99
```rust
10+
use pulldown_cmark::Parser;
1011
use pulldown_html_ext::{HtmlConfig, push_html};
1112

1213
fn main() -> Result<(), Box<dyn std::error::Error>> {
14+
// Create configuration
1315
let config = HtmlConfig::default();
1416

1517
let markdown = r#"
@@ -38,8 +40,13 @@ fn main() {
3840
```
3941
"#;
4042

41-
let html = push_html(markdown, &config)?;
42-
println!("{}", html);
43+
// Create parser
44+
let parser = Parser::new(markdown);
45+
let mut output = String::new();
46+
47+
// Convert to HTML
48+
push_html(&mut output, parser, &config)?;
49+
println!("{}", output);
4350
Ok(())
4451
}
4552
```
@@ -51,19 +58,21 @@ Read from and write to files:
5158
```rust
5259
use std::fs::File;
5360
use std::io::Read;
61+
use pulldown_cmark::Parser;
5462
use pulldown_html_ext::{HtmlConfig, write_html_io};
5563

5664
fn convert_file(input: &str, output: &str) -> Result<(), Box<dyn std::error::Error>> {
5765
// Read markdown file
5866
let mut markdown = String::new();
5967
File::open(input)?.read_to_string(&mut markdown)?;
6068

61-
// Set up config
69+
// Set up config and parser
6270
let config = HtmlConfig::default();
71+
let parser = Parser::new(&markdown);
6372

6473
// Write HTML to file
6574
let output_file = File::create(output)?;
66-
write_html_io(output_file, &markdown, &config)?;
75+
write_html_io(output_file, parser, &config)?;
6776

6877
Ok(())
6978
}
@@ -80,11 +89,14 @@ fn main() {
8089
Integrate with an HTML template:
8190

8291
```rust
92+
use pulldown_cmark::Parser;
8393
use pulldown_html_ext::{HtmlConfig, push_html};
8494

8595
fn generate_page(title: &str, content: &str) -> Result<String, Box<dyn std::error::Error>> {
8696
let config = HtmlConfig::default();
87-
let html_content = push_html(content, &config)?;
97+
let parser = Parser::new(content);
98+
let mut html_content = String::new();
99+
push_html(&mut html_content, parser, &config)?;
88100

89101
Ok(format!(
90102
r#"<!DOCTYPE html>
@@ -150,7 +162,8 @@ fn process_documents(
150162
let writer = DefaultHtmlWriter::new(FmtWriter(&mut output), &config);
151163
let mut renderer = create_html_renderer(writer);
152164

153-
renderer.run(Parser::new(&markdown))?;
165+
let parser = Parser::new(&markdown);
166+
renderer.run(parser)?;
154167
results.insert(name, output);
155168
}
156169

@@ -178,14 +191,17 @@ fn main() {
178191
Proper error handling example:
179192

180193
```rust
194+
use pulldown_cmark::Parser;
181195
use pulldown_html_ext::{HtmlConfig, HtmlError, push_html};
182196
use std::error::Error;
183197

184198
fn process_markdown(markdown: &str) -> Result<String, Box<dyn Error>> {
185199
let config = HtmlConfig::default();
200+
let parser = Parser::new(markdown);
201+
let mut output = String::new();
186202

187-
match push_html(markdown, &config) {
188-
Ok(html) => Ok(html),
203+
match push_html(&mut output, parser, &config) {
204+
Ok(()) => Ok(output),
189205
Err(HtmlError::Config(e)) => Err(format!("Configuration error: {}", e).into()),
190206
Err(HtmlError::Render(e)) => Err(format!("Rendering error: {}", e).into()),
191207
Err(HtmlError::Theme(e)) => Err(format!("Theme error: {}", e).into()),

lib/docs/examples/custom-config.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This guide provides practical examples of customizing the HTML output using vari
77
Add custom attributes to specific HTML elements:
88

99
```rust
10+
use pulldown_cmark::Parser;
1011
use pulldown_html_ext::{HtmlConfig, push_html};
1112
use std::collections::HashMap;
1213

@@ -32,8 +33,11 @@ Some content
3233
More content
3334
"#;
3435

35-
let html = push_html(markdown, &config)?;
36-
println!("{}", html);
36+
let parser = Parser::new(markdown);
37+
let mut output = String::new();
38+
push_html(&mut output, parser, &config)?;
39+
40+
println!("{}", output);
3741
Ok(())
3842
}
3943
```
@@ -43,6 +47,7 @@ More content
4347
Configure heading IDs and classes:
4448

4549
```rust
50+
use pulldown_cmark::Parser;
4651
use pulldown_html_ext::{HtmlConfig, push_html};
4752
use std::collections::HashMap;
4853

@@ -66,8 +71,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6671
### Subsection
6772
"#;
6873

69-
let html = push_html(markdown, &config)?;
70-
println!("{}", html);
74+
let parser = Parser::new(markdown);
75+
let mut output = String::new();
76+
push_html(&mut output, parser, &config)?;
77+
78+
println!("{}", output);
7179
Ok(())
7280
}
7381
```
@@ -77,6 +85,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7785
Customize link handling:
7886

7987
```rust
88+
use pulldown_cmark::Parser;
8089
use pulldown_html_ext::{HtmlConfig, push_html};
8190

8291
fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -94,8 +103,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
94103
- [Another Internal](/about)
95104
"#;
96105

97-
let html = push_html(markdown, &config)?;
98-
println!("{}", html);
106+
let parser = Parser::new(markdown);
107+
let mut output = String::new();
108+
push_html(&mut output, parser, &config)?;
109+
110+
println!("{}", output);
99111
Ok(())
100112
}
101113
```
@@ -105,6 +117,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
105117
Customize code block rendering:
106118

107119
```rust
120+
use pulldown_cmark::Parser;
108121
use pulldown_html_ext::{HtmlConfig, push_html};
109122

110123
fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -129,8 +142,11 @@ def greet(name):
129142
```
130143
"#;
131144

132-
let html = push_html(markdown, &config)?;
133-
println!("{}", html);
145+
let parser = Parser::new(markdown);
146+
let mut output = String::new();
147+
push_html(&mut output, parser, &config)?;
148+
149+
println!("{}", output);
134150
Ok(())
135151
}
136152
```
@@ -140,6 +156,7 @@ def greet(name):
140156
Configure HTML output formatting:
141157

142158
```rust
159+
use pulldown_cmark::Parser;
143160
use pulldown_html_ext::{HtmlConfig, push_html};
144161

145162
fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -162,8 +179,11 @@ Line two
162179
<img src="test.jpg" alt="Test">
163180
"#;
164181

165-
let html = push_html(markdown, &config)?;
166-
println!("{}", html);
182+
let parser = Parser::new(markdown);
183+
let mut output = String::new();
184+
push_html(&mut output, parser, &config)?;
185+
186+
println!("{}", output);
167187
Ok(())
168188
}
169189
```
@@ -173,6 +193,7 @@ Line two
173193
Load configuration from a TOML file:
174194

175195
```rust
196+
use pulldown_cmark::Parser;
176197
use pulldown_html_ext::{HtmlConfig, push_html};
177198
use std::fs;
178199
use toml;
@@ -211,8 +232,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
211232
// Load and use config
212233
let config = load_config("config.toml")?;
213234
let markdown = "# Test\nSome content";
214-
let html = push_html(markdown, &config)?;
215-
println!("{}", html);
235+
236+
let parser = Parser::new(markdown);
237+
let mut output = String::new();
238+
push_html(&mut output, parser, &config)?;
239+
240+
println!("{}", output);
216241

217242
Ok(())
218243
}

0 commit comments

Comments
 (0)