Skip to content

Commit 6aba47a

Browse files
authored
fix: various html doc gen fixes for reference generation (#601)
1 parent ad9eccf commit 6aba47a

File tree

208 files changed

+2690
-1443
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+2690
-1443
lines changed

build_css.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ const pageFinal = transform({
2828
analyzeDependencies: false,
2929
});
3030
await Deno.writeFile("src/html/templates/pages/page.gen.css", pageFinal.code);
31+
32+
const reset =
33+
await $`deno run -A npm:tailwindcss@3.4.3 --input src/html/templates/pages/reset.css`
34+
.bytes();
35+
const resetFinal = transform({
36+
filename: "./page.css",
37+
code: reset,
38+
minify: true,
39+
targets: browserslistToTargets(browsers),
40+
analyzeDependencies: false,
41+
});
42+
await Deno.writeFile("src/html/templates/pages/reset.gen.css", resetFinal.code);

examples/ddoc/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ fn generate_docs_directory(
226226
usage_composer: None,
227227
rewrite_map: Some(index_map),
228228
composable_output: false,
229+
category_docs: None,
230+
disable_search: false,
231+
symbol_redirect_map: None,
232+
default_symbol_map: None,
229233
};
230234
let html = deno_doc::html::generate(options, doc_nodes_by_url)?;
231235

src/class.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl From<ClassPropertyDef> for DocNode {
128128
fn from(def: ClassPropertyDef) -> DocNode {
129129
DocNode::variable(
130130
def.name,
131+
false,
131132
def.location,
132133
DeclarationKind::Private,
133134
def.js_doc,
@@ -181,6 +182,7 @@ impl From<ClassMethodDef> for DocNode {
181182
fn from(def: ClassMethodDef) -> DocNode {
182183
DocNode::function(
183184
def.name,
185+
false,
184186
def.location,
185187
DeclarationKind::Private,
186188
def.js_doc,

src/html/comrak_adapters.rs

Lines changed: 100 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -232,66 +232,132 @@ pub struct ToCEntry {
232232
pub anchor: String,
233233
}
234234

235-
#[derive(Default, Clone)]
235+
#[derive(Debug)]
236+
pub struct ToCGroup {
237+
pub toc: Vec<ToCEntry>,
238+
pub id: Option<String>,
239+
}
240+
241+
#[derive(Clone)]
236242
pub struct HeadingToCAdapter {
237-
toc: Arc<Mutex<Vec<ToCEntry>>>,
243+
toc_groups: Arc<Mutex<Vec<ToCGroup>>>,
238244
anchorizer: Arc<Mutex<comrak::html::Anchorizer>>,
239245
offset: Arc<Mutex<u8>>,
240246
}
241247

248+
impl Default for HeadingToCAdapter {
249+
fn default() -> Self {
250+
Self {
251+
toc_groups: Arc::new(Mutex::new(vec![ToCGroup {
252+
toc: vec![],
253+
id: None,
254+
}])),
255+
anchorizer: Arc::new(Mutex::new(Default::default())),
256+
offset: Arc::new(Mutex::new(0)),
257+
}
258+
}
259+
}
260+
242261
impl HeadingToCAdapter {
243-
pub fn add_entry(&self, level: u8, content: String) -> String {
244-
let mut lock = self.toc.lock().unwrap();
262+
pub fn create_group(&self, id: String) {
263+
let mut toc_groups = self.toc_groups.lock().unwrap();
264+
265+
toc_groups.push(ToCGroup {
266+
toc: vec![],
267+
id: Some(id),
268+
});
269+
}
270+
271+
pub fn anchorize(&self, content: String) -> String {
245272
let mut anchorizer = self.anchorizer.lock().unwrap();
273+
anchorizer.anchorize(content.clone())
274+
}
275+
276+
pub fn add_entry(
277+
&self,
278+
level: u8,
279+
content: String,
280+
anchor: String,
281+
) -> String {
282+
let mut toc_groups = self.toc_groups.lock().unwrap();
246283
let mut offset = self.offset.lock().unwrap();
247284

248-
let anchor = anchorizer.anchorize(content.clone());
249285
*offset = level;
250286

251-
lock.push(ToCEntry {
252-
level,
253-
content,
254-
anchor: anchor.clone(),
255-
});
287+
let toc_group = toc_groups.last_mut().unwrap();
288+
289+
if toc_group
290+
.toc
291+
.last()
292+
.map_or(true, |toc| toc.content != content)
293+
{
294+
toc_group.toc.push(ToCEntry {
295+
level,
296+
content,
297+
anchor: anchor.clone(),
298+
});
299+
}
256300

257301
anchor
258302
}
259303

260-
pub fn into_toc(self) -> Vec<ToCEntry> {
261-
Arc::into_inner(self.toc).unwrap().into_inner().unwrap()
304+
pub fn into_toc(self) -> Vec<ToCGroup> {
305+
Arc::into_inner(self.toc_groups)
306+
.unwrap()
307+
.into_inner()
308+
.unwrap()
262309
}
263310

264311
pub fn render(self) -> Option<String> {
265-
let toc = Arc::into_inner(self.toc).unwrap().into_inner().unwrap();
312+
let toc_groups = Arc::into_inner(self.toc_groups)
313+
.unwrap()
314+
.into_inner()
315+
.unwrap();
266316

267-
if toc.is_empty() {
317+
if toc_groups.is_empty()
318+
|| (toc_groups.len() == 1 && toc_groups[0].toc.is_empty())
319+
{
268320
return None;
269321
}
270322

271-
let mut toc_content = vec![String::from(r#"<ul>"#)];
272-
273-
let mut current_level = 1;
323+
let mut toc_content = vec![];
274324

275-
for entry in toc {
276-
match current_level.cmp(&entry.level) {
277-
Ordering::Equal => {}
278-
Ordering::Less => {
279-
toc_content.push(r#"<li><ul>"#.to_string());
280-
current_level = entry.level;
281-
}
282-
Ordering::Greater => {
283-
toc_content.push("</ul></li>".to_string());
284-
current_level = entry.level;
285-
}
325+
for toc_group in toc_groups {
326+
if toc_group.toc.is_empty() {
327+
continue;
286328
}
287329

288330
toc_content.push(format!(
289-
r##"<li><a href="#{}" title="{}">{}</a></li>"##,
290-
entry.anchor, entry.content, entry.content
331+
r#"<ul{}>"#,
332+
toc_group
333+
.id
334+
.map(|id| format!(r#" id="{id}""#))
335+
.unwrap_or_default(),
291336
));
292-
}
293337

294-
toc_content.push(String::from("</ul>"));
338+
let mut current_level = 1;
339+
340+
for entry in toc_group.toc {
341+
match current_level.cmp(&entry.level) {
342+
Ordering::Equal => {}
343+
Ordering::Less => {
344+
toc_content.push(r#"<li><ul>"#.to_string());
345+
current_level = entry.level;
346+
}
347+
Ordering::Greater => {
348+
toc_content.push("</ul></li>".to_string());
349+
current_level = entry.level;
350+
}
351+
}
352+
353+
toc_content.push(format!(
354+
r##"<li><a href="#{}" title="{}">{}</a></li>"##,
355+
entry.anchor, entry.content, entry.content
356+
));
357+
}
358+
359+
toc_content.push(String::from("</ul>"));
360+
}
295361

296362
Some(toc_content.join(""))
297363
}
@@ -310,8 +376,8 @@ impl HeadingAdapter for HeadingToCAdapter {
310376
let anchor = anchorizer.anchorize(heading.content.clone());
311377
writeln!(output, r#"<h{} id="{anchor}">"#, heading.level)?;
312378

313-
let mut lock = self.toc.lock().unwrap();
314-
lock.push(ToCEntry {
379+
let mut lock = self.toc_groups.lock().unwrap();
380+
lock.last_mut().unwrap().toc.push(ToCEntry {
315381
level: heading.level + *offset,
316382
content: heading.content.clone(),
317383
anchor,

src/html/jsdoc.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn parse_links<'a>(md: &'a str, ctx: &RenderContext) -> Cow<'a, str> {
6262
.iter()
6363
.any(|node| node.get_qualified_name() == symbol_match.as_str())
6464
{
65-
link = ctx.ctx.href_resolver.resolve_path(
65+
link = ctx.ctx.resolve_path(
6666
ctx.get_current_resolve(),
6767
UrlResolveKind::Symbol {
6868
file: short_path,
@@ -78,7 +78,7 @@ fn parse_links<'a>(md: &'a str, ctx: &RenderContext) -> Cow<'a, str> {
7878
}
7979
}
8080
} else {
81-
link = ctx.ctx.href_resolver.resolve_path(
81+
link = ctx.ctx.resolve_path(
8282
ctx.get_current_resolve(),
8383
short_path.as_resolve_kind(),
8484
);
@@ -517,9 +517,9 @@ pub(crate) fn jsdoc_examples(
517517

518518
#[derive(Debug, Serialize, Clone)]
519519
pub struct ExampleCtx {
520-
anchor: AnchorCtx,
521-
id: String,
522-
markdown_title: String,
520+
pub anchor: AnchorCtx,
521+
pub id: String,
522+
pub markdown_title: String,
523523
markdown_body: String,
524524
}
525525

@@ -684,6 +684,10 @@ mod test {
684684
usage_composer: None,
685685
rewrite_map: None,
686686
composable_output: false,
687+
category_docs: None,
688+
disable_search: false,
689+
symbol_redirect_map: None,
690+
default_symbol_map: None,
687691
},
688692
Default::default(),
689693
Default::default(),
@@ -693,6 +697,7 @@ mod test {
693697
vec![
694698
DocNode::interface(
695699
"foo".to_string(),
700+
false,
696701
Location::default(),
697702
DeclarationKind::Export,
698703
JsDoc::default(),
@@ -709,6 +714,7 @@ mod test {
709714
),
710715
DocNode::interface(
711716
"bar".to_string(),
717+
false,
712718
Location::default(),
713719
DeclarationKind::Export,
714720
JsDoc::default(),
@@ -729,6 +735,7 @@ mod test {
729735
ModuleSpecifier::parse("file:///b.ts").unwrap(),
730736
vec![DocNode::interface(
731737
"baz".to_string(),
738+
false,
732739
Location::default(),
733740
DeclarationKind::Export,
734741
JsDoc::default(),
@@ -806,11 +813,11 @@ mod test {
806813

807814
assert_eq!(
808815
parse_links("foo {@link [b.ts]} bar", &render_ctx),
809-
"foo [b.ts](../../.././/b.ts/~/index.html) bar"
816+
"foo [b.ts](../../.././/b.ts/index.html) bar"
810817
);
811818
assert_eq!(
812819
parse_links("foo {@linkcode [b.ts]} bar", &render_ctx),
813-
"foo [`b.ts`](../../.././/b.ts/~/index.html) bar"
820+
"foo [`b.ts`](../../.././/b.ts/index.html) bar"
814821
);
815822

816823
assert_eq!(
@@ -834,6 +841,10 @@ mod test {
834841
usage_composer: None,
835842
rewrite_map: None,
836843
composable_output: false,
844+
category_docs: None,
845+
disable_search: false,
846+
symbol_redirect_map: None,
847+
default_symbol_map: None,
837848
},
838849
Default::default(),
839850
Default::default(),

0 commit comments

Comments
 (0)