Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Light-Beacon committed Feb 20, 2024
1 parent 0051972 commit c041d80
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
41 changes: 29 additions & 12 deletions Core/MarkdownPresenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,41 @@ def listItem2xaml(tag,res):
if isinstance(child,str):
content += replace_esc_char(child)
else:
content += tag2xaml(child,res)
content += element2xaml_general(child,res)
else:
if in_paragraph:
content += '</Paragraph>'
in_paragraph = False
content += tag2xaml(child,res)
content += element2xaml_general(child,res)
if in_paragraph:
content += '</Paragraph>'
return element_frame.replace('${content}',content)

def tag2xaml(tag,res):
def quote2xaml(tag,res):
if tag.name != 'blockquote':
raise ValueError()
element_frame:str = get_element_frame(tag.name,{},res)
content = ''
if tag.contents:
for child in tag:
if isinstance(child,str) or child.name != 'p':
continue
for grand_child in child:
content += element2xaml_general(grand_child,res)
return element_frame.replace('${content}',content)

def element2xaml_general(tag,res):
if isinstance(tag,str):
return replace_esc_char(tag)
match tag.name:
case 'li':
return listItem2xaml(tag,res)
case 'blockquote':
return quote2xaml(tag,res)
case _:
return common2xaml(tag,res)

def common2xaml(tag,res):
name = tag.name
attrs = tag.attrs
content = ''
Expand All @@ -76,21 +100,14 @@ def tag2xaml(tag,res):
if name == 'p':
content += FIRSTLINE_SPACES
for child in tag.contents:
if isinstance(child,str):
content += replace_esc_char(child)
else:
match child.name:
case 'li':
content += listItem2xaml(child,res)
case _:
content += tag2xaml(child,res)
content += element2xaml_general(child,res)
return element_frame.replace('${content}',content)

def html2xaml(html,res):
soup = BeautifulSoup(html,'html.parser')
xaml = ''
for tag in soup.find_all(recursive=False):
xaml += tag2xaml(tag,res)
xaml += element2xaml_general(tag,res)
return xaml

def replace_esc_char(string:str):
Expand Down
1 change: 1 addition & 0 deletions Plugin/Markdown/Resources/Components/del.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Span TextDecorations="Strikethrough">${content}</Span>

0 comments on commit c041d80

Please sign in to comment.