Skip to content

Commit

Permalink
feat(parser): code syntax highlighting
Browse files Browse the repository at this point in the history
Signed-off-by: Rongrong <[email protected]>
  • Loading branch information
Rongronggg9 committed Nov 4, 2023
1 parent 31857ad commit 657fe1d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/parsing/html_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,17 @@ async def _parse_item(self, soup: Union[PageElement, BeautifulSoup, Tag, Navigab
return Pre(await self._parse_item(soup.children))

if tag == 'code':
return Code(await self._parse_item(soup.children))
class_ = soup.get('class')
if isinstance(class_, list):
try:
class_ = next(filter(lambda x: x.startswith('language-'), class_))
except StopIteration:
class_ = None
elif class_ and isinstance(class_, str) and not class_.startswith('language-'):
class_ = f'language-{class_}'
else:
class_ = None
return Code(await self._parse_item(soup.children), param=class_)

if tag == 'br':
return Br()
Expand Down

0 comments on commit 657fe1d

Please sign in to comment.