function process_inline_markdown
Processes inline markdown formatting by unescaping HTML entities in text. Currently performs basic cleanup while preserving markdown syntax for downstream processing.
/tf/active/vicechatdev/vice_ai/complex_app.py
1479 - 1492
simple
Purpose
This function serves as a preprocessing step for text containing inline markdown formatting (bold, italic, code). It handles HTML entity decoding (e.g., & to &, < to <) to ensure proper text representation. The function is designed to be part of a larger markdown processing pipeline where actual markdown-to-format conversion is delegated to export functions (Word/PDF generators). This allows for more flexible and context-appropriate formatting handling based on the output format.
Source Code
def process_inline_markdown(text):
"""Process inline markdown formatting like **bold**, *italic*, `code`"""
if not text:
return text
# Convert markdown formatting to structured format
# For now, we'll keep the markdown and let the export functions handle it
# This allows for more complex formatting handling in Word/PDF
# Basic cleanup
import html
text = html.unescape(text) # Handle HTML entities
return text
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
text |
- | - | positional_or_keyword |
Parameter Details
text: A string containing markdown-formatted text with potential HTML entities. Can be None or empty string. Expected to contain inline markdown syntax like **bold**, *italic*, or `code`, though the function currently only processes HTML entities and returns the text unchanged otherwise.
Return Value
Returns the input text with HTML entities unescaped (e.g., '&' becomes '&', '<' becomes '<'). If the input is None or empty, returns the input unchanged. Return type is string or None, matching the input type.
Dependencies
html
Required Imports
import html
Usage Example
import html
def process_inline_markdown(text):
if not text:
return text
text = html.unescape(text)
return text
# Example usage
text_with_entities = "This is **bold** text with & symbol and <tag>"
processed = process_inline_markdown(text_with_entities)
print(processed)
# Output: This is **bold** text with & symbol and <tag>
# Handle None input
result = process_inline_markdown(None)
print(result)
# Output: None
# Handle empty string
result = process_inline_markdown("")
print(result)
# Output: (empty string)
Best Practices
- This function currently only performs HTML entity unescaping and does not actually convert markdown syntax to formatted text
- The function is designed to be part of a pipeline where actual markdown rendering happens in export functions (Word/PDF generators)
- Always check if text is None or empty before processing to avoid errors
- The function preserves markdown syntax intentionally, so downstream processors must handle markdown-to-format conversion
- Consider extending this function if inline markdown processing needs to be centralized rather than delegated to export functions
- The html.unescape() call handles common HTML entities like &, <, >, ", and &#xxx; numeric entities
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function format_inline_markdown 82.7% similar
-
function simple_markdown_to_html 71.6% similar
-
function html_to_markdown 71.1% similar
-
function html_to_markdown_v1 71.0% similar
-
function basic_markdown_to_html 69.9% similar