pomera-ai-commander 0.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +105 -680
- package/bin/pomera-ai-commander.js +62 -62
- package/core/__init__.py +65 -65
- package/core/app_context.py +482 -482
- package/core/async_text_processor.py +421 -421
- package/core/backup_manager.py +655 -655
- package/core/backup_recovery_manager.py +1033 -1033
- package/core/content_hash_cache.py +508 -508
- package/core/context_menu.py +313 -313
- package/core/data_validator.py +1066 -1066
- package/core/database_connection_manager.py +744 -744
- package/core/database_curl_settings_manager.py +608 -608
- package/core/database_promera_ai_settings_manager.py +446 -446
- package/core/database_schema.py +411 -411
- package/core/database_schema_manager.py +395 -395
- package/core/database_settings_manager.py +1507 -1507
- package/core/database_settings_manager_interface.py +456 -456
- package/core/dialog_manager.py +734 -734
- package/core/efficient_line_numbers.py +510 -510
- package/core/error_handler.py +746 -746
- package/core/error_service.py +431 -431
- package/core/event_consolidator.py +511 -511
- package/core/mcp/__init__.py +43 -43
- package/core/mcp/protocol.py +288 -288
- package/core/mcp/schema.py +251 -251
- package/core/mcp/server_stdio.py +299 -299
- package/core/mcp/tool_registry.py +2372 -2345
- package/core/memory_efficient_text_widget.py +711 -711
- package/core/migration_manager.py +914 -914
- package/core/migration_test_suite.py +1085 -1085
- package/core/migration_validator.py +1143 -1143
- package/core/optimized_find_replace.py +714 -714
- package/core/optimized_pattern_engine.py +424 -424
- package/core/optimized_search_highlighter.py +552 -552
- package/core/performance_monitor.py +674 -674
- package/core/persistence_manager.py +712 -712
- package/core/progressive_stats_calculator.py +632 -632
- package/core/regex_pattern_cache.py +529 -529
- package/core/regex_pattern_library.py +350 -350
- package/core/search_operation_manager.py +434 -434
- package/core/settings_defaults_registry.py +1087 -1087
- package/core/settings_integrity_validator.py +1111 -1111
- package/core/settings_serializer.py +557 -557
- package/core/settings_validator.py +1823 -1823
- package/core/smart_stats_calculator.py +709 -709
- package/core/statistics_update_manager.py +619 -619
- package/core/stats_config_manager.py +858 -858
- package/core/streaming_text_handler.py +723 -723
- package/core/task_scheduler.py +596 -596
- package/core/update_pattern_library.py +168 -168
- package/core/visibility_monitor.py +596 -596
- package/core/widget_cache.py +498 -498
- package/mcp.json +51 -61
- package/package.json +61 -57
- package/pomera.py +7482 -7482
- package/pomera_mcp_server.py +183 -144
- package/requirements.txt +32 -0
- package/tools/__init__.py +4 -4
- package/tools/ai_tools.py +2891 -2891
- package/tools/ascii_art_generator.py +352 -352
- package/tools/base64_tools.py +183 -183
- package/tools/base_tool.py +511 -511
- package/tools/case_tool.py +308 -308
- package/tools/column_tools.py +395 -395
- package/tools/cron_tool.py +884 -884
- package/tools/curl_history.py +600 -600
- package/tools/curl_processor.py +1207 -1207
- package/tools/curl_settings.py +502 -502
- package/tools/curl_tool.py +5467 -5467
- package/tools/diff_viewer.py +1071 -1071
- package/tools/email_extraction_tool.py +248 -248
- package/tools/email_header_analyzer.py +425 -425
- package/tools/extraction_tools.py +250 -250
- package/tools/find_replace.py +1750 -1750
- package/tools/folder_file_reporter.py +1463 -1463
- package/tools/folder_file_reporter_adapter.py +480 -480
- package/tools/generator_tools.py +1216 -1216
- package/tools/hash_generator.py +255 -255
- package/tools/html_tool.py +656 -656
- package/tools/jsonxml_tool.py +729 -729
- package/tools/line_tools.py +419 -419
- package/tools/markdown_tools.py +561 -561
- package/tools/mcp_widget.py +1417 -1417
- package/tools/notes_widget.py +973 -973
- package/tools/number_base_converter.py +372 -372
- package/tools/regex_extractor.py +571 -571
- package/tools/slug_generator.py +310 -310
- package/tools/sorter_tools.py +458 -458
- package/tools/string_escape_tool.py +392 -392
- package/tools/text_statistics_tool.py +365 -365
- package/tools/text_wrapper.py +430 -430
- package/tools/timestamp_converter.py +421 -421
- package/tools/tool_loader.py +710 -710
- package/tools/translator_tools.py +522 -522
- package/tools/url_link_extractor.py +261 -261
- package/tools/url_parser.py +204 -204
- package/tools/whitespace_tools.py +355 -355
- package/tools/word_frequency_counter.py +146 -146
- package/core/__pycache__/__init__.cpython-313.pyc +0 -0
- package/core/__pycache__/app_context.cpython-313.pyc +0 -0
- package/core/__pycache__/async_text_processor.cpython-313.pyc +0 -0
- package/core/__pycache__/backup_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/backup_recovery_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/content_hash_cache.cpython-313.pyc +0 -0
- package/core/__pycache__/context_menu.cpython-313.pyc +0 -0
- package/core/__pycache__/data_validator.cpython-313.pyc +0 -0
- package/core/__pycache__/database_connection_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_curl_settings_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_promera_ai_settings_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_schema.cpython-313.pyc +0 -0
- package/core/__pycache__/database_schema_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_settings_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_settings_manager_interface.cpython-313.pyc +0 -0
- package/core/__pycache__/dialog_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/efficient_line_numbers.cpython-313.pyc +0 -0
- package/core/__pycache__/error_handler.cpython-313.pyc +0 -0
- package/core/__pycache__/error_service.cpython-313.pyc +0 -0
- package/core/__pycache__/event_consolidator.cpython-313.pyc +0 -0
- package/core/__pycache__/memory_efficient_text_widget.cpython-313.pyc +0 -0
- package/core/__pycache__/migration_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/migration_test_suite.cpython-313.pyc +0 -0
- package/core/__pycache__/migration_validator.cpython-313.pyc +0 -0
- package/core/__pycache__/optimized_find_replace.cpython-313.pyc +0 -0
- package/core/__pycache__/optimized_pattern_engine.cpython-313.pyc +0 -0
- package/core/__pycache__/optimized_search_highlighter.cpython-313.pyc +0 -0
- package/core/__pycache__/performance_monitor.cpython-313.pyc +0 -0
- package/core/__pycache__/persistence_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/progressive_stats_calculator.cpython-313.pyc +0 -0
- package/core/__pycache__/regex_pattern_cache.cpython-313.pyc +0 -0
- package/core/__pycache__/regex_pattern_library.cpython-313.pyc +0 -0
- package/core/__pycache__/search_operation_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/settings_defaults_registry.cpython-313.pyc +0 -0
- package/core/__pycache__/settings_integrity_validator.cpython-313.pyc +0 -0
- package/core/__pycache__/settings_serializer.cpython-313.pyc +0 -0
- package/core/__pycache__/settings_validator.cpython-313.pyc +0 -0
- package/core/__pycache__/smart_stats_calculator.cpython-313.pyc +0 -0
- package/core/__pycache__/statistics_update_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/stats_config_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/streaming_text_handler.cpython-313.pyc +0 -0
- package/core/__pycache__/task_scheduler.cpython-313.pyc +0 -0
- package/core/__pycache__/visibility_monitor.cpython-313.pyc +0 -0
- package/core/__pycache__/widget_cache.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/__init__.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/protocol.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/schema.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/server_stdio.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/tool_registry.cpython-313.pyc +0 -0
- package/tools/__pycache__/__init__.cpython-313.pyc +0 -0
- package/tools/__pycache__/ai_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/ascii_art_generator.cpython-313.pyc +0 -0
- package/tools/__pycache__/base64_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/base_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/case_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/column_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/cron_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/curl_history.cpython-313.pyc +0 -0
- package/tools/__pycache__/curl_processor.cpython-313.pyc +0 -0
- package/tools/__pycache__/curl_settings.cpython-313.pyc +0 -0
- package/tools/__pycache__/curl_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/diff_viewer.cpython-313.pyc +0 -0
- package/tools/__pycache__/email_extraction_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/email_header_analyzer.cpython-313.pyc +0 -0
- package/tools/__pycache__/extraction_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/find_replace.cpython-313.pyc +0 -0
- package/tools/__pycache__/folder_file_reporter.cpython-313.pyc +0 -0
- package/tools/__pycache__/folder_file_reporter_adapter.cpython-313.pyc +0 -0
- package/tools/__pycache__/generator_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/hash_generator.cpython-313.pyc +0 -0
- package/tools/__pycache__/html_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/huggingface_helper.cpython-313.pyc +0 -0
- package/tools/__pycache__/jsonxml_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/line_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/list_comparator.cpython-313.pyc +0 -0
- package/tools/__pycache__/markdown_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/mcp_widget.cpython-313.pyc +0 -0
- package/tools/__pycache__/notes_widget.cpython-313.pyc +0 -0
- package/tools/__pycache__/number_base_converter.cpython-313.pyc +0 -0
- package/tools/__pycache__/regex_extractor.cpython-313.pyc +0 -0
- package/tools/__pycache__/slug_generator.cpython-313.pyc +0 -0
- package/tools/__pycache__/sorter_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/string_escape_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/text_statistics_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/text_wrapper.cpython-313.pyc +0 -0
- package/tools/__pycache__/timestamp_converter.cpython-313.pyc +0 -0
- package/tools/__pycache__/tool_loader.cpython-313.pyc +0 -0
- package/tools/__pycache__/translator_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/url_link_extractor.cpython-313.pyc +0 -0
- package/tools/__pycache__/url_parser.cpython-313.pyc +0 -0
- package/tools/__pycache__/whitespace_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/word_frequency_counter.cpython-313.pyc +0 -0
package/tools/markdown_tools.py
CHANGED
|
@@ -1,562 +1,562 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Markdown Tools Module - Markdown processing utilities
|
|
3
|
-
|
|
4
|
-
This module provides markdown manipulation functionality with a tabbed UI interface
|
|
5
|
-
for the Pomera AI Commander application.
|
|
6
|
-
|
|
7
|
-
Features:
|
|
8
|
-
- Strip Markdown: Remove all markdown formatting
|
|
9
|
-
- Extract Links: Extract all links from markdown
|
|
10
|
-
- Extract Headers: Extract all headers with hierarchy
|
|
11
|
-
- Table to CSV: Convert markdown tables to CSV
|
|
12
|
-
- Format Table: Auto-align markdown tables
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
import tkinter as tk
|
|
16
|
-
from tkinter import ttk
|
|
17
|
-
import re
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class MarkdownToolsProcessor:
|
|
21
|
-
"""Markdown tools processor with various markdown manipulation capabilities."""
|
|
22
|
-
|
|
23
|
-
@staticmethod
|
|
24
|
-
def strip_markdown(text, preserve_links_text=True):
|
|
25
|
-
"""Remove all markdown formatting from text."""
|
|
26
|
-
result = text
|
|
27
|
-
|
|
28
|
-
# Remove code blocks
|
|
29
|
-
result = re.sub(r'```[\s\S]*?```', '', result)
|
|
30
|
-
result = re.sub(r'`[^`]+`', lambda m: m.group(0)[1:-1], result)
|
|
31
|
-
|
|
32
|
-
# Handle links
|
|
33
|
-
if preserve_links_text:
|
|
34
|
-
result = re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', result)
|
|
35
|
-
else:
|
|
36
|
-
result = re.sub(r'\[([^\]]+)\]\([^\)]+\)', '', result)
|
|
37
|
-
|
|
38
|
-
# Remove images
|
|
39
|
-
result = re.sub(r'!\[([^\]]*)\]\([^\)]+\)', r'\1', result)
|
|
40
|
-
|
|
41
|
-
# Remove headers
|
|
42
|
-
result = re.sub(r'^#{1,6}\s+', '', result, flags=re.MULTILINE)
|
|
43
|
-
|
|
44
|
-
# Remove bold and italic
|
|
45
|
-
result = re.sub(r'\*\*\*([^*]+)\*\*\*', r'\1', result)
|
|
46
|
-
result = re.sub(r'\*\*([^*]+)\*\*', r'\1', result)
|
|
47
|
-
result = re.sub(r'\*([^*]+)\*', r'\1', result)
|
|
48
|
-
result = re.sub(r'___([^_]+)___', r'\1', result)
|
|
49
|
-
result = re.sub(r'__([^_]+)__', r'\1', result)
|
|
50
|
-
result = re.sub(r'_([^_]+)_', r'\1', result)
|
|
51
|
-
|
|
52
|
-
# Remove strikethrough
|
|
53
|
-
result = re.sub(r'~~([^~]+)~~', r'\1', result)
|
|
54
|
-
|
|
55
|
-
# Remove blockquotes
|
|
56
|
-
result = re.sub(r'^>\s*', '', result, flags=re.MULTILINE)
|
|
57
|
-
|
|
58
|
-
# Remove horizontal rules
|
|
59
|
-
result = re.sub(r'^[-*_]{3,}\s*$', '', result, flags=re.MULTILINE)
|
|
60
|
-
|
|
61
|
-
# Remove list markers
|
|
62
|
-
result = re.sub(r'^\s*[-*+]\s+', '', result, flags=re.MULTILINE)
|
|
63
|
-
result = re.sub(r'^\s*\d+\.\s+', '', result, flags=re.MULTILINE)
|
|
64
|
-
|
|
65
|
-
# Clean up extra whitespace
|
|
66
|
-
result = re.sub(r'\n{3,}', '\n\n', result)
|
|
67
|
-
|
|
68
|
-
return result.strip()
|
|
69
|
-
|
|
70
|
-
@staticmethod
|
|
71
|
-
def extract_links(text, include_images=False):
|
|
72
|
-
"""Extract all links from markdown text."""
|
|
73
|
-
results = []
|
|
74
|
-
|
|
75
|
-
# Extract regular links [text](url)
|
|
76
|
-
links = re.findall(r'\[([^\]]+)\]\(([^\)]+)\)', text)
|
|
77
|
-
for link_text, url in links:
|
|
78
|
-
if not url.startswith('!'):
|
|
79
|
-
results.append(f"{link_text}: {url}")
|
|
80
|
-
|
|
81
|
-
# Extract images if requested 
|
|
82
|
-
if include_images:
|
|
83
|
-
images = re.findall(r'!\[([^\]]*)\]\(([^\)]+)\)', text)
|
|
84
|
-
for alt_text, url in images:
|
|
85
|
-
results.append(f"[IMAGE] {alt_text or 'No alt text'}: {url}")
|
|
86
|
-
|
|
87
|
-
# Extract reference-style links [text][ref] and [ref]: url
|
|
88
|
-
ref_defs = dict(re.findall(r'^\[([^\]]+)\]:\s*(.+)$', text, re.MULTILINE))
|
|
89
|
-
ref_links = re.findall(r'\[([^\]]+)\]\[([^\]]*)\]', text)
|
|
90
|
-
for link_text, ref in ref_links:
|
|
91
|
-
ref_key = ref if ref else link_text
|
|
92
|
-
if ref_key.lower() in {k.lower(): k for k in ref_defs}:
|
|
93
|
-
actual_key = next(k for k in ref_defs if k.lower() == ref_key.lower())
|
|
94
|
-
results.append(f"{link_text}: {ref_defs[actual_key]}")
|
|
95
|
-
|
|
96
|
-
# Extract bare URLs
|
|
97
|
-
bare_urls = re.findall(r'<(https?://[^>]+)>', text)
|
|
98
|
-
for url in bare_urls:
|
|
99
|
-
results.append(f"[URL] {url}")
|
|
100
|
-
|
|
101
|
-
if not results:
|
|
102
|
-
return "No links found in the text."
|
|
103
|
-
|
|
104
|
-
output = ["=" * 50, "EXTRACTED LINKS", "=" * 50, ""]
|
|
105
|
-
output.extend(results)
|
|
106
|
-
output.append("")
|
|
107
|
-
output.append(f"Total: {len(results)} link(s) found")
|
|
108
|
-
output.append("=" * 50)
|
|
109
|
-
|
|
110
|
-
return '\n'.join(output)
|
|
111
|
-
|
|
112
|
-
@staticmethod
|
|
113
|
-
def extract_headers(text, format_style="indented"):
|
|
114
|
-
"""Extract all headers from markdown text."""
|
|
115
|
-
headers = re.findall(r'^(#{1,6})\s+(.+)$', text, re.MULTILINE)
|
|
116
|
-
|
|
117
|
-
if not headers:
|
|
118
|
-
return "No headers found in the text."
|
|
119
|
-
|
|
120
|
-
results = []
|
|
121
|
-
results.append("=" * 50)
|
|
122
|
-
results.append("EXTRACTED HEADERS")
|
|
123
|
-
results.append("=" * 50)
|
|
124
|
-
results.append("")
|
|
125
|
-
|
|
126
|
-
for i, (hashes, header_text) in enumerate(headers, 1):
|
|
127
|
-
level = len(hashes)
|
|
128
|
-
|
|
129
|
-
if format_style == "indented":
|
|
130
|
-
indent = " " * (level - 1)
|
|
131
|
-
results.append(f"{indent}{header_text}")
|
|
132
|
-
elif format_style == "flat":
|
|
133
|
-
results.append(f"H{level}: {header_text}")
|
|
134
|
-
elif format_style == "numbered":
|
|
135
|
-
results.append(f"{i}. [{level}] {header_text}")
|
|
136
|
-
|
|
137
|
-
results.append("")
|
|
138
|
-
results.append(f"Total: {len(headers)} header(s) found")
|
|
139
|
-
results.append("=" * 50)
|
|
140
|
-
|
|
141
|
-
return '\n'.join(results)
|
|
142
|
-
|
|
143
|
-
@staticmethod
|
|
144
|
-
def table_to_csv(text, delimiter=","):
|
|
145
|
-
"""Convert markdown tables to CSV format."""
|
|
146
|
-
lines = text.strip().split('\n')
|
|
147
|
-
tables = []
|
|
148
|
-
current_table = []
|
|
149
|
-
in_table = False
|
|
150
|
-
|
|
151
|
-
for line in lines:
|
|
152
|
-
line = line.strip()
|
|
153
|
-
if '|' in line:
|
|
154
|
-
# Skip separator lines (containing only |, -, :, and spaces)
|
|
155
|
-
if re.match(r'^[\|\-:\s]+$', line):
|
|
156
|
-
continue
|
|
157
|
-
|
|
158
|
-
# Parse table row
|
|
159
|
-
cells = [cell.strip() for cell in line.split('|')]
|
|
160
|
-
# Remove empty first/last cells from leading/trailing |
|
|
161
|
-
if cells and not cells[0]:
|
|
162
|
-
cells = cells[1:]
|
|
163
|
-
if cells and not cells[-1]:
|
|
164
|
-
cells = cells[:-1]
|
|
165
|
-
|
|
166
|
-
if cells:
|
|
167
|
-
current_table.append(cells)
|
|
168
|
-
in_table = True
|
|
169
|
-
else:
|
|
170
|
-
if in_table and current_table:
|
|
171
|
-
tables.append(current_table)
|
|
172
|
-
current_table = []
|
|
173
|
-
in_table = False
|
|
174
|
-
|
|
175
|
-
# Don't forget the last table
|
|
176
|
-
if current_table:
|
|
177
|
-
tables.append(current_table)
|
|
178
|
-
|
|
179
|
-
if not tables:
|
|
180
|
-
return "No markdown tables found in the text."
|
|
181
|
-
|
|
182
|
-
results = []
|
|
183
|
-
for i, table in enumerate(tables):
|
|
184
|
-
if i > 0:
|
|
185
|
-
results.append("")
|
|
186
|
-
results.append(f"--- Table {i + 1} ---")
|
|
187
|
-
results.append("")
|
|
188
|
-
|
|
189
|
-
for row in table:
|
|
190
|
-
# Escape delimiter in cells and quote if necessary
|
|
191
|
-
escaped_cells = []
|
|
192
|
-
for cell in row:
|
|
193
|
-
if delimiter in cell or '"' in cell or '\n' in cell:
|
|
194
|
-
cell = '"' + cell.replace('"', '""') + '"'
|
|
195
|
-
escaped_cells.append(cell)
|
|
196
|
-
results.append(delimiter.join(escaped_cells))
|
|
197
|
-
|
|
198
|
-
return '\n'.join(results)
|
|
199
|
-
|
|
200
|
-
@staticmethod
|
|
201
|
-
def format_table(text):
|
|
202
|
-
"""Auto-align markdown tables."""
|
|
203
|
-
lines = text.strip().split('\n')
|
|
204
|
-
result_lines = []
|
|
205
|
-
current_table = []
|
|
206
|
-
table_start_idx = -1
|
|
207
|
-
|
|
208
|
-
for i, line in enumerate(lines):
|
|
209
|
-
line_stripped = line.strip()
|
|
210
|
-
if '|' in line_stripped:
|
|
211
|
-
if table_start_idx == -1:
|
|
212
|
-
table_start_idx = len(result_lines)
|
|
213
|
-
current_table.append(line_stripped)
|
|
214
|
-
else:
|
|
215
|
-
if current_table:
|
|
216
|
-
# Process and format the table
|
|
217
|
-
formatted = MarkdownToolsProcessor._format_single_table(current_table)
|
|
218
|
-
result_lines.extend(formatted)
|
|
219
|
-
current_table = []
|
|
220
|
-
table_start_idx = -1
|
|
221
|
-
result_lines.append(line)
|
|
222
|
-
|
|
223
|
-
# Handle table at end of text
|
|
224
|
-
if current_table:
|
|
225
|
-
formatted = MarkdownToolsProcessor._format_single_table(current_table)
|
|
226
|
-
result_lines.extend(formatted)
|
|
227
|
-
|
|
228
|
-
return '\n'.join(result_lines)
|
|
229
|
-
|
|
230
|
-
@staticmethod
|
|
231
|
-
def _format_single_table(table_lines):
|
|
232
|
-
"""Format a single markdown table."""
|
|
233
|
-
rows = []
|
|
234
|
-
separator_idx = -1
|
|
235
|
-
|
|
236
|
-
for i, line in enumerate(table_lines):
|
|
237
|
-
if re.match(r'^[\|\-:\s]+$', line):
|
|
238
|
-
separator_idx = i
|
|
239
|
-
continue
|
|
240
|
-
|
|
241
|
-
cells = [cell.strip() for cell in line.split('|')]
|
|
242
|
-
if cells and not cells[0]:
|
|
243
|
-
cells = cells[1:]
|
|
244
|
-
if cells and not cells[-1]:
|
|
245
|
-
cells = cells[:-1]
|
|
246
|
-
rows.append(cells)
|
|
247
|
-
|
|
248
|
-
if not rows:
|
|
249
|
-
return table_lines
|
|
250
|
-
|
|
251
|
-
# Calculate column widths
|
|
252
|
-
num_cols = max(len(row) for row in rows)
|
|
253
|
-
col_widths = [0] * num_cols
|
|
254
|
-
|
|
255
|
-
for row in rows:
|
|
256
|
-
for j, cell in enumerate(row):
|
|
257
|
-
if j < num_cols:
|
|
258
|
-
col_widths[j] = max(col_widths[j], len(cell))
|
|
259
|
-
|
|
260
|
-
# Ensure minimum width of 3 for separator
|
|
261
|
-
col_widths = [max(w, 3) for w in col_widths]
|
|
262
|
-
|
|
263
|
-
# Format rows
|
|
264
|
-
formatted = []
|
|
265
|
-
for i, row in enumerate(rows):
|
|
266
|
-
padded = []
|
|
267
|
-
for j in range(num_cols):
|
|
268
|
-
cell = row[j] if j < len(row) else ""
|
|
269
|
-
padded.append(cell.ljust(col_widths[j]))
|
|
270
|
-
formatted.append("| " + " | ".join(padded) + " |")
|
|
271
|
-
|
|
272
|
-
# Add separator after header (first row)
|
|
273
|
-
if i == 0:
|
|
274
|
-
sep_parts = ["-" * w for w in col_widths]
|
|
275
|
-
formatted.append("| " + " | ".join(sep_parts) + " |")
|
|
276
|
-
|
|
277
|
-
return formatted
|
|
278
|
-
|
|
279
|
-
@staticmethod
|
|
280
|
-
def process_text(input_text, tool_type, settings):
|
|
281
|
-
"""Process text using the specified markdown tool and settings."""
|
|
282
|
-
if tool_type == "Strip Markdown":
|
|
283
|
-
return MarkdownToolsProcessor.strip_markdown(
|
|
284
|
-
input_text,
|
|
285
|
-
settings.get("preserve_links_text", True)
|
|
286
|
-
)
|
|
287
|
-
elif tool_type == "Extract Links":
|
|
288
|
-
return MarkdownToolsProcessor.extract_links(
|
|
289
|
-
input_text,
|
|
290
|
-
settings.get("include_images", False)
|
|
291
|
-
)
|
|
292
|
-
elif tool_type == "Extract Headers":
|
|
293
|
-
return MarkdownToolsProcessor.extract_headers(
|
|
294
|
-
input_text,
|
|
295
|
-
settings.get("header_format", "indented")
|
|
296
|
-
)
|
|
297
|
-
elif tool_type == "Table to CSV":
|
|
298
|
-
return MarkdownToolsProcessor.table_to_csv(
|
|
299
|
-
input_text,
|
|
300
|
-
settings.get("csv_delimiter", ",")
|
|
301
|
-
)
|
|
302
|
-
elif tool_type == "Format Table":
|
|
303
|
-
return MarkdownToolsProcessor.format_table(input_text)
|
|
304
|
-
else:
|
|
305
|
-
return f"Unknown markdown tool: {tool_type}"
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
class MarkdownToolsWidget(ttk.Frame):
|
|
309
|
-
"""Tabbed interface widget for markdown tools."""
|
|
310
|
-
|
|
311
|
-
def __init__(self, parent, app):
|
|
312
|
-
super().__init__(parent)
|
|
313
|
-
self.app = app
|
|
314
|
-
self.processor = MarkdownToolsProcessor()
|
|
315
|
-
|
|
316
|
-
self.preserve_links_text = tk.BooleanVar(value=True)
|
|
317
|
-
self.include_images = tk.BooleanVar(value=False)
|
|
318
|
-
self.header_format = tk.StringVar(value="indented")
|
|
319
|
-
self.csv_delimiter = tk.StringVar(value=",")
|
|
320
|
-
|
|
321
|
-
self.create_widgets()
|
|
322
|
-
self.load_settings()
|
|
323
|
-
|
|
324
|
-
def create_widgets(self):
|
|
325
|
-
"""Creates the tabbed interface for markdown tools."""
|
|
326
|
-
self.notebook = ttk.Notebook(self)
|
|
327
|
-
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
328
|
-
|
|
329
|
-
self.create_strip_tab()
|
|
330
|
-
self.create_links_tab()
|
|
331
|
-
self.create_headers_tab()
|
|
332
|
-
self.create_table_csv_tab()
|
|
333
|
-
self.create_format_table_tab()
|
|
334
|
-
|
|
335
|
-
def create_strip_tab(self):
|
|
336
|
-
"""Creates the Strip Markdown tab."""
|
|
337
|
-
frame = ttk.Frame(self.notebook)
|
|
338
|
-
self.notebook.add(frame, text="Strip Markdown")
|
|
339
|
-
|
|
340
|
-
options_frame = ttk.LabelFrame(frame, text="Options", padding=10)
|
|
341
|
-
options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
342
|
-
|
|
343
|
-
ttk.Checkbutton(options_frame, text="Preserve Link Text",
|
|
344
|
-
variable=self.preserve_links_text,
|
|
345
|
-
command=self.on_setting_change).pack(anchor=tk.W)
|
|
346
|
-
|
|
347
|
-
info = ttk.Label(frame, text="Removes all markdown formatting (headers, bold, italic,\n"
|
|
348
|
-
"links, images, code blocks, lists, etc.)",
|
|
349
|
-
justify=tk.CENTER)
|
|
350
|
-
info.pack(pady=10)
|
|
351
|
-
|
|
352
|
-
ttk.Button(frame, text="Strip Markdown",
|
|
353
|
-
command=lambda: self.process("Strip Markdown")).pack(pady=10)
|
|
354
|
-
|
|
355
|
-
def create_links_tab(self):
|
|
356
|
-
"""Creates the Extract Links tab."""
|
|
357
|
-
frame = ttk.Frame(self.notebook)
|
|
358
|
-
self.notebook.add(frame, text="Extract Links")
|
|
359
|
-
|
|
360
|
-
options_frame = ttk.LabelFrame(frame, text="Options", padding=10)
|
|
361
|
-
options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
362
|
-
|
|
363
|
-
ttk.Checkbutton(options_frame, text="Include Image URLs",
|
|
364
|
-
variable=self.include_images,
|
|
365
|
-
command=self.on_setting_change).pack(anchor=tk.W)
|
|
366
|
-
|
|
367
|
-
info = ttk.Label(frame, text="Extracts all links from markdown text,\n"
|
|
368
|
-
"including inline links and reference-style links.",
|
|
369
|
-
justify=tk.CENTER)
|
|
370
|
-
info.pack(pady=10)
|
|
371
|
-
|
|
372
|
-
ttk.Button(frame, text="Extract Links",
|
|
373
|
-
command=lambda: self.process("Extract Links")).pack(pady=10)
|
|
374
|
-
|
|
375
|
-
def create_headers_tab(self):
|
|
376
|
-
"""Creates the Extract Headers tab."""
|
|
377
|
-
frame = ttk.Frame(self.notebook)
|
|
378
|
-
self.notebook.add(frame, text="Extract Headers")
|
|
379
|
-
|
|
380
|
-
format_frame = ttk.LabelFrame(frame, text="Output Format", padding=10)
|
|
381
|
-
format_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
382
|
-
|
|
383
|
-
ttk.Radiobutton(format_frame, text="Indented (hierarchy)",
|
|
384
|
-
variable=self.header_format, value="indented",
|
|
385
|
-
command=self.on_setting_change).pack(anchor=tk.W)
|
|
386
|
-
ttk.Radiobutton(format_frame, text="Flat (H1, H2, etc.)",
|
|
387
|
-
variable=self.header_format, value="flat",
|
|
388
|
-
command=self.on_setting_change).pack(anchor=tk.W)
|
|
389
|
-
ttk.Radiobutton(format_frame, text="Numbered",
|
|
390
|
-
variable=self.header_format, value="numbered",
|
|
391
|
-
command=self.on_setting_change).pack(anchor=tk.W)
|
|
392
|
-
|
|
393
|
-
ttk.Button(frame, text="Extract Headers",
|
|
394
|
-
command=lambda: self.process("Extract Headers")).pack(pady=10)
|
|
395
|
-
|
|
396
|
-
def create_table_csv_tab(self):
|
|
397
|
-
"""Creates the Table to CSV tab."""
|
|
398
|
-
frame = ttk.Frame(self.notebook)
|
|
399
|
-
self.notebook.add(frame, text="Table to CSV")
|
|
400
|
-
|
|
401
|
-
delimiter_frame = ttk.LabelFrame(frame, text="CSV Delimiter", padding=10)
|
|
402
|
-
delimiter_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
403
|
-
|
|
404
|
-
ttk.Label(delimiter_frame, text="Delimiter:").pack(side=tk.LEFT)
|
|
405
|
-
delimiter_combo = ttk.Combobox(delimiter_frame, textvariable=self.csv_delimiter,
|
|
406
|
-
values=[",", ";", "\t", "|"], width=5)
|
|
407
|
-
delimiter_combo.pack(side=tk.LEFT, padx=5)
|
|
408
|
-
delimiter_combo.bind("<<ComboboxSelected>>", lambda e: self.on_setting_change())
|
|
409
|
-
|
|
410
|
-
info = ttk.Label(frame, text="Converts markdown tables to CSV format.",
|
|
411
|
-
justify=tk.CENTER)
|
|
412
|
-
info.pack(pady=10)
|
|
413
|
-
|
|
414
|
-
ttk.Button(frame, text="Convert to CSV",
|
|
415
|
-
command=lambda: self.process("Table to CSV")).pack(pady=10)
|
|
416
|
-
|
|
417
|
-
def create_format_table_tab(self):
|
|
418
|
-
"""Creates the Format Table tab."""
|
|
419
|
-
frame = ttk.Frame(self.notebook)
|
|
420
|
-
self.notebook.add(frame, text="Format Table")
|
|
421
|
-
|
|
422
|
-
info = ttk.Label(frame, text="Auto-aligns markdown tables by padding cells\n"
|
|
423
|
-
"to create properly aligned columns.",
|
|
424
|
-
justify=tk.CENTER)
|
|
425
|
-
info.pack(pady=20)
|
|
426
|
-
|
|
427
|
-
ttk.Button(frame, text="Format Table",
|
|
428
|
-
command=lambda: self.process("Format Table")).pack(pady=10)
|
|
429
|
-
|
|
430
|
-
def load_settings(self):
|
|
431
|
-
"""Load settings from the application."""
|
|
432
|
-
settings = self.app.settings.get("tool_settings", {}).get("Markdown Tools", {})
|
|
433
|
-
|
|
434
|
-
self.preserve_links_text.set(settings.get("preserve_links_text", True))
|
|
435
|
-
self.include_images.set(settings.get("include_images", False))
|
|
436
|
-
self.header_format.set(settings.get("header_format", "indented"))
|
|
437
|
-
self.csv_delimiter.set(settings.get("csv_delimiter", ","))
|
|
438
|
-
|
|
439
|
-
def save_settings(self):
|
|
440
|
-
"""Save current settings to the application."""
|
|
441
|
-
if "Markdown Tools" not in self.app.settings["tool_settings"]:
|
|
442
|
-
self.app.settings["tool_settings"]["Markdown Tools"] = {}
|
|
443
|
-
|
|
444
|
-
self.app.settings["tool_settings"]["Markdown Tools"].update({
|
|
445
|
-
"preserve_links_text": self.preserve_links_text.get(),
|
|
446
|
-
"include_images": self.include_images.get(),
|
|
447
|
-
"header_format": self.header_format.get(),
|
|
448
|
-
"csv_delimiter": self.csv_delimiter.get()
|
|
449
|
-
})
|
|
450
|
-
|
|
451
|
-
self.app.save_settings()
|
|
452
|
-
|
|
453
|
-
def on_setting_change(self, *args):
|
|
454
|
-
"""Handle setting changes."""
|
|
455
|
-
self.save_settings()
|
|
456
|
-
|
|
457
|
-
def process(self, tool_type):
|
|
458
|
-
"""Process the input text with the selected tool."""
|
|
459
|
-
active_input_tab = self.app.input_tabs[self.app.input_notebook.index(self.app.input_notebook.select())]
|
|
460
|
-
input_text = active_input_tab.text.get("1.0", tk.END).rstrip('\n')
|
|
461
|
-
|
|
462
|
-
if not input_text.strip():
|
|
463
|
-
return
|
|
464
|
-
|
|
465
|
-
settings = {
|
|
466
|
-
"preserve_links_text": self.preserve_links_text.get(),
|
|
467
|
-
"include_images": self.include_images.get(),
|
|
468
|
-
"header_format": self.header_format.get(),
|
|
469
|
-
"csv_delimiter": self.csv_delimiter.get()
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
result = MarkdownToolsProcessor.process_text(input_text, tool_type, settings)
|
|
473
|
-
|
|
474
|
-
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
475
|
-
active_output_tab.text.config(state="normal")
|
|
476
|
-
active_output_tab.text.delete("1.0", tk.END)
|
|
477
|
-
active_output_tab.text.insert("1.0", result)
|
|
478
|
-
active_output_tab.text.config(state="disabled")
|
|
479
|
-
|
|
480
|
-
self.app.update_all_stats()
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
class MarkdownTools:
|
|
484
|
-
"""Main class for Markdown Tools integration."""
|
|
485
|
-
|
|
486
|
-
def __init__(self):
|
|
487
|
-
self.processor = MarkdownToolsProcessor()
|
|
488
|
-
|
|
489
|
-
def create_widget(self, parent, app):
|
|
490
|
-
"""Create and return the Markdown Tools widget."""
|
|
491
|
-
return MarkdownToolsWidget(parent, app)
|
|
492
|
-
|
|
493
|
-
def get_default_settings(self):
|
|
494
|
-
"""Return default settings for Markdown Tools."""
|
|
495
|
-
return {
|
|
496
|
-
"preserve_links_text": True,
|
|
497
|
-
"include_images": False,
|
|
498
|
-
"header_format": "indented",
|
|
499
|
-
"csv_delimiter": ","
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
def process_text(self, input_text, tool_type, settings):
|
|
503
|
-
"""Process text using the specified tool and settings."""
|
|
504
|
-
return MarkdownToolsProcessor.process_text(input_text, tool_type, settings)
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
# BaseTool-compatible wrapper
|
|
508
|
-
try:
|
|
509
|
-
from tools.base_tool import ToolWithOptions
|
|
510
|
-
from typing import Dict, Any
|
|
511
|
-
|
|
512
|
-
class MarkdownToolsV2(ToolWithOptions):
|
|
513
|
-
"""
|
|
514
|
-
BaseTool-compatible version of MarkdownTools.
|
|
515
|
-
"""
|
|
516
|
-
|
|
517
|
-
TOOL_NAME = "Markdown Tools"
|
|
518
|
-
TOOL_DESCRIPTION = "Process and manipulate markdown text"
|
|
519
|
-
TOOL_VERSION = "2.0.0"
|
|
520
|
-
|
|
521
|
-
OPTIONS = [
|
|
522
|
-
("Strip Markdown", "strip"),
|
|
523
|
-
("Extract Links", "extract_links"),
|
|
524
|
-
("Extract Headers", "extract_headers"),
|
|
525
|
-
("Table to CSV", "table_to_csv"),
|
|
526
|
-
("Format Table", "format_table"),
|
|
527
|
-
]
|
|
528
|
-
OPTIONS_LABEL = "Operation"
|
|
529
|
-
USE_DROPDOWN = True
|
|
530
|
-
DEFAULT_OPTION = "strip"
|
|
531
|
-
|
|
532
|
-
def process_text(self, input_text: str, settings: Dict[str, Any]) -> str:
|
|
533
|
-
"""Process markdown text."""
|
|
534
|
-
mode = settings.get("mode", "strip")
|
|
535
|
-
|
|
536
|
-
if mode == "strip":
|
|
537
|
-
return MarkdownToolsProcessor.strip_markdown(
|
|
538
|
-
input_text,
|
|
539
|
-
settings.get("preserve_links_text", True)
|
|
540
|
-
)
|
|
541
|
-
elif mode == "extract_links":
|
|
542
|
-
return MarkdownToolsProcessor.extract_links(
|
|
543
|
-
input_text,
|
|
544
|
-
settings.get("include_images", False)
|
|
545
|
-
)
|
|
546
|
-
elif mode == "extract_headers":
|
|
547
|
-
return MarkdownToolsProcessor.extract_headers(
|
|
548
|
-
input_text,
|
|
549
|
-
settings.get("header_format", "indented")
|
|
550
|
-
)
|
|
551
|
-
elif mode == "table_to_csv":
|
|
552
|
-
return MarkdownToolsProcessor.table_to_csv(
|
|
553
|
-
input_text,
|
|
554
|
-
settings.get("csv_delimiter", ",")
|
|
555
|
-
)
|
|
556
|
-
elif mode == "format_table":
|
|
557
|
-
return MarkdownToolsProcessor.format_table(input_text)
|
|
558
|
-
else:
|
|
559
|
-
return input_text
|
|
560
|
-
|
|
561
|
-
except ImportError:
|
|
1
|
+
"""
|
|
2
|
+
Markdown Tools Module - Markdown processing utilities
|
|
3
|
+
|
|
4
|
+
This module provides markdown manipulation functionality with a tabbed UI interface
|
|
5
|
+
for the Pomera AI Commander application.
|
|
6
|
+
|
|
7
|
+
Features:
|
|
8
|
+
- Strip Markdown: Remove all markdown formatting
|
|
9
|
+
- Extract Links: Extract all links from markdown
|
|
10
|
+
- Extract Headers: Extract all headers with hierarchy
|
|
11
|
+
- Table to CSV: Convert markdown tables to CSV
|
|
12
|
+
- Format Table: Auto-align markdown tables
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import tkinter as tk
|
|
16
|
+
from tkinter import ttk
|
|
17
|
+
import re
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MarkdownToolsProcessor:
|
|
21
|
+
"""Markdown tools processor with various markdown manipulation capabilities."""
|
|
22
|
+
|
|
23
|
+
@staticmethod
|
|
24
|
+
def strip_markdown(text, preserve_links_text=True):
|
|
25
|
+
"""Remove all markdown formatting from text."""
|
|
26
|
+
result = text
|
|
27
|
+
|
|
28
|
+
# Remove code blocks
|
|
29
|
+
result = re.sub(r'```[\s\S]*?```', '', result)
|
|
30
|
+
result = re.sub(r'`[^`]+`', lambda m: m.group(0)[1:-1], result)
|
|
31
|
+
|
|
32
|
+
# Handle links
|
|
33
|
+
if preserve_links_text:
|
|
34
|
+
result = re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', result)
|
|
35
|
+
else:
|
|
36
|
+
result = re.sub(r'\[([^\]]+)\]\([^\)]+\)', '', result)
|
|
37
|
+
|
|
38
|
+
# Remove images
|
|
39
|
+
result = re.sub(r'!\[([^\]]*)\]\([^\)]+\)', r'\1', result)
|
|
40
|
+
|
|
41
|
+
# Remove headers
|
|
42
|
+
result = re.sub(r'^#{1,6}\s+', '', result, flags=re.MULTILINE)
|
|
43
|
+
|
|
44
|
+
# Remove bold and italic
|
|
45
|
+
result = re.sub(r'\*\*\*([^*]+)\*\*\*', r'\1', result)
|
|
46
|
+
result = re.sub(r'\*\*([^*]+)\*\*', r'\1', result)
|
|
47
|
+
result = re.sub(r'\*([^*]+)\*', r'\1', result)
|
|
48
|
+
result = re.sub(r'___([^_]+)___', r'\1', result)
|
|
49
|
+
result = re.sub(r'__([^_]+)__', r'\1', result)
|
|
50
|
+
result = re.sub(r'_([^_]+)_', r'\1', result)
|
|
51
|
+
|
|
52
|
+
# Remove strikethrough
|
|
53
|
+
result = re.sub(r'~~([^~]+)~~', r'\1', result)
|
|
54
|
+
|
|
55
|
+
# Remove blockquotes
|
|
56
|
+
result = re.sub(r'^>\s*', '', result, flags=re.MULTILINE)
|
|
57
|
+
|
|
58
|
+
# Remove horizontal rules
|
|
59
|
+
result = re.sub(r'^[-*_]{3,}\s*$', '', result, flags=re.MULTILINE)
|
|
60
|
+
|
|
61
|
+
# Remove list markers
|
|
62
|
+
result = re.sub(r'^\s*[-*+]\s+', '', result, flags=re.MULTILINE)
|
|
63
|
+
result = re.sub(r'^\s*\d+\.\s+', '', result, flags=re.MULTILINE)
|
|
64
|
+
|
|
65
|
+
# Clean up extra whitespace
|
|
66
|
+
result = re.sub(r'\n{3,}', '\n\n', result)
|
|
67
|
+
|
|
68
|
+
return result.strip()
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def extract_links(text, include_images=False):
|
|
72
|
+
"""Extract all links from markdown text."""
|
|
73
|
+
results = []
|
|
74
|
+
|
|
75
|
+
# Extract regular links [text](url)
|
|
76
|
+
links = re.findall(r'\[([^\]]+)\]\(([^\)]+)\)', text)
|
|
77
|
+
for link_text, url in links:
|
|
78
|
+
if not url.startswith('!'):
|
|
79
|
+
results.append(f"{link_text}: {url}")
|
|
80
|
+
|
|
81
|
+
# Extract images if requested 
|
|
82
|
+
if include_images:
|
|
83
|
+
images = re.findall(r'!\[([^\]]*)\]\(([^\)]+)\)', text)
|
|
84
|
+
for alt_text, url in images:
|
|
85
|
+
results.append(f"[IMAGE] {alt_text or 'No alt text'}: {url}")
|
|
86
|
+
|
|
87
|
+
# Extract reference-style links [text][ref] and [ref]: url
|
|
88
|
+
ref_defs = dict(re.findall(r'^\[([^\]]+)\]:\s*(.+)$', text, re.MULTILINE))
|
|
89
|
+
ref_links = re.findall(r'\[([^\]]+)\]\[([^\]]*)\]', text)
|
|
90
|
+
for link_text, ref in ref_links:
|
|
91
|
+
ref_key = ref if ref else link_text
|
|
92
|
+
if ref_key.lower() in {k.lower(): k for k in ref_defs}:
|
|
93
|
+
actual_key = next(k for k in ref_defs if k.lower() == ref_key.lower())
|
|
94
|
+
results.append(f"{link_text}: {ref_defs[actual_key]}")
|
|
95
|
+
|
|
96
|
+
# Extract bare URLs
|
|
97
|
+
bare_urls = re.findall(r'<(https?://[^>]+)>', text)
|
|
98
|
+
for url in bare_urls:
|
|
99
|
+
results.append(f"[URL] {url}")
|
|
100
|
+
|
|
101
|
+
if not results:
|
|
102
|
+
return "No links found in the text."
|
|
103
|
+
|
|
104
|
+
output = ["=" * 50, "EXTRACTED LINKS", "=" * 50, ""]
|
|
105
|
+
output.extend(results)
|
|
106
|
+
output.append("")
|
|
107
|
+
output.append(f"Total: {len(results)} link(s) found")
|
|
108
|
+
output.append("=" * 50)
|
|
109
|
+
|
|
110
|
+
return '\n'.join(output)
|
|
111
|
+
|
|
112
|
+
@staticmethod
|
|
113
|
+
def extract_headers(text, format_style="indented"):
|
|
114
|
+
"""Extract all headers from markdown text."""
|
|
115
|
+
headers = re.findall(r'^(#{1,6})\s+(.+)$', text, re.MULTILINE)
|
|
116
|
+
|
|
117
|
+
if not headers:
|
|
118
|
+
return "No headers found in the text."
|
|
119
|
+
|
|
120
|
+
results = []
|
|
121
|
+
results.append("=" * 50)
|
|
122
|
+
results.append("EXTRACTED HEADERS")
|
|
123
|
+
results.append("=" * 50)
|
|
124
|
+
results.append("")
|
|
125
|
+
|
|
126
|
+
for i, (hashes, header_text) in enumerate(headers, 1):
|
|
127
|
+
level = len(hashes)
|
|
128
|
+
|
|
129
|
+
if format_style == "indented":
|
|
130
|
+
indent = " " * (level - 1)
|
|
131
|
+
results.append(f"{indent}{header_text}")
|
|
132
|
+
elif format_style == "flat":
|
|
133
|
+
results.append(f"H{level}: {header_text}")
|
|
134
|
+
elif format_style == "numbered":
|
|
135
|
+
results.append(f"{i}. [{level}] {header_text}")
|
|
136
|
+
|
|
137
|
+
results.append("")
|
|
138
|
+
results.append(f"Total: {len(headers)} header(s) found")
|
|
139
|
+
results.append("=" * 50)
|
|
140
|
+
|
|
141
|
+
return '\n'.join(results)
|
|
142
|
+
|
|
143
|
+
@staticmethod
|
|
144
|
+
def table_to_csv(text, delimiter=","):
|
|
145
|
+
"""Convert markdown tables to CSV format."""
|
|
146
|
+
lines = text.strip().split('\n')
|
|
147
|
+
tables = []
|
|
148
|
+
current_table = []
|
|
149
|
+
in_table = False
|
|
150
|
+
|
|
151
|
+
for line in lines:
|
|
152
|
+
line = line.strip()
|
|
153
|
+
if '|' in line:
|
|
154
|
+
# Skip separator lines (containing only |, -, :, and spaces)
|
|
155
|
+
if re.match(r'^[\|\-:\s]+$', line):
|
|
156
|
+
continue
|
|
157
|
+
|
|
158
|
+
# Parse table row
|
|
159
|
+
cells = [cell.strip() for cell in line.split('|')]
|
|
160
|
+
# Remove empty first/last cells from leading/trailing |
|
|
161
|
+
if cells and not cells[0]:
|
|
162
|
+
cells = cells[1:]
|
|
163
|
+
if cells and not cells[-1]:
|
|
164
|
+
cells = cells[:-1]
|
|
165
|
+
|
|
166
|
+
if cells:
|
|
167
|
+
current_table.append(cells)
|
|
168
|
+
in_table = True
|
|
169
|
+
else:
|
|
170
|
+
if in_table and current_table:
|
|
171
|
+
tables.append(current_table)
|
|
172
|
+
current_table = []
|
|
173
|
+
in_table = False
|
|
174
|
+
|
|
175
|
+
# Don't forget the last table
|
|
176
|
+
if current_table:
|
|
177
|
+
tables.append(current_table)
|
|
178
|
+
|
|
179
|
+
if not tables:
|
|
180
|
+
return "No markdown tables found in the text."
|
|
181
|
+
|
|
182
|
+
results = []
|
|
183
|
+
for i, table in enumerate(tables):
|
|
184
|
+
if i > 0:
|
|
185
|
+
results.append("")
|
|
186
|
+
results.append(f"--- Table {i + 1} ---")
|
|
187
|
+
results.append("")
|
|
188
|
+
|
|
189
|
+
for row in table:
|
|
190
|
+
# Escape delimiter in cells and quote if necessary
|
|
191
|
+
escaped_cells = []
|
|
192
|
+
for cell in row:
|
|
193
|
+
if delimiter in cell or '"' in cell or '\n' in cell:
|
|
194
|
+
cell = '"' + cell.replace('"', '""') + '"'
|
|
195
|
+
escaped_cells.append(cell)
|
|
196
|
+
results.append(delimiter.join(escaped_cells))
|
|
197
|
+
|
|
198
|
+
return '\n'.join(results)
|
|
199
|
+
|
|
200
|
+
@staticmethod
|
|
201
|
+
def format_table(text):
|
|
202
|
+
"""Auto-align markdown tables."""
|
|
203
|
+
lines = text.strip().split('\n')
|
|
204
|
+
result_lines = []
|
|
205
|
+
current_table = []
|
|
206
|
+
table_start_idx = -1
|
|
207
|
+
|
|
208
|
+
for i, line in enumerate(lines):
|
|
209
|
+
line_stripped = line.strip()
|
|
210
|
+
if '|' in line_stripped:
|
|
211
|
+
if table_start_idx == -1:
|
|
212
|
+
table_start_idx = len(result_lines)
|
|
213
|
+
current_table.append(line_stripped)
|
|
214
|
+
else:
|
|
215
|
+
if current_table:
|
|
216
|
+
# Process and format the table
|
|
217
|
+
formatted = MarkdownToolsProcessor._format_single_table(current_table)
|
|
218
|
+
result_lines.extend(formatted)
|
|
219
|
+
current_table = []
|
|
220
|
+
table_start_idx = -1
|
|
221
|
+
result_lines.append(line)
|
|
222
|
+
|
|
223
|
+
# Handle table at end of text
|
|
224
|
+
if current_table:
|
|
225
|
+
formatted = MarkdownToolsProcessor._format_single_table(current_table)
|
|
226
|
+
result_lines.extend(formatted)
|
|
227
|
+
|
|
228
|
+
return '\n'.join(result_lines)
|
|
229
|
+
|
|
230
|
+
@staticmethod
|
|
231
|
+
def _format_single_table(table_lines):
|
|
232
|
+
"""Format a single markdown table."""
|
|
233
|
+
rows = []
|
|
234
|
+
separator_idx = -1
|
|
235
|
+
|
|
236
|
+
for i, line in enumerate(table_lines):
|
|
237
|
+
if re.match(r'^[\|\-:\s]+$', line):
|
|
238
|
+
separator_idx = i
|
|
239
|
+
continue
|
|
240
|
+
|
|
241
|
+
cells = [cell.strip() for cell in line.split('|')]
|
|
242
|
+
if cells and not cells[0]:
|
|
243
|
+
cells = cells[1:]
|
|
244
|
+
if cells and not cells[-1]:
|
|
245
|
+
cells = cells[:-1]
|
|
246
|
+
rows.append(cells)
|
|
247
|
+
|
|
248
|
+
if not rows:
|
|
249
|
+
return table_lines
|
|
250
|
+
|
|
251
|
+
# Calculate column widths
|
|
252
|
+
num_cols = max(len(row) for row in rows)
|
|
253
|
+
col_widths = [0] * num_cols
|
|
254
|
+
|
|
255
|
+
for row in rows:
|
|
256
|
+
for j, cell in enumerate(row):
|
|
257
|
+
if j < num_cols:
|
|
258
|
+
col_widths[j] = max(col_widths[j], len(cell))
|
|
259
|
+
|
|
260
|
+
# Ensure minimum width of 3 for separator
|
|
261
|
+
col_widths = [max(w, 3) for w in col_widths]
|
|
262
|
+
|
|
263
|
+
# Format rows
|
|
264
|
+
formatted = []
|
|
265
|
+
for i, row in enumerate(rows):
|
|
266
|
+
padded = []
|
|
267
|
+
for j in range(num_cols):
|
|
268
|
+
cell = row[j] if j < len(row) else ""
|
|
269
|
+
padded.append(cell.ljust(col_widths[j]))
|
|
270
|
+
formatted.append("| " + " | ".join(padded) + " |")
|
|
271
|
+
|
|
272
|
+
# Add separator after header (first row)
|
|
273
|
+
if i == 0:
|
|
274
|
+
sep_parts = ["-" * w for w in col_widths]
|
|
275
|
+
formatted.append("| " + " | ".join(sep_parts) + " |")
|
|
276
|
+
|
|
277
|
+
return formatted
|
|
278
|
+
|
|
279
|
+
@staticmethod
|
|
280
|
+
def process_text(input_text, tool_type, settings):
|
|
281
|
+
"""Process text using the specified markdown tool and settings."""
|
|
282
|
+
if tool_type == "Strip Markdown":
|
|
283
|
+
return MarkdownToolsProcessor.strip_markdown(
|
|
284
|
+
input_text,
|
|
285
|
+
settings.get("preserve_links_text", True)
|
|
286
|
+
)
|
|
287
|
+
elif tool_type == "Extract Links":
|
|
288
|
+
return MarkdownToolsProcessor.extract_links(
|
|
289
|
+
input_text,
|
|
290
|
+
settings.get("include_images", False)
|
|
291
|
+
)
|
|
292
|
+
elif tool_type == "Extract Headers":
|
|
293
|
+
return MarkdownToolsProcessor.extract_headers(
|
|
294
|
+
input_text,
|
|
295
|
+
settings.get("header_format", "indented")
|
|
296
|
+
)
|
|
297
|
+
elif tool_type == "Table to CSV":
|
|
298
|
+
return MarkdownToolsProcessor.table_to_csv(
|
|
299
|
+
input_text,
|
|
300
|
+
settings.get("csv_delimiter", ",")
|
|
301
|
+
)
|
|
302
|
+
elif tool_type == "Format Table":
|
|
303
|
+
return MarkdownToolsProcessor.format_table(input_text)
|
|
304
|
+
else:
|
|
305
|
+
return f"Unknown markdown tool: {tool_type}"
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
class MarkdownToolsWidget(ttk.Frame):
|
|
309
|
+
"""Tabbed interface widget for markdown tools."""
|
|
310
|
+
|
|
311
|
+
def __init__(self, parent, app):
|
|
312
|
+
super().__init__(parent)
|
|
313
|
+
self.app = app
|
|
314
|
+
self.processor = MarkdownToolsProcessor()
|
|
315
|
+
|
|
316
|
+
self.preserve_links_text = tk.BooleanVar(value=True)
|
|
317
|
+
self.include_images = tk.BooleanVar(value=False)
|
|
318
|
+
self.header_format = tk.StringVar(value="indented")
|
|
319
|
+
self.csv_delimiter = tk.StringVar(value=",")
|
|
320
|
+
|
|
321
|
+
self.create_widgets()
|
|
322
|
+
self.load_settings()
|
|
323
|
+
|
|
324
|
+
def create_widgets(self):
|
|
325
|
+
"""Creates the tabbed interface for markdown tools."""
|
|
326
|
+
self.notebook = ttk.Notebook(self)
|
|
327
|
+
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
328
|
+
|
|
329
|
+
self.create_strip_tab()
|
|
330
|
+
self.create_links_tab()
|
|
331
|
+
self.create_headers_tab()
|
|
332
|
+
self.create_table_csv_tab()
|
|
333
|
+
self.create_format_table_tab()
|
|
334
|
+
|
|
335
|
+
def create_strip_tab(self):
|
|
336
|
+
"""Creates the Strip Markdown tab."""
|
|
337
|
+
frame = ttk.Frame(self.notebook)
|
|
338
|
+
self.notebook.add(frame, text="Strip Markdown")
|
|
339
|
+
|
|
340
|
+
options_frame = ttk.LabelFrame(frame, text="Options", padding=10)
|
|
341
|
+
options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
342
|
+
|
|
343
|
+
ttk.Checkbutton(options_frame, text="Preserve Link Text",
|
|
344
|
+
variable=self.preserve_links_text,
|
|
345
|
+
command=self.on_setting_change).pack(anchor=tk.W)
|
|
346
|
+
|
|
347
|
+
info = ttk.Label(frame, text="Removes all markdown formatting (headers, bold, italic,\n"
|
|
348
|
+
"links, images, code blocks, lists, etc.)",
|
|
349
|
+
justify=tk.CENTER)
|
|
350
|
+
info.pack(pady=10)
|
|
351
|
+
|
|
352
|
+
ttk.Button(frame, text="Strip Markdown",
|
|
353
|
+
command=lambda: self.process("Strip Markdown")).pack(pady=10)
|
|
354
|
+
|
|
355
|
+
def create_links_tab(self):
|
|
356
|
+
"""Creates the Extract Links tab."""
|
|
357
|
+
frame = ttk.Frame(self.notebook)
|
|
358
|
+
self.notebook.add(frame, text="Extract Links")
|
|
359
|
+
|
|
360
|
+
options_frame = ttk.LabelFrame(frame, text="Options", padding=10)
|
|
361
|
+
options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
362
|
+
|
|
363
|
+
ttk.Checkbutton(options_frame, text="Include Image URLs",
|
|
364
|
+
variable=self.include_images,
|
|
365
|
+
command=self.on_setting_change).pack(anchor=tk.W)
|
|
366
|
+
|
|
367
|
+
info = ttk.Label(frame, text="Extracts all links from markdown text,\n"
|
|
368
|
+
"including inline links and reference-style links.",
|
|
369
|
+
justify=tk.CENTER)
|
|
370
|
+
info.pack(pady=10)
|
|
371
|
+
|
|
372
|
+
ttk.Button(frame, text="Extract Links",
|
|
373
|
+
command=lambda: self.process("Extract Links")).pack(pady=10)
|
|
374
|
+
|
|
375
|
+
def create_headers_tab(self):
|
|
376
|
+
"""Creates the Extract Headers tab."""
|
|
377
|
+
frame = ttk.Frame(self.notebook)
|
|
378
|
+
self.notebook.add(frame, text="Extract Headers")
|
|
379
|
+
|
|
380
|
+
format_frame = ttk.LabelFrame(frame, text="Output Format", padding=10)
|
|
381
|
+
format_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
382
|
+
|
|
383
|
+
ttk.Radiobutton(format_frame, text="Indented (hierarchy)",
|
|
384
|
+
variable=self.header_format, value="indented",
|
|
385
|
+
command=self.on_setting_change).pack(anchor=tk.W)
|
|
386
|
+
ttk.Radiobutton(format_frame, text="Flat (H1, H2, etc.)",
|
|
387
|
+
variable=self.header_format, value="flat",
|
|
388
|
+
command=self.on_setting_change).pack(anchor=tk.W)
|
|
389
|
+
ttk.Radiobutton(format_frame, text="Numbered",
|
|
390
|
+
variable=self.header_format, value="numbered",
|
|
391
|
+
command=self.on_setting_change).pack(anchor=tk.W)
|
|
392
|
+
|
|
393
|
+
ttk.Button(frame, text="Extract Headers",
|
|
394
|
+
command=lambda: self.process("Extract Headers")).pack(pady=10)
|
|
395
|
+
|
|
396
|
+
def create_table_csv_tab(self):
|
|
397
|
+
"""Creates the Table to CSV tab."""
|
|
398
|
+
frame = ttk.Frame(self.notebook)
|
|
399
|
+
self.notebook.add(frame, text="Table to CSV")
|
|
400
|
+
|
|
401
|
+
delimiter_frame = ttk.LabelFrame(frame, text="CSV Delimiter", padding=10)
|
|
402
|
+
delimiter_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
403
|
+
|
|
404
|
+
ttk.Label(delimiter_frame, text="Delimiter:").pack(side=tk.LEFT)
|
|
405
|
+
delimiter_combo = ttk.Combobox(delimiter_frame, textvariable=self.csv_delimiter,
|
|
406
|
+
values=[",", ";", "\t", "|"], width=5)
|
|
407
|
+
delimiter_combo.pack(side=tk.LEFT, padx=5)
|
|
408
|
+
delimiter_combo.bind("<<ComboboxSelected>>", lambda e: self.on_setting_change())
|
|
409
|
+
|
|
410
|
+
info = ttk.Label(frame, text="Converts markdown tables to CSV format.",
|
|
411
|
+
justify=tk.CENTER)
|
|
412
|
+
info.pack(pady=10)
|
|
413
|
+
|
|
414
|
+
ttk.Button(frame, text="Convert to CSV",
|
|
415
|
+
command=lambda: self.process("Table to CSV")).pack(pady=10)
|
|
416
|
+
|
|
417
|
+
def create_format_table_tab(self):
|
|
418
|
+
"""Creates the Format Table tab."""
|
|
419
|
+
frame = ttk.Frame(self.notebook)
|
|
420
|
+
self.notebook.add(frame, text="Format Table")
|
|
421
|
+
|
|
422
|
+
info = ttk.Label(frame, text="Auto-aligns markdown tables by padding cells\n"
|
|
423
|
+
"to create properly aligned columns.",
|
|
424
|
+
justify=tk.CENTER)
|
|
425
|
+
info.pack(pady=20)
|
|
426
|
+
|
|
427
|
+
ttk.Button(frame, text="Format Table",
|
|
428
|
+
command=lambda: self.process("Format Table")).pack(pady=10)
|
|
429
|
+
|
|
430
|
+
def load_settings(self):
|
|
431
|
+
"""Load settings from the application."""
|
|
432
|
+
settings = self.app.settings.get("tool_settings", {}).get("Markdown Tools", {})
|
|
433
|
+
|
|
434
|
+
self.preserve_links_text.set(settings.get("preserve_links_text", True))
|
|
435
|
+
self.include_images.set(settings.get("include_images", False))
|
|
436
|
+
self.header_format.set(settings.get("header_format", "indented"))
|
|
437
|
+
self.csv_delimiter.set(settings.get("csv_delimiter", ","))
|
|
438
|
+
|
|
439
|
+
def save_settings(self):
|
|
440
|
+
"""Save current settings to the application."""
|
|
441
|
+
if "Markdown Tools" not in self.app.settings["tool_settings"]:
|
|
442
|
+
self.app.settings["tool_settings"]["Markdown Tools"] = {}
|
|
443
|
+
|
|
444
|
+
self.app.settings["tool_settings"]["Markdown Tools"].update({
|
|
445
|
+
"preserve_links_text": self.preserve_links_text.get(),
|
|
446
|
+
"include_images": self.include_images.get(),
|
|
447
|
+
"header_format": self.header_format.get(),
|
|
448
|
+
"csv_delimiter": self.csv_delimiter.get()
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
self.app.save_settings()
|
|
452
|
+
|
|
453
|
+
def on_setting_change(self, *args):
|
|
454
|
+
"""Handle setting changes."""
|
|
455
|
+
self.save_settings()
|
|
456
|
+
|
|
457
|
+
def process(self, tool_type):
|
|
458
|
+
"""Process the input text with the selected tool."""
|
|
459
|
+
active_input_tab = self.app.input_tabs[self.app.input_notebook.index(self.app.input_notebook.select())]
|
|
460
|
+
input_text = active_input_tab.text.get("1.0", tk.END).rstrip('\n')
|
|
461
|
+
|
|
462
|
+
if not input_text.strip():
|
|
463
|
+
return
|
|
464
|
+
|
|
465
|
+
settings = {
|
|
466
|
+
"preserve_links_text": self.preserve_links_text.get(),
|
|
467
|
+
"include_images": self.include_images.get(),
|
|
468
|
+
"header_format": self.header_format.get(),
|
|
469
|
+
"csv_delimiter": self.csv_delimiter.get()
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
result = MarkdownToolsProcessor.process_text(input_text, tool_type, settings)
|
|
473
|
+
|
|
474
|
+
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
475
|
+
active_output_tab.text.config(state="normal")
|
|
476
|
+
active_output_tab.text.delete("1.0", tk.END)
|
|
477
|
+
active_output_tab.text.insert("1.0", result)
|
|
478
|
+
active_output_tab.text.config(state="disabled")
|
|
479
|
+
|
|
480
|
+
self.app.update_all_stats()
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
class MarkdownTools:
|
|
484
|
+
"""Main class for Markdown Tools integration."""
|
|
485
|
+
|
|
486
|
+
def __init__(self):
|
|
487
|
+
self.processor = MarkdownToolsProcessor()
|
|
488
|
+
|
|
489
|
+
def create_widget(self, parent, app):
|
|
490
|
+
"""Create and return the Markdown Tools widget."""
|
|
491
|
+
return MarkdownToolsWidget(parent, app)
|
|
492
|
+
|
|
493
|
+
def get_default_settings(self):
|
|
494
|
+
"""Return default settings for Markdown Tools."""
|
|
495
|
+
return {
|
|
496
|
+
"preserve_links_text": True,
|
|
497
|
+
"include_images": False,
|
|
498
|
+
"header_format": "indented",
|
|
499
|
+
"csv_delimiter": ","
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
def process_text(self, input_text, tool_type, settings):
|
|
503
|
+
"""Process text using the specified tool and settings."""
|
|
504
|
+
return MarkdownToolsProcessor.process_text(input_text, tool_type, settings)
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
# BaseTool-compatible wrapper
|
|
508
|
+
try:
|
|
509
|
+
from tools.base_tool import ToolWithOptions
|
|
510
|
+
from typing import Dict, Any
|
|
511
|
+
|
|
512
|
+
class MarkdownToolsV2(ToolWithOptions):
|
|
513
|
+
"""
|
|
514
|
+
BaseTool-compatible version of MarkdownTools.
|
|
515
|
+
"""
|
|
516
|
+
|
|
517
|
+
TOOL_NAME = "Markdown Tools"
|
|
518
|
+
TOOL_DESCRIPTION = "Process and manipulate markdown text"
|
|
519
|
+
TOOL_VERSION = "2.0.0"
|
|
520
|
+
|
|
521
|
+
OPTIONS = [
|
|
522
|
+
("Strip Markdown", "strip"),
|
|
523
|
+
("Extract Links", "extract_links"),
|
|
524
|
+
("Extract Headers", "extract_headers"),
|
|
525
|
+
("Table to CSV", "table_to_csv"),
|
|
526
|
+
("Format Table", "format_table"),
|
|
527
|
+
]
|
|
528
|
+
OPTIONS_LABEL = "Operation"
|
|
529
|
+
USE_DROPDOWN = True
|
|
530
|
+
DEFAULT_OPTION = "strip"
|
|
531
|
+
|
|
532
|
+
def process_text(self, input_text: str, settings: Dict[str, Any]) -> str:
|
|
533
|
+
"""Process markdown text."""
|
|
534
|
+
mode = settings.get("mode", "strip")
|
|
535
|
+
|
|
536
|
+
if mode == "strip":
|
|
537
|
+
return MarkdownToolsProcessor.strip_markdown(
|
|
538
|
+
input_text,
|
|
539
|
+
settings.get("preserve_links_text", True)
|
|
540
|
+
)
|
|
541
|
+
elif mode == "extract_links":
|
|
542
|
+
return MarkdownToolsProcessor.extract_links(
|
|
543
|
+
input_text,
|
|
544
|
+
settings.get("include_images", False)
|
|
545
|
+
)
|
|
546
|
+
elif mode == "extract_headers":
|
|
547
|
+
return MarkdownToolsProcessor.extract_headers(
|
|
548
|
+
input_text,
|
|
549
|
+
settings.get("header_format", "indented")
|
|
550
|
+
)
|
|
551
|
+
elif mode == "table_to_csv":
|
|
552
|
+
return MarkdownToolsProcessor.table_to_csv(
|
|
553
|
+
input_text,
|
|
554
|
+
settings.get("csv_delimiter", ",")
|
|
555
|
+
)
|
|
556
|
+
elif mode == "format_table":
|
|
557
|
+
return MarkdownToolsProcessor.format_table(input_text)
|
|
558
|
+
else:
|
|
559
|
+
return input_text
|
|
560
|
+
|
|
561
|
+
except ImportError:
|
|
562
562
|
pass
|