Created
June 14, 2024 21:23
-
-
Save Cryptizism/68000145d7c4a23edb828c90cd865b31 to your computer and use it in GitHub Desktop.
Obsidian to HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def merge_all_markdown_files(folder_path): | |
merged_content = "" | |
for root, _, files in os.walk(folder_path): | |
for file_name in files: | |
if file_name.endswith(".md"): | |
file_path = os.path.join(root, file_name) | |
with open(file_path, 'r', encoding='utf-8') as topic_file: | |
topic_content = topic_file.read() | |
topic_name = os.path.splitext(file_name)[0] # Extracting topic name without extension | |
merged_content += f"# {topic_name}\n\n{topic_content}\n\n" | |
# Write the merged content back to a new file | |
merged_filename = "merged_all_topics.md" | |
merged_filepath = os.path.join(folder_path, merged_filename) | |
with open(merged_filepath, 'w', encoding='utf-8') as merged_file: | |
merged_file.write(merged_content.strip()) # Remove trailing newline | |
print(f"All topics merged and saved to {merged_filename}") | |
if __name__ == "__main__": | |
folder_path = input("Enter the path to the folder containing markdown files: ") | |
merge_all_markdown_files(folder_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set /p markdown_file="Enter the path to the Markdown file: " | |
if not exist "%markdown_file%" ( | |
echo File does not exist. | |
pause | |
exit /b | |
) | |
set output_file=%markdown_file:.md=.html% | |
pandoc "%markdown_file%" -o "%output_file%" | |
echo Conversion completed. HTML file saved as "%output_file%". | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment