Skip to content

Commit

Permalink
static folder prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
mingming-ma committed Oct 31, 2023
1 parent 9b7aa83 commit b4ebaf9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion examples/test-folder/test1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ This is title

This is the first paragraph.

This is the second paragraph.
This is the second paragraph.

This is image </img/test.png>
12 changes: 12 additions & 0 deletions txt2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ def process_text_file(input_file, output_folder, lang_attribute_value = "en-CA")
for i in range(1, len(text_lines)):
updatedLine = text_lines[i].strip()

# Check for static assets in the form of </img/txt2html.png>
static_asset_pattern = r'</([^/]+/[^>]+)>'
matches = re.findall(static_asset_pattern, updatedLine)
# Use a folder name 'static' under tool's folder as a default asset folder
static_dir = os.path.abspath('static')
for match in matches:
asset_path = os.path.join(static_dir, match)
if os.path.exists(asset_path):
# Replace the static asset tag with the appropriate HTML tag
img_tag = f'<img src="{asset_path}">'
updatedLine = updatedLine.replace(f'</{match}>', img_tag)

#Check if input_file is Markdown (.md)
if (input_file.endswith(".md")):
if (updatedLine.__eq__("---")):
Expand Down

0 comments on commit b4ebaf9

Please sign in to comment.