From 0de305a9a3b795d7938a654b263083bdad8e6453 Mon Sep 17 00:00:00 2001 From: sammyette Date: Mon, 25 Dec 2023 19:52:16 -0400 Subject: [PATCH] docs: fix extra whitespace --- cmd/docgen/docgen.go | 4 ++-- docs/api/bait.md | 11 +++++----- docs/api/commander.md | 4 ++-- docs/api/fs.md | 16 ++++++++------- docs/api/hilbish/_index.md | 28 +++++++++++++++++--------- docs/api/hilbish/hilbish.aliases.md | 6 ++++-- docs/api/hilbish/hilbish.completion.md | 8 ++++---- docs/api/hilbish/hilbish.editor.md | 5 +++++ docs/api/hilbish/hilbish.history.md | 5 +++++ docs/api/hilbish/hilbish.jobs.md | 7 +++++-- docs/api/hilbish/hilbish.module.md | 1 + docs/api/hilbish/hilbish.runner.md | 3 +++ docs/api/hilbish/hilbish.timers.md | 2 ++ docs/api/terminal.md | 4 ++++ nature/commands/doc.lua | 12 +++++++---- 15 files changed, 77 insertions(+), 39 deletions(-) diff --git a/cmd/docgen/docgen.go b/cmd/docgen/docgen.go index 537c39e..86a622a 100644 --- a/cmd/docgen/docgen.go +++ b/cmd/docgen/docgen.go @@ -554,11 +554,11 @@ func main() { `, htmlSig, dps.FuncName)) for _, doc := range dps.Doc { - if !strings.HasPrefix(doc, "---") { + if !strings.HasPrefix(doc, "---") && doc != "" { f.WriteString(doc + " \n") } } - f.WriteString("#### Parameters\n") + f.WriteString("\n#### Parameters\n") if len(dps.Params) == 0 { f.WriteString("This function has no parameters. \n") } diff --git a/docs/api/bait.md b/docs/api/bait.md index 62e1493..950d680 100644 --- a/docs/api/bait.md +++ b/docs/api/bait.md @@ -51,8 +51,7 @@ bait.catch(name, cb) Catches an event. This function can be used to act on events. - - + #### Parameters `string` **`name`** The name of the hook. @@ -78,6 +77,7 @@ bait.catchOnce(name, cb) Catches an event, but only once. This will remove the hook immediately after it runs for the first time. + #### Parameters `string` **`name`** The name of the event @@ -97,6 +97,7 @@ bait.hooks(name) -> table Returns a list of callbacks that are hooked on an event with the corresponding `name`. + #### Parameters `string` **`name`** The name of the function @@ -115,8 +116,7 @@ bait.release(name, catcher) Removes the `catcher` for the event with `name`. For this to work, `catcher` has to be the same function used to catch an event, like one saved to a variable. - - + #### Parameters `string` **`name`** Name of the event the hook is on @@ -146,8 +146,7 @@ bait.throw(name, ...args) Throws a hook with `name` with the provided `args`. - - + #### Parameters `string` **`name`** The name of the hook. diff --git a/docs/api/commander.md b/docs/api/commander.md index b4180cc..03ece54 100644 --- a/docs/api/commander.md +++ b/docs/api/commander.md @@ -52,6 +52,7 @@ commander.deregister(name) Removes the named command. Note that this will only remove Commander-registered commands. + #### Parameters `string` **`name`** Name of the command to remove. @@ -69,8 +70,7 @@ commander.register(name, cb) Adds a new command with the given `name`. When Hilbish has to run a command with a name, it will run the function providing the arguments and sinks. - - + #### Parameters `string` **`name`** Name of the command diff --git a/docs/api/fs.md b/docs/api/fs.md index 8addc78..0ee4830 100644 --- a/docs/api/fs.md +++ b/docs/api/fs.md @@ -42,6 +42,7 @@ fs.abs(path) -> string Returns an absolute version of the `path`. This can be used to resolve short paths like `..` to `/home/user`. + #### Parameters `string` **`path`** @@ -59,6 +60,7 @@ fs.basename(path) -> string Returns the "basename," or the last part of the provided `path`. If path is empty, `.` will be returned. + #### Parameters `string` **`path`** Path to get the base name of. @@ -75,6 +77,7 @@ fs.cd(dir) Changes Hilbish's directory to `dir`. + #### Parameters `string` **`dir`** Path to change directory to. @@ -92,6 +95,7 @@ fs.dir(path) -> string Returns the directory part of `path`. If a file path like `~/Documents/doc.txt` then this function will return `~/Documents`. + #### Parameters `string` **`path`** Path to get the directory for. @@ -109,8 +113,7 @@ fs.glob(pattern) -> matches (table) Match all files based on the provided `pattern`. For the syntax' refer to Go's filepath.Match function: https://pkg.go.dev/path/filepath#Match - - + #### Parameters `string` **`pattern`** Pattern to compare files with. @@ -140,8 +143,7 @@ fs.join(...path) -> string Takes any list of paths and joins them based on the operating system's path separator. - - + #### Parameters `string` **`path`** (This type is variadic. You can pass an infinite amount of parameters with this type.) Paths to join together @@ -165,10 +167,10 @@ fs.mkdir(name, recursive) Creates a new directory with the provided `name`. With `recursive`, mkdir will create parent directories. - -- This will create the directory foo, then create the directory bar in the -- foo directory. If recursive is false in this case, it will fail. fs.mkdir('./foo/bar', true) + #### Parameters `string` **`name`** Name of the directory @@ -192,6 +194,7 @@ fs.readdir(path) -> table[string] Returns a list of all files and directories in the provided path. + #### Parameters `string` **`dir`** @@ -213,8 +216,7 @@ name (string) - Name of the path size (number) - Size of the path in bytes mode (string) - Unix permission mode in an octal format string (with leading 0) isDir (boolean) - If the path is a directory - - + #### Parameters `string` **`path`** diff --git a/docs/api/hilbish/_index.md b/docs/api/hilbish/_index.md index ff89f63..ad3d6b7 100644 --- a/docs/api/hilbish/_index.md +++ b/docs/api/hilbish/_index.md @@ -56,8 +56,7 @@ hilbish.alias(cmd, orig) Sets an alias, with a name of `cmd` to another command. - - + #### Parameters `string` **`cmd`** Name of the alias @@ -86,8 +85,7 @@ hilbish.appendPath(dir) Appends the provided dir to the command path (`$PATH`) - - + #### Parameters `string|table` **`dir`** Directory (or directories) to append to path @@ -119,6 +117,7 @@ A `scope` is currently only expected to be `command.`, replacing with the name of the command (for example `command.git`). The documentation for completions, under Features/Completions or `doc completions` provides more details. + #### Parameters `string` **`scope`** @@ -138,6 +137,7 @@ hilbish.cwd() -> string Returns the current directory of the shell + #### Parameters This function has no parameters. @@ -153,6 +153,7 @@ hilbish.exec(cmd) Replaces the currently running Hilbish instance with the supplied command. This can be used to do an in-place restart. + #### Parameters `string` **`cmd`** @@ -171,6 +172,7 @@ hilbish.goro(fn) Puts `fn` in a Goroutine. This can be used to run any function in another thread. **NOTE: THIS FUNCTION MAY CRASH HILBISH IF OUTSIDE VARIABLES ARE ACCESSED.** + #### Parameters `function` **`fn`** @@ -191,7 +193,7 @@ This is mainly for syntax highlighting, but in reality could set the input of the prompt to *display* anything. The callback is passed the current line and is expected to return a line that will be used as the input display. Note that to set a highlighter, one has to override this function. - + #### Parameters `string` **`line`** @@ -219,8 +221,7 @@ determine what text to use as an inline hint. It is passed the current line and cursor position. It is expected to return a string which is used as the text for the hint. This is by default a shim. To set hints, override this function with your custom handler. - - + #### Parameters `string` **`line`** @@ -249,6 +250,7 @@ hilbish.inputMode(mode) Sets the input mode for Hilbish's line reader. Accepts either emacs or vim. `emacs` is the default. Setting it to `vim` changes behavior of input to be Vim-like with modes and Vim keybinds. + #### Parameters `string` **`mode`** @@ -266,6 +268,7 @@ hilbish.interval(cb, time) -> string Checks if `name` is a valid command. Will return the path of the binary, or a basename if it's a commander. + #### Parameters `string` **`name`** diff --git a/docs/api/hilbish/hilbish.aliases.md b/docs/api/hilbish/hilbish.aliases.md index 3e74a3b..e0a6f48 100644 --- a/docs/api/hilbish/hilbish.aliases.md +++ b/docs/api/hilbish/hilbish.aliases.md @@ -28,6 +28,7 @@ hilbish.aliases.add(alias, cmd) This is an alias (ha) for the [hilbish.alias](../#alias) function. + #### Parameters This function has no parameters. @@ -42,6 +43,7 @@ hilbish.aliases.delete(name) Removes an alias. + #### Parameters `string` **`name`** @@ -58,8 +60,7 @@ hilbish.aliases.list() -> table[string, string] Get a table of all aliases, with string keys as the alias and the value as the command. - - + #### Parameters This function has no parameters. #### Example @@ -81,6 +82,7 @@ hilbish.aliases.resolve(alias) -> string? Resolves an alias to its original command. Will thrown an error if the alias doesn't exist. + #### Parameters `string` **`alias`** diff --git a/docs/api/hilbish/hilbish.completion.md b/docs/api/hilbish/hilbish.completion.md index 46fde24..be6c094 100644 --- a/docs/api/hilbish/hilbish.completion.md +++ b/docs/api/hilbish/hilbish.completion.md @@ -29,8 +29,7 @@ hilbish.completion.bins(query, ctx, fields) -> entries (table), prefix (string) Return binaries/executables based on the provided parameters. This function is meant to be used as a helper in a command completion handler. - - + #### Parameters `string` **`query`** @@ -73,6 +72,7 @@ hilbish.completion.call(name, query, ctx, fields) -> completionGroups (table), p Calls a completer function. This is mainly used to call a command completer, which will have a `name` in the form of `command.name`, example: `command.git`. You can check the Completions doc or `doc completions` for info on the `completionGroups` return value. + #### Parameters `string` **`name`** @@ -99,6 +99,7 @@ hilbish.completion.files(query, ctx, fields) -> entries (table), prefix (string) Returns file matches based on the provided parameters. This function is meant to be used as a helper in a command completion handler. + #### Parameters `string` **`query`** @@ -123,8 +124,7 @@ hilbish.completion.handler(line, pos) This function contains the general completion handler for Hilbish. This function handles completion of everything, which includes calling other command handlers, binaries, and files. This function can be overriden to supply a custom handler. Note that alias resolution is required to be done in this function. - - + #### Parameters `string` **`line`** The current Hilbish command line diff --git a/docs/api/hilbish/hilbish.editor.md b/docs/api/hilbish/hilbish.editor.md index 5e59ec3..c70b605 100644 --- a/docs/api/hilbish/hilbish.editor.md +++ b/docs/api/hilbish/hilbish.editor.md @@ -30,6 +30,7 @@ hilbish.editor.getLine() -> string Returns the current input line. + #### Parameters This function has no parameters. @@ -44,6 +45,7 @@ hilbish.editor.getVimRegister(register) -> string Returns the text that is at the register. + #### Parameters `string` **`register`** @@ -60,6 +62,7 @@ hilbish.editor.insert(text) Inserts text into the Hilbish command line. + #### Parameters `string` **`text`** @@ -76,6 +79,7 @@ hilbish.editor.getChar() -> string Reads a keystroke from the user. This is in a format of something like Ctrl-L. + #### Parameters This function has no parameters. @@ -90,6 +94,7 @@ hilbish.editor.setVimRegister(register, text) Sets the vim register at `register` to hold the passed text. + #### Parameters `string` **`text`** diff --git a/docs/api/hilbish/hilbish.history.md b/docs/api/hilbish/hilbish.history.md index 301ef2b..6de9bdf 100644 --- a/docs/api/hilbish/hilbish.history.md +++ b/docs/api/hilbish/hilbish.history.md @@ -31,6 +31,7 @@ hilbish.history.add(cmd) Adds a command to the history. + #### Parameters `string` **`cmd`** @@ -47,6 +48,7 @@ hilbish.history.all() -> table Retrieves all history as a table. + #### Parameters This function has no parameters. @@ -61,6 +63,7 @@ hilbish.history.clear() Deletes all commands from the history. + #### Parameters This function has no parameters. @@ -75,6 +78,7 @@ hilbish.history.get(index) Retrieves a command from the history based on the `index`. + #### Parameters `number` **`index`** @@ -91,6 +95,7 @@ hilbish.history.size() -> number Returns the amount of commands in the history. + #### Parameters This function has no parameters. diff --git a/docs/api/hilbish/hilbish.jobs.md b/docs/api/hilbish/hilbish.jobs.md index 0ff4db9..cc2c55e 100644 --- a/docs/api/hilbish/hilbish.jobs.md +++ b/docs/api/hilbish/hilbish.jobs.md @@ -34,8 +34,7 @@ hilbish.jobs.add(cmdstr, args, execPath) Creates a new job. This function does not run the job. This function is intended to be used by runners, but can also be used to create jobs via Lua. Commanders cannot be ran as jobs. - - + #### Parameters `string` **`cmdstr`** String that a user would write for the job @@ -62,6 +61,7 @@ hilbish.jobs.all() -> table[ Get a job object via its ID. + #### Parameters This function has no parameters. @@ -106,6 +108,7 @@ hilbish.jobs.last() -> Returns the last added job to the table. + #### Parameters This function has no parameters. diff --git a/docs/api/hilbish/hilbish.module.md b/docs/api/hilbish/hilbish.module.md index cfe3920..4029d7a 100644 --- a/docs/api/hilbish/hilbish.module.md +++ b/docs/api/hilbish/hilbish.module.md @@ -64,6 +64,7 @@ hilbish.module.load(path) Loads a module at the designated `path`. It will throw if any error occurs. + #### Parameters `string` **`path`** diff --git a/docs/api/hilbish/hilbish.runner.md b/docs/api/hilbish/hilbish.runner.md index 56eb030..9a5cf71 100644 --- a/docs/api/hilbish/hilbish.runner.md +++ b/docs/api/hilbish/hilbish.runner.md @@ -34,6 +34,7 @@ This is the same as the `hilbish.runnerMode` function. It takes a callback, which will be used to execute all interactive input. In normal cases, neither callbacks should be overrided by the user, as the higher level functions listed below this will handle it. + #### Parameters `function` **`cb`** @@ -51,6 +52,7 @@ hilbish.runner.lua(cmd) Evaluates `cmd` as Lua input. This is the same as using `dofile` or `load`, but is appropriated for the runner interface. + #### Parameters `string` **`cmd`** @@ -68,6 +70,7 @@ hilbish.runner.sh(cmd) Runs a command in Hilbish's shell script interpreter. This is the equivalent of using `source`. + #### Parameters `string` **`cmd`** diff --git a/docs/api/hilbish/hilbish.timers.md b/docs/api/hilbish/hilbish.timers.md index d100547..f218d2b 100644 --- a/docs/api/hilbish/hilbish.timers.md +++ b/docs/api/hilbish/hilbish.timers.md @@ -48,6 +48,7 @@ hilbish.timers.create(type, time, callback) -> Retrieves a timer via its ID. + #### Parameters `number` **`id`** diff --git a/docs/api/terminal.md b/docs/api/terminal.md index a5ecde8..1bd4cc1 100644 --- a/docs/api/terminal.md +++ b/docs/api/terminal.md @@ -28,6 +28,7 @@ terminal.restoreState() Restores the last saved state of the terminal + #### Parameters This function has no parameters. @@ -42,6 +43,7 @@ terminal.saveState() Saves the current state of the terminal. + #### Parameters This function has no parameters. @@ -56,6 +58,7 @@ terminal.setRaw() Puts the terminal into raw mode. + #### Parameters This function has no parameters. @@ -71,6 +74,7 @@ terminal.size() Gets the dimensions of the terminal. Returns a table with `width` and `height` NOTE: The size refers to the amount of columns and rows of text that can fit in the terminal. + #### Parameters This function has no parameters. diff --git a/nature/commands/doc.lua b/nature/commands/doc.lua index dc3fe9c..7263fe4 100644 --- a/nature/commands/doc.lua +++ b/nature/commands/doc.lua @@ -19,9 +19,11 @@ local function transformHTMLandMD(text) :gsub('|(.-)|(.-)|', function(entry1, entry2) return string.format('%s - %s', entry1, entry2) end) - :gsub('^\n\n', '\n') + :gsub('
', '{separator}') + :gsub('<.->', '') + --:gsub('^\n\n', '\n') :gsub('\n%s+\n', '\n\n') - :gsub(' \n', '\n\n') + --:gsub(' \n', '\n\n') :gsub('{{< (%w+) `(.-)` >}}', function(shortcode, text) return docfuncs.renderInfoBlock(shortcode, text) end) @@ -34,8 +36,6 @@ local function transformHTMLandMD(text) :gsub('`[^\n].-`', lunacolors.cyan) :gsub('#+ (.-\n)', function(heading) return lunacolors.blue(lunacolors.bold('→ ' .. heading)) end) :gsub('%*%*(.-)%*%*', lunacolors.bold) - :gsub('
', '{separator}') - :gsub('<.->', '') end commander.register('doc', function(args, sinks) @@ -64,6 +64,10 @@ Available sections: ]] .. table.concat(modules, ', ') local valsStr = docs:match '^%-%-%-\n.-\n%-%-%-' if valsStr then docs = docs:sub(valsStr:len() + 2, #docs) + local pre = docs:sub(1, 1) + if pre == '\n' then + docs = docs:sub(2) + end -- parse vals local lines = string.split(valsStr, '\n')