Skip to content

Commit

Permalink
Merge pull request #93 from Bishoy-at-pieces/fix-table-rendering-issue
Browse files Browse the repository at this point in the history
fix table rendering issue #92
  • Loading branch information
bishoy-at-pieces authored Jun 20, 2024
2 parents e207357 + 2b41cbc commit f8abe97
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions assets/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import queue
from typing import Dict
import threading
import re

from .._pieces_lib.pieces_os_client import Asset, AssetApi,StreamedIdentifiers
import sublime

Expand Down Expand Up @@ -65,23 +66,21 @@ def assets_snapshot_callback(cls,ids:StreamedIdentifiers):


def tabulate_from_markdown(md_text):
# Split the markdown text into lines
lines = md_text.split('\n')
table_regex = re.compile(r'(\|.*\|(?:\n\|.*\|)+)')
match = table_regex.search(md_text)

if match:
table_md = match.group(1)
else: return md_text


# Filter out lines that contain '|', and join them back into a string
table_md = "\n".join(line for line in lines if '|' in line)

# Split the markdown table into lines, and then into cells
# Also, remove leading/trailing whitespace from each cell
data = [[cell.strip() for cell in line.split("|")[1:-1]] for line in table_md.strip().split("\n")]

headers = "<div>"
for header in data[0]:
if header:
headers += "<span><h1>" + header + "</h1></span>"

# Generate HTML string
html_text = f"{headers}</div><br><div>"
html_text = f"<h3>{data[0][0]}</h3><br><div>"
for row in data[2:]:
html_text += "<div>"
for idx,cell in enumerate(row):
Expand All @@ -92,4 +91,4 @@ def tabulate_from_markdown(md_text):
html_text += "</div>"


return md_text.replace(table_md,html_text)
return md_text.replace(table_md,html_text)

0 comments on commit f8abe97

Please sign in to comment.