Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelmansuy committed Jun 28, 2024
1 parent 60bf191 commit e5bb838
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions code2prompt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,29 @@ def create_markdown_file(
file_path.stat().st_mtime
).strftime("%Y-%m-%d %H:%M:%S")


language = "unknown"
try:
with file_path.open("r", encoding="utf-8") as f:
file_content = f.read()
language = infer_language(file_path.name)
if suppress_comments:
language = infer_language(file_path.name)
if language != "unknown":
file_content = strip_comments(file_content, language)
except UnicodeDecodeError:
continue

file_info = f"## File: {file_path}\n\n"
file_info += f"- Extension: {file_extension}\n"
file_info += f"- Language: {language}\n"
file_info += f"- Size: {file_size} bytes\n"
file_info += f"- Created: {file_creation_time}\n"
file_info += f"- Modified: {file_modification_time}\n\n"
file_code = f"### Code\n\n\n"
file_code = "### Code\n\n\n"
file_code += f"```{language}\n{file_content}\n```\n\n"
content.append(file_info + file_code)
table_of_contents.append(
f"- [{file_path}](#{file_path.as_posix().replace('/', '')})\n"
f"- {file_path}\n"
)

markdown_content = (
Expand Down
5 changes: 4 additions & 1 deletion tests/test_code2prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,7 @@ def test_create_markdown_with_exclude():
assert "file1.py" in output_content
assert "file2.py" in output_content
assert "file3.txt" in output_content # Assuming we want to include non-Python files by default
assert "ignore_me.py" not in output_content # Ensuring excluded file is not in the output
assert "ignore_me.py" not in output_content # Ensuring excluded file is not in the output



0 comments on commit e5bb838

Please sign in to comment.