Skip to content

Commit 9dcc58c

Browse files
committed
Fix links in markdown rendering
1 parent 807aa0c commit 9dcc58c

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

example/cppdoc.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ compiler_arguments = ["-Iinclude", "-std=gnu++20", "-xc++"]
88

99
[pages]
1010
index = "README.md"
11-
extra = ["extra-pages/getting_started.md"]
11+
extra = ["extra-pages/extra-page.md"]
1212

1313
[output]
1414
static_dir = "static"
File renamed without changes.

src/main.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn main() {
110110

111111
let mut doctests = Vec::new();
112112

113-
render::process_namespace(root_namespace, &output.index, &mut doctests);
113+
render::process_namespace(root_namespace, &output.index, &mut doctests, &config);
114114

115115
let index = match config.pages.index {
116116
Some(ref x) => std::fs::read_to_string(x).unwrap(),
@@ -120,7 +120,8 @@ fn main() {
120120
},
121121
};
122122

123-
let index_html = render::process_markdown(&index, &output.index, &mut doctests);
123+
let index_html =
124+
render::process_markdown(&index, &output.index, &mut doctests, &config);
124125

125126
let mut extra_pages = Vec::new();
126127

@@ -133,7 +134,8 @@ fn main() {
133134
}
134135
};
135136

136-
let mut page = render::process_markdown(&page_source, &output.index, &mut doctests);
137+
let mut page =
138+
render::process_markdown(&page_source, &output.index, &mut doctests, &config);
137139

138140
if page.title.is_empty() {
139141
page.title = page_path.split("/").last().unwrap().to_string();

src/render.rs

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::config::Config;
12
use crate::doctest;
23
use crate::parser;
34

@@ -47,6 +48,7 @@ pub fn process_markdown(
4748
input: &str,
4849
index: &HashMap<String, String>,
4950
doctests: &mut Vec<doctest::Doctest>,
51+
config: &Config,
5052
) -> Page {
5153
let mut code = String::new();
5254
let mut in_code_block = false;
@@ -146,7 +148,9 @@ pub fn process_markdown(
146148
let real = get_path_for_name(url, index);
147149

148150
if let Some(real) = real {
149-
return Some(Event::Html(format!("<a href=\"/{}.html\">", real).into()));
151+
return Some(Event::Html(
152+
format!("<a href=\"{}/{}.html\">", config.output.base_url, real).into(),
153+
));
150154
}
151155
}
152156
}
@@ -177,66 +181,74 @@ pub fn process_function(
177181
func: &mut parser::Function,
178182
index: &HashMap<String, String>,
179183
doctests: &mut Vec<doctest::Doctest>,
184+
config: &Config,
180185
) {
181186
if let Some(ref mut comment) = &mut func.comment {
182-
comment.brief = process_markdown(&comment.brief, index, doctests).content;
183-
comment.description = process_markdown(&comment.description, index, doctests).content;
187+
comment.brief = process_markdown(&comment.brief, index, doctests, config).content;
188+
comment.description =
189+
process_markdown(&comment.description, index, doctests, config).content;
184190
}
185191
}
186192

187193
pub fn process_enum(
188194
enm: &mut parser::Enum,
189195
index: &HashMap<String, String>,
190196
doctests: &mut Vec<doctest::Doctest>,
197+
config: &Config,
191198
) {
192199
if let Some(ref mut comment) = &mut enm.comment {
193-
comment.brief = process_markdown(&comment.brief, index, doctests).content;
194-
comment.description = process_markdown(&comment.description, index, doctests).content;
200+
comment.brief = process_markdown(&comment.brief, index, doctests, config).content;
201+
comment.description =
202+
process_markdown(&comment.description, index, doctests, config).content;
195203
}
196204
}
197205

198206
pub fn process_record(
199207
record: &mut parser::Record,
200208
index: &HashMap<String, String>,
201209
doctests: &mut Vec<doctest::Doctest>,
210+
config: &Config,
202211
) {
203212
if let Some(ref mut comment) = &mut record.comment {
204-
comment.brief = process_markdown(&comment.brief, index, doctests).content;
205-
comment.description = process_markdown(&comment.description, index, doctests).content;
213+
comment.brief = process_markdown(&comment.brief, index, doctests, config).content;
214+
comment.description =
215+
process_markdown(&comment.description, index, doctests, config).content;
206216
}
207217

208218
for method in &mut record.methods {
209-
process_function(method, index, doctests);
219+
process_function(method, index, doctests, config);
210220
}
211221

212222
for ctor in &mut record.ctor {
213-
process_function(ctor, index, doctests);
223+
process_function(ctor, index, doctests, config);
214224
}
215225
}
216226

217227
pub fn process_namespace(
218228
namespace: &mut parser::Namespace,
219229
index: &HashMap<String, String>,
220230
doctests: &mut Vec<doctest::Doctest>,
231+
config: &Config,
221232
) {
222233
if let Some(ref mut comment) = &mut namespace.comment {
223-
comment.brief = process_markdown(&comment.brief, index, doctests).content;
224-
comment.description = process_markdown(&comment.description, index, doctests).content;
234+
comment.brief = process_markdown(&comment.brief, index, doctests, config).content;
235+
comment.description =
236+
process_markdown(&comment.description, index, doctests, config).content;
225237
}
226238

227239
for func in &mut namespace.functions {
228-
process_function(func, index, doctests);
240+
process_function(func, index, doctests, config);
229241
}
230242

231243
for record in &mut namespace.records {
232-
process_record(record, index, doctests);
244+
process_record(record, index, doctests, config);
233245
}
234246

235247
for enm in &mut namespace.enums {
236-
process_enum(enm, index, doctests);
248+
process_enum(enm, index, doctests, config);
237249
}
238250

239251
for ns in &mut namespace.namespaces {
240-
process_namespace(ns, index, doctests);
252+
process_namespace(ns, index, doctests, config);
241253
}
242254
}

0 commit comments

Comments
 (0)