Skip to content

Commit

Permalink
✨ Add filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 22, 2023
1 parent deba18b commit 2c34b04
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/tree_sitter_lsp/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
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
Expand Down Expand Up @@ -92,26 +91,33 @@ def html2soup(html: str) -> BeautifulSoup:


def get_soup(
uri: str, method: Literal["pandoc", "groff"] = "pandoc"
uri: str,
converter: Literal["pandoc", "groff"] = "pandoc",
filetype: str = "man",
) -> BeautifulSoup:
r"""Get soup.
pandoc doesn't support mdoc.
`<https://github.com/jgm/pandoc/issues/9056>`_
:param uri:
:type uri: str
:param method:
:type method: Literal["pandoc", "groff"]
:param converter:
:type converter: Literal["pandoc", "groff"]
:param filetype:
:type filetype: str
:rtype: BeautifulSoup
"""
if uri_scheme(uri):
with request.urlopen(uri) as f: # nosec: B310
html = f.read()
else:
text = get_man(uri)
if method == "pandoc":
html = convert_text(text, "html", "man")
if converter == "pandoc":
html = convert_text(text, "html", filetype)
else:
html = check_output( # nosec: B603
split("groff -mman -Thtml"),
html = check_output( # nosec: B603 B607
["groff", "-m", filetype, "-Thtml"],
input=text.encode(),
).decode()
return html2soup(html)
Expand Down

0 comments on commit 2c34b04

Please sign in to comment.