Skip to content

Commit be9d58a

Browse files
authored
update doc template (#69)
* update doc template * update doc template
1 parent a9a9628 commit be9d58a

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

.changeset/selfish-cars-study.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'rankify-contracts': patch
3+
---
4+
5+
doc generation template improvements

docs/templates/common.hbs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{{h 2}} {{visibility}} {{toLowerCase type}} {{name}}
21

32
{{#if (isVisible visibility)}}
43
{{h 2}} {{name}}
@@ -10,6 +9,7 @@
109
{{{signature}}}
1110
```
1211
{{/if}}
12+
{{/if}}
1313

1414
{{#if natspec.params}}
1515
| Input | Type | Description |
@@ -36,3 +36,4 @@
3636
{{#if natspec.dev}}
3737
{{{transformDev (substituteAnchors natspec.dev)}}}
3838
{{/if}}
39+

docs/templates/contract.hbs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
## Description
2-
31
{{{natspec.notice}}}
42

5-
{{{natspec.dev}}}
3+
{{{transformDev (substituteAnchors natspec.dev)}}}
64

7-
## Implementation
85

96
{{#each items}}
107
{{>item}}

docs/templates/helpers.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function joinLines(text?: string) {
6464

6565
export function transformDev(comment: string): string {
6666
// Split the comment into lines
67-
const lines = comment.split('\n');
67+
const lines = comment?.split('\n') ?? [];
6868

6969
// Initialize variables to store the transformed text
7070
let transformedText = '';
@@ -117,8 +117,18 @@ export const isVisible = (type: string) => {
117117

118118
export const substituteAnchors = (text: string) => {
119119
if (typeof text === 'string') {
120-
return text.replace(/{(\w+)}/g, (match: string, p1: string) => {
121-
return `[${p1}](#${p1.toLocaleLowerCase()})`;
120+
return text.replace(/{([^}]+)}/g, (match: string, p1: string) => {
121+
// Split the reference into parts
122+
const parts = p1.split('.');
123+
const anchor = parts.length > 1 ? `#${parts.slice(1).join('.').toLocaleLowerCase()}` : '';
124+
const reference = parts[0];
125+
const displayText = reference.charAt(0).toUpperCase() + reference.slice(1);
126+
127+
// Handle different depth levels
128+
const path = reference.startsWith('../') ? reference : `./${reference}`;
129+
130+
return `[${displayText}${anchor}](../${path}${anchor})`;
122131
});
123132
}
133+
return text;
124134
};

0 commit comments

Comments
 (0)