Skip to content

Commit

Permalink
✨ Support groff
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 22, 2023
1 parent 2ac5ceb commit b5a2f0c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/tree_sitter_lsp/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"""
from gzip import decompress
from itertools import chain
from shlex import split
from subprocess import check_output # nosec: B404
from typing import Literal
from urllib import request

from bs4 import BeautifulSoup, FeatureNotFound
Expand All @@ -20,7 +23,9 @@ def get_man(filename: str) -> str:
:type filename: str
:rtype: str
"""
filename += ".5*"
if filename.find(".") == -1:
filename += ".5"
filename += "*"
text = b""
path = ""
for path in chain(
Expand Down Expand Up @@ -83,19 +88,30 @@ def html2soup(html: str) -> BeautifulSoup:
return soup


def get_soup(uri: str) -> BeautifulSoup:
def get_soup(
uri: str, method: Literal["pandoc", "groff"] = "pandoc"
) -> BeautifulSoup:
r"""Get soup.
:param uri:
:type uri: str
:param method:
:type method: Literal["pandoc", "groff"]
:rtype: BeautifulSoup
"""
if uri_scheme(uri):
with request.urlopen(uri) as f: # nosec: B310
html = f.read()
else:
text = get_man(uri)
html = convert_text(text, "html", "man")
if method == "pandoc":
html = convert_text(text, "html", "man")
else:
html = check_output( # nosec: B603
split("groff -mman -Thtml"),
input=text.encode(),
universal_newlines=True,
)
return html2soup(html)


Expand Down

0 comments on commit b5a2f0c

Please sign in to comment.