Skip to content

Commit

Permalink
Add support for sections in the doc (#54)
Browse files Browse the repository at this point in the history
* Add support for sections in the doc

* Add spaces
  • Loading branch information
Ariana-Hlavaty-i2 authored Aug 24, 2022
1 parent 67841df commit b64998d
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ A brief line about the project. Can be specified once in the beginning of the fi

### `@description`

A multiline description of the project/function.
* Can be specified once for the whole file in the begibeginning of the file.
A multiline description of the project/section/function.
* Can be specified once for the whole file in the beginning of the file.
* Can be specified once for a section of the file. See [@section](#section).
* Can be specified once for on top of a function definition.

**Example**
Expand All @@ -157,6 +158,16 @@ function super() {
}
```

### `@section`

The name of a section of the file. Can be used to group functions.

**Example**
```bash
# @section My utilities functions
# @description The following functions can be used to solve problems.
```

### `@example`

A multiline example of the function usage. Can be specified only alongside the function definition.
Expand Down
28 changes: 27 additions & 1 deletion shdoc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ function handle_description() {
return;
}

if (section != "" && section_description == "") {
debug("→ → description: added")
section_description = description
return;
}

if (file_description == "") {
debug("→ → description: added")
file_description = description
Expand Down Expand Up @@ -185,7 +191,19 @@ function render_docblock(func_name, description, docblock) {
debug("→ → func_name: [" func_name "]")
debug("→ → description: [" description "]")

lines[0] = render("h3", func_name)
if (section != "") {
lines[0] = render("h2", section)
if (section_description != "") {
push(lines, section_description)
}
section = ""
section_description = ""
push(lines, render("h3", func_name))
push(lines, "")
} else {
lines[0] = render("h3", func_name)
}

if (description != "") {
push(lines, description)
}
Expand Down Expand Up @@ -343,6 +361,14 @@ in_description {
}
}

/^[[:space:]]*# @section/ {
debug("→ @section")
sub(/^[[:space:]]*# @section /, "")
section = $0

next
}

/^[[:space:]]*# @example/ {
debug("→ @example")

Expand Down
68 changes: 68 additions & 0 deletions tests/testcases/@section.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

tests:put input <<EOF
# @name Project Name
# @brief Brief
# @description a
# b
# @section Section A
# @description a
# a
# @description func a
# line a 2
# @noargs
a() {
}
# @section Section B
# @description b
# @description func b
# ab
# @noargs
b() {
}
EOF

tests:put expected <<EOF
# Project Name
Brief
## Overview
a
b
## Index
* [a](#a)
* [b](#b)
## Section A
a
a
### a
func a
line a 2
_Function has no arguments._
## Section B
b
### b
func b
ab
_Function has no arguments._
EOF

assert

0 comments on commit b64998d

Please sign in to comment.