Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding inital support for converting markdown files #9

Merged
merged 6 commits into from
Sep 21, 2023

Conversation

ijacobs-cpa
Copy link
Contributor

Fixes #8

I added some functions to handle processing markdown files by checking and replacing different titles (with '#'), bold text, and italicized text with their HTML equivalent. It keeps to the same format as your other write_text_to_html() function but adds a loop to go through each line of text looking for markdown symbols.

New function:

# Markdown support functions here:
#
# Similiar to the text variant this function writes converts the markdown into HTML with some of the included features (headings, bolding, italics)
# Interacts similar to text
def write_markdown_to_html(new_content, new_title,new_cssstyle):
    
    # Markdown conversion
    converted_md = ""
    lines = new_content.splitlines()    # Spliting each line of the new_content into a list


    i = 0
    for  curr_line in lines:        # Going through each line
       
        if '#' in curr_line:                        # Checking for titles
            if curr_line.startswith("###"):
                curr_line = "<h3>" + curr_line.lstrip('#') + "</h3>\n"
            elif curr_line.startswith("##"):                             
                curr_line = "<h2>" + curr_line.lstrip('#') + "</h2>\n"
            else:
                curr_line = "<h1>" + curr_line.lstrip('#') + "</h1>\n"

I also added checks throughout your code for .md where it was checking for .txt files and handled them by sending them to the right function or creating the right filename

For example in your processFile() function:

## Markdown supports changing new filename based on what type of file is it
        html_newfile_path = ""
        if is_markdown(file_path):
            html_newfile_path = file_path.replace('.md', '.html')
        else: 
            html_newfile_path = file_path.replace('.txt', '.html')

All places where these types of changes were taking place were commented on the same as above.

The isMarkdown() is just a quick boolean function to check if the file ending is .md

def is_markdown(file_name):
    return (".md" in  file_name)

New Tests:

I created two new test files one in the main directory test.md, and one in the test/ folder called 'test4.md' for testing .md files within a folder.

To test the new support you can use:

python waypoint.py test.md

or

python waypoint.py test/

for the folder test.

Readme

I've updated the readme explaining markdown support and providing an example

@vercel
Copy link

vercel bot commented Sep 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
waypoint ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 21, 2023 7:57pm
waypoint-5sn9 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 21, 2023 7:57pm
waypoint-f3xn ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 21, 2023 7:57pm

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for playful-nougat-6c62ea ready!

Name Link
🔨 Latest commit 467d7c5
🔍 Latest deploy log https://app.netlify.com/sites/playful-nougat-6c62ea/deploys/650ca0178ee4e2000819bfe6
😎 Deploy Preview https://deploy-preview-9--playful-nougat-6c62ea.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for .md/markdown files
2 participants