Skip to content

Commit

Permalink
fix: deprecated warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiz Figueiredo authored and figueiredoluiz committed Aug 8, 2024
1 parent 4dde0cd commit 056c835
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
16 changes: 7 additions & 9 deletions src/utils/code_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
from html import escape

class CodeHighlighter:
"""
Class for handling code highlighting.
"""
@staticmethod
def highlight_code(content: str, file_extension: str) -> str:
"""
Highlight the given code content based on the file extension.
Args:
content (str): The code content to highlight.
file_extension (str): The file extension to determine the language.
Returns:
str: HTML string of the highlighted code.
"""
try:
lexer = get_lexer_by_name(file_extension)
Expand All @@ -20,9 +22,5 @@ def highlight_code(content: str, file_extension: str) -> str:
formatter = HtmlFormatter(style='colorful', noclasses=True)
highlighted_code = highlight(escape(content), lexer, formatter)

# Convert HTML to plain text with ANSI escape codes
from bs4 import BeautifulSoup
soup = BeautifulSoup(highlighted_code, 'html.parser')
plain_text = soup.get_text()

return plain_text
# Wrap the highlighted code in a div
return f'<div class="highlighted-code">{highlighted_code}</div>'
7 changes: 2 additions & 5 deletions src/utils/custom_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ def chapter_title(self, title: str):
self.ln(10)

def chapter_body(self, body: str, is_code: bool = False):
self.set_font(Config.FONT_FAMILY, Config.FONT_STYLE_NORMAL, Config.FONT_SIZE_SMALL)
if is_code:
# Split the code into lines and write each line
lines = body.split('\n')
for line in lines:
self.cell(0, 5, line, 0, 1)
self.write_html(body)
else:
self.set_font(Config.FONT_FAMILY, Config.FONT_STYLE_NORMAL, Config.FONT_SIZE_SMALL)
self.multi_cell(0, 5, body)
self.ln()

Expand Down

0 comments on commit 056c835

Please sign in to comment.