From b3e0752a6c566b97e2896b486caafd4b25f4683a Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Tue, 26 Dec 2023 19:25:36 -0500 Subject: docs: autogenerate formatter options docs (#234) --- scripts/generate.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'scripts') diff --git a/scripts/generate.py b/scripts/generate.py index b4da7b4..032a86a 100755 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -8,10 +8,12 @@ from typing import List from nvim_doc_tools import ( Vimdoc, VimdocSection, + dedent, generate_md_toc, indent, parse_functions, read_nvim_json, + read_section, render_md_api, render_vimdoc_api, replace_section, @@ -24,6 +26,7 @@ README = os.path.join(ROOT, "README.md") DOC = os.path.join(ROOT, "doc") RECIPES = os.path.join(DOC, "recipes.md") ADVANCED = os.path.join(DOC, "advanced_topics.md") +FORMATTER_OPTIONS = os.path.join(DOC, "formatter_options.md") VIMDOC = os.path.join(DOC, "conform.txt") OPTIONS = os.path.join(ROOT, "scripts", "options_doc.lua") AUTOFORMAT = os.path.join(ROOT, "scripts", "autoformat_doc.lua") @@ -34,6 +37,7 @@ class Formatter: name: str description: str url: str + has_options: bool deprecated: bool = False @@ -91,6 +95,25 @@ def update_autocmd_md(): ) +def update_formatter_options_md(): + lines = ["\n"] + for formatter in get_all_formatters(): + if formatter.has_options: + lines.extend([f"## {formatter.name}\n", "\n", "```lua\n", "options = {\n"]) + formatter_file = os.path.join( + ROOT, "lua", "conform", "formatters", f"{formatter.name}.lua" + ) + code = read_section(formatter_file, r"^ options = {$", r"^ },$") + lines.extend(dedent(code, 2)) + lines.extend(["}\n", "```\n", "\n"]) + replace_section( + FORMATTER_OPTIONS, + r"^$", + r"^$", + lines, + ) + + def add_md_link_path(path: str, lines: List[str]) -> List[str]: ret = [] for line in lines: @@ -133,6 +156,18 @@ def update_advanced_toc(): replace_section(README, r"^$", r"^$", subtoc) +def update_formatter_options_toc(): + toc = ["\n"] + generate_md_toc(FORMATTER_OPTIONS) + ["\n"] + replace_section(FORMATTER_OPTIONS, r"^$", r"^$", toc) + subtoc = add_md_link_path("doc/formatter_options.md", toc) + replace_section( + README, + r"^$", + r"^$", + subtoc, + ) + + def gen_options_vimdoc() -> VimdocSection: section = VimdocSection("Options", "conform-options", ["\n", ">lua\n"]) with open(OPTIONS, "r", encoding="utf-8") as f: @@ -208,8 +243,10 @@ def main() -> None: update_formatter_list() update_options() update_autocmd_md() + update_formatter_options_md() update_md_api() update_recipes_toc() update_advanced_toc() + update_formatter_options_toc() update_readme_toc() generate_vimdoc() -- cgit v1.2.3-70-g09d2