diff --git a/packages/@winglang/wingc/src/generate_docs.rs b/packages/@winglang/wingc/src/generate_docs.rs index 68e286a8b6b..08523394dd9 100644 --- a/packages/@winglang/wingc/src/generate_docs.rs +++ b/packages/@winglang/wingc/src/generate_docs.rs @@ -156,7 +156,7 @@ fn generate_docs_helper(types: &Types, project_dir: &Utf8Path) -> Result panic!("Error in root env: {}", diag), }; - docs.push_str("

API Reference

\n\n"); + docs.push_str("## API Reference\n\n"); let mut public_types = vec![]; let namespaces = find_documentable_namespaces_recursive(&ns); @@ -220,7 +220,7 @@ fn simplified_fqn(typ: &TypeRef) -> String { } fn print_table_of_contents(types: &[TypeRef], docs: &mut String) { - docs.push_str("

Table of Contents

\n\n"); + docs.push_str("### Table of Contents\n\n"); let mut classes = vec![]; let mut interfaces = vec![]; @@ -287,19 +287,21 @@ fn print_table_of_contents(types: &[TypeRef], docs: &mut String) { fn print_classes(types: &[TypeRef], docs: &mut String) { for typ in types { if let Type::Class(ref class) = **typ { - docs.push_str("

"); + docs.push_str("### "); docs.push_str(&simplified_fqn(typ)); docs.push_str(" ("); docs.push_str(&class.phase.to_string()); - docs.push_str(" class)

\n\n"); + docs.push_str(" class) \n\n"); let docstring = class.docs.render(); if !docstring.is_empty() { docs.push_str(&docstring); - docs.push_str("\n\n"); + } else { + docs.push_str("*No description*"); } + docs.push_str("\n\n"); print_constructors(docs, class); print_properties(docs, class); @@ -311,17 +313,19 @@ fn print_classes(types: &[TypeRef], docs: &mut String) { fn print_interfaces(types: &[TypeRef], docs: &mut String) { for typ in types { if let Type::Interface(ref interface) = **typ { - docs.push_str("

"); + docs.push_str("### "); docs.push_str(&simplified_fqn(typ)); - docs.push_str(" (interface)

\n\n"); + docs.push_str(" (interface) \n\n"); let docstring = interface.docs.render(); if !docstring.is_empty() { docs.push_str(&docstring); - docs.push_str("\n\n"); + } else { + docs.push_str("*No description*"); } + docs.push_str("\n\n"); print_properties(docs, interface); print_methods(docs, interface); @@ -332,17 +336,19 @@ fn print_interfaces(types: &[TypeRef], docs: &mut String) { fn print_structs(types: &[TypeRef], docs: &mut String) { for typ in types { if let Type::Struct(ref struct_) = **typ { - docs.push_str("

"); + docs.push_str("### "); docs.push_str(&simplified_fqn(typ)); - docs.push_str(" (struct)

\n\n"); + docs.push_str(" (struct) \n\n"); let docstring = struct_.docs.render(); if !docstring.is_empty() { docs.push_str(&docstring); - docs.push_str("\n\n"); + } else { + docs.push_str("*No description*"); } + docs.push_str("\n\n"); print_properties(docs, struct_); } @@ -352,19 +358,21 @@ fn print_structs(types: &[TypeRef], docs: &mut String) { fn print_enums(types: &[TypeRef], docs: &mut String) { for typ in types { if let Type::Enum(ref enum_) = **typ { - docs.push_str("

"); + docs.push_str("### "); docs.push_str(&simplified_fqn(typ)); - docs.push_str(" (enum)

\n\n"); + docs.push_str(" (enum) \n\n"); let docstring = enum_.docs.render(); if !docstring.is_empty() { docs.push_str(&docstring); - docs.push_str("\n\n"); + } else { + docs.push_str("*No description*"); } + docs.push_str("\n\n"); - docs.push_str("

Values

\n\n"); + docs.push_str("#### Values\n\n"); docs.push_str("| **Name** | **Description** |\n"); docs.push_str("| --- | --- |\n"); for (name, description) in enum_.values.iter() { @@ -385,7 +393,7 @@ fn print_enums(types: &[TypeRef], docs: &mut String) { } fn print_constructors(docs: &mut String, class: &impl ClassLike) { - docs.push_str("

Constructor

\n\n"); + docs.push_str("#### Constructor\n\n"); let mut constructors = class.constructors(true).collect::>(); constructors.retain(|(_, constructor_info)| constructor_info.access == AccessModifier::Public); @@ -395,7 +403,7 @@ fn print_constructors(docs: &mut String, class: &impl ClassLike) { if constructors.is_empty() { docs.push_str("*No constructor*\n"); } else { - docs.push_str("
\n");
+		docs.push_str("```\n");
 		for (_, constructor_info) in constructors {
 			let sig = constructor_info
 				.type_
@@ -404,14 +412,14 @@ fn print_constructors(docs: &mut String, class: &impl ClassLike) {
 			print_signature(&VariableKind::InstanceMember, "new", sig, docs);
 			docs.push_str("\n");
 		}
-		docs.push_str("
\n"); + docs.push_str("```\n"); } docs.push_str("\n"); } fn print_properties(docs: &mut String, class: &impl ClassLike) { - docs.push_str("

Properties

\n\n"); + docs.push_str("#### Properties\n\n"); let mut fields = class.fields(true).collect::>(); fields.retain(|(_, field_info)| field_info.access == AccessModifier::Public); @@ -441,7 +449,7 @@ fn print_properties(docs: &mut String, class: &impl ClassLike) { } fn print_methods(docs: &mut String, class: &impl ClassLike) { - docs.push_str("

Methods

\n\n"); + docs.push_str("#### Methods\n\n"); let mut methods = class.methods(true).collect::>(); methods.retain(|(_, method_info)| method_info.access == AccessModifier::Public); diff --git a/packages/@winglibs/testfixture/API.md b/packages/@winglibs/testfixture/API.md index eb3329b5a17..388f1b7a129 100644 --- a/packages/@winglibs/testfixture/API.md +++ b/packages/@winglibs/testfixture/API.md @@ -1,6 +1,6 @@ -

API Reference

+## API Reference -

Table of Contents

+### Table of Contents - **Classes** - PublicClass @@ -14,39 +14,43 @@ - **Enums** - FavoriteNumbers -

PublicClass (preflight class)

+### PublicClass (preflight class) -

Constructor

+*No description* -
+#### Constructor
+
+```
 new(): PublicClass
-
+``` -

Properties

+#### Properties | **Name** | **Type** | **Description** | | --- | --- | --- | | publicField | num | *No description* | -

Methods

+#### Methods | **Signature** | **Description** | | --- | --- | | publicMethod(): void | *No description* | -

Store (preflight class)

+### Store (preflight class) + +*No description* -

Constructor

+#### Constructor -
+```
 new(options: StoreOptions?): Store
-
+``` -

Properties

+#### Properties *No properties* -

Methods

+#### Methods | **Signature** | **Description** | | --- | --- | @@ -55,52 +59,62 @@ new(options: StoreOptions?): Store | onSet(handler: inflight (str): void): void | *No description* | | inflight set(message: str): void | *No description* | -

subdir.Util (preflight class)

+### subdir.Util (preflight class) -

Constructor

+*No description* -
+#### Constructor
+
+```
 new(): Util
-
+``` -

Properties

+#### Properties *No properties* -

Methods

+#### Methods | **Signature** | **Description** | | --- | --- | | static inflight double(msg: str): str | *No description* | | static inflight makeKeyInflight(name: str): str | *No description* | -

PublicInterface (interface)

+### PublicInterface (interface) + +*No description* -

Properties

+#### Properties *No properties* -

Methods

+#### Methods *No methods* -

PublicStruct (struct)

+### PublicStruct (struct) -

Properties

+*No description* + +#### Properties *No properties* -

StoreOptions (struct)

+### StoreOptions (struct) + +*No description* -

Properties

+#### Properties | **Name** | **Type** | **Description** | | --- | --- | --- | | name | str? | *No description* | -

FavoriteNumbers (enum)

+### FavoriteNumbers (enum) + +*No description* -

Values

+#### Values | **Name** | **Description** | | --- | --- | diff --git a/packages/winglang/fixtures/valid1/API.md b/packages/winglang/fixtures/valid1/API.md index a5882b101a6..556715aa624 100644 --- a/packages/winglang/fixtures/valid1/API.md +++ b/packages/winglang/fixtures/valid1/API.md @@ -1,25 +1,25 @@ -

API Reference

+## API Reference -

Table of Contents

+### Table of Contents - **Classes** - Foo -

Foo (preflight class)

+### Foo (preflight class) A test class -

Constructor

+#### Constructor -
+```
 new(): Foo
-
+``` -

Properties

+#### Properties *No properties* -

Methods

+#### Methods *No methods*