command-line-interface-pages / v2-tooling

Tools for handling v2.*.* syntax
6 stars 3 forks source link

Parser breaks pages while reformatting sometimes when CHECK is unset #71

Open EmilyGraceSeville7cf opened 1 year ago

EmilyGraceSeville7cf commented 1 year ago

Script being used:

#!/usr/bin/env bash

. ./clip-parse.sh

# shellcheck disable=2155
prettify() {
    declare in_content="$1"

    declare header="$(parser__header "$in_content")"
    declare summary="$(parser_summary__cleaned_up "$in_content")"

    declare examples=
    declare -i count="$(parser_examples__count "$in_content")"

    for ((i = 0; i < count; i++)); do
        declare description="$(parser_examples__description_at "$in_content" "$i")"
        declare code="$(parser_examples__code_at "$in_content" "$i")"

        examples+="- $description:

\`$code\`

"
    done

    echo "# $header

$summary

$examples"
}

declare clip_pages="/home/emilyseville7cfg/Documents/mine/other/cli-pages"

for category_path in "$clip_pages/"*; do
    [[ ! -d "$category_path" ]] && continue

    declare category="${category_path##*/}"
    echo "Refreshing pages in '$category' category"

    for file in "$category_path/"*.clip; do
        prettified="$(prettify "$(cat "$file")")"
        echo "$prettified" > "$file"
        echo "'$file' refreshed"
    done
done

Input page:

# gist

> Upload code to https://gist.github.com
> More information: https://github.com/defunkt/gist

- Log in in gist on this computer:

`gist --login`

- Create a gist from any number of text files:

`gist {file value: sample.txt} {file value: sample.txt}`

- Create a private gist with a description:

`gist --private --description "{string value: A meaningful description}" {file value: sample.txt} `

- Read contents from stdin and create a gist from it:

`{string value: echo "hello world"} | gist`

- List your public and private gists:

`gist --list`

- List all public gists for any user:

`gist --list {string user}`

- Update a gist using the ID from URL:

`gist --update {string value: GIST_ID} {file value: sample.txt}`

Output broken page:

# gist

> 

- Log in in gist on this computer:

`gist --login`

- Create a gist from any number of text files:

`gist {file value: sample.txt} {file value: sample.txt}`

- Create a private gist with a description:

`gist --private --description "{string value: A meaningful description}" {file value: sample.txt}`

- Read contents from stdin and create a gist from it:

`{string value: echo "hello world"} | gist`

- List your public and private gists:

`gist --list`

- List all public gists for any user:

`gist --list {string user}`

- Update a gist using the ID from URL:

`gist --update {string value: GIST_ID} {file value: sample.txt}`

Potentially url in the first string caused such error. I guess Upload code to https was interpreted as an unknown tag name. As a result parser thought that there was no description provided for a command.

EmilyGraceSeville7cf commented 1 year ago

Solution: introduce escaping for tags.

EmilyGraceSeville7cf commented 1 year ago

Another input page:

# pacman

> Arch Linux package manager utility
> Some subcommands such as `pacman sync` have their own usage documentation
> For equivalent commands in other package managers, see <https://wiki.archlinux.org/title/Pacman/Rosetta>
> More information: https://man.archlinux.org/man/pacman.8

- Synchronize and update all packages:

`sudo pacman -Syu`

- Install a new package:

`sudo pacman -S {string value: package_name}`

- Remove a package and its dependencies:

`sudo pacman -Rs {string value: package_name}`

- Search the package database for a regular expression or keyword:

`pacman -Ss "{string value: search_pattern}"`

- List installed packages and versions:

`pacman -Q`

- List only the explicitly installed packages and versions:

`pacman -Qe`

- List orphan packages (installed as dependencies but not actually required by any package):

`pacman -Qtdq`

- Empty the entire pacman cache:

`sudo pacman -Scc`

being "prettified" to this one:

# pacman

> Arch Linux package manager utility
> Some subcommands such as `pacman sync` have their own usage documentation

- Synchronize and update all packages:

`sudo pacman -Syu`

- Install a new package:

`sudo pacman -S {string value: package_name}`

- Remove a package and its dependencies:

`sudo pacman -Rs {string value: package_name}`

- Search the package database for a regular expression or keyword:

`pacman -Ss "{string value: search_pattern}"`

- List installed packages and versions:

`pacman -Q`

- List only the explicitly installed packages and versions:

`pacman -Qe`

- List orphan packages (installed as dependencies but not actually required by any package):

`pacman -Qtdq`

- Empty the entire pacman cache:

`sudo pacman -Scc`