Update app.py
Browse files
app.py
CHANGED
|
@@ -11,9 +11,9 @@ def remove_links_keep_issue_numbers(text):
|
|
| 11 |
def strip_markdown(text):
|
| 12 |
# Remove headers
|
| 13 |
text = re.sub(r'^#+\s*', '', text, flags=re.MULTILINE)
|
| 14 |
-
# Remove bold/italic
|
| 15 |
-
text = re.sub(r'\*{1,2}([^\*]+)
|
| 16 |
-
# Remove inline code
|
| 17 |
text = re.sub(r'`([^`]+)`', r'\1', text)
|
| 18 |
# Remove blockquotes
|
| 19 |
text = re.sub(r'^\s*>\s*', '', text, flags=re.MULTILINE)
|
|
@@ -24,11 +24,11 @@ def markdown_to_docx(doc, markdown_text):
|
|
| 24 |
|
| 25 |
for line in lines:
|
| 26 |
stripped_line = strip_markdown(line)
|
| 27 |
-
if line.startswith('# '):
|
| 28 |
doc.add_heading(stripped_line, level=1)
|
| 29 |
-
elif line.startswith('## '):
|
| 30 |
doc.add_heading(stripped_line, level=2)
|
| 31 |
-
elif line.startswith('### '):
|
| 32 |
doc.add_heading(stripped_line, level=3)
|
| 33 |
elif line.strip().startswith('- ') or line.strip().startswith('* '):
|
| 34 |
doc.add_paragraph(stripped_line.strip()[2:], style='List Bullet')
|
|
|
|
| 11 |
def strip_markdown(text):
|
| 12 |
# Remove headers
|
| 13 |
text = re.sub(r'^#+\s*', '', text, flags=re.MULTILINE)
|
| 14 |
+
# Remove bold/italic without removing adjacent characters
|
| 15 |
+
text = re.sub(r'(\*{1,2})([^\*]+)\1', r'\2', text)
|
| 16 |
+
# Remove inline code without removing adjacent characters
|
| 17 |
text = re.sub(r'`([^`]+)`', r'\1', text)
|
| 18 |
# Remove blockquotes
|
| 19 |
text = re.sub(r'^\s*>\s*', '', text, flags=re.MULTILINE)
|
|
|
|
| 24 |
|
| 25 |
for line in lines:
|
| 26 |
stripped_line = strip_markdown(line)
|
| 27 |
+
if line.lstrip().startswith('# '):
|
| 28 |
doc.add_heading(stripped_line, level=1)
|
| 29 |
+
elif line.lstrip().startswith('## '):
|
| 30 |
doc.add_heading(stripped_line, level=2)
|
| 31 |
+
elif line.lstrip().startswith('### '):
|
| 32 |
doc.add_heading(stripped_line, level=3)
|
| 33 |
elif line.strip().startswith('- ') or line.strip().startswith('* '):
|
| 34 |
doc.add_paragraph(stripped_line.strip()[2:], style='List Bullet')
|