From 164dd0d637614097eda2969cd600c102a076f062 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 25 Sep 2023 21:05:26 +0530 Subject: [PATCH] man pages: Fix table markup in kitty man pages not being rendered correctly at all window sizes Fixes #5095 --- docs/conf.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index a9830d7e8..fae09602a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,7 +12,7 @@ import re import subprocess import sys import time -from functools import partial +from functools import partial, lru_cache from typing import Any, Callable, Dict, Iterable, List, Tuple from docutils import nodes @@ -546,9 +546,41 @@ def add_html_context(app: Any, pagename: str, templatename: str, context: Any, d context['toctree'] = include_sub_headings +@lru_cache +def monkeypatch_man_writer() -> None: + ''' + Monkeypatch the docutils man translator to output better tables + ''' + from docutils.writers.manpage import Table, Translator + + class PatchedTable(Table): + _options: list[str] + def __init__(self) -> None: + super().__init__() + self.needs_border_removal = self._options == ['center'] + if self.needs_border_removal: + self._options = ['box', 'center'] + + def as_list(self) -> list[str]: + ans = super().as_list() + if self.needs_border_removal: + # remove side and top borders as we use box in self._options + ans[2] = ans[2][1:] + a, b = ans[2].rpartition('|')[::2] + ans[2] = a + b + if ans[3] == '_\n': + del ans[3] # top border + del ans[-2] # bottom border + return ans + def visit_table(self: Translator, node: object) -> None: + self._active_table = PatchedTable() # type: ignore + Translator.visit_table = visit_table # type: ignore + + def setup(app: Any) -> None: os.makedirs('generated/conf', exist_ok=True) from kittens.runner import all_kitten_names + monkeypatch_man_writer() kn = all_kitten_names() write_cli_docs(kn) write_remote_control_protocol_docs()