python-color-math 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl

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.
color_math/__init__.py CHANGED
@@ -5,7 +5,7 @@ from .config import ColorMathOptions
5
5
  from .converters.block import convert_text
6
6
  from .undo import uncolor_text
7
7
 
8
- __version__ = "0.2.1"
8
+ __version__ = "0.2.2"
9
9
 
10
10
  __all__ = [
11
11
  "__version__",
color_math/main.py CHANGED
@@ -32,7 +32,7 @@ from .parsers.math_parser import describe_math_blocks
32
32
  from .self_test import run_self_test
33
33
  from .tutorial import run_tutorial
34
34
 
35
- VERSION = "0.2.1"
35
+ VERSION = "0.2.2"
36
36
  SUPPORTED_EXTENSIONS = {".md", ".markdown", ".qmd", ".ipynb", ".tex", ".latex"}
37
37
  DEFAULT_EXCLUDES = {
38
38
  ".git",
color_math/mcp_server.py CHANGED
@@ -149,22 +149,30 @@ def create_mcp_server() -> MCPServer:
149
149
  normalize_braces=normalize_braces,
150
150
  )
151
151
 
152
- clean_expr = expression.strip()
153
- had_delimiters = clean_expr.startswith("$$") and clean_expr.endswith("$$")
154
- block_text = clean_expr if had_delimiters else f"$${clean_expr}$$"
152
+ try:
153
+ clean_expr = expression.strip()
154
+ had_delimiters = clean_expr.startswith("$$") and clean_expr.endswith("$$")
155
+ block_text = clean_expr if had_delimiters else f"$${clean_expr}$$"
155
156
 
156
- colored = convert_math_block(block_text, pal, opts)
157
- if not had_delimiters and colored.startswith("$$") and colored.endswith("$$"):
158
- colored_output = colored[2:-2]
159
- else:
160
- colored_output = colored
157
+ colored = convert_math_block(block_text, pal, opts)
158
+ if not had_delimiters and colored.startswith("$$") and colored.endswith("$$"):
159
+ colored_output = colored[2:-2]
160
+ else:
161
+ colored_output = colored
161
162
 
162
- return {
163
- "original": expression,
164
- "colorized": colored_output,
165
- "changed": colored_output != expression,
166
- "theme": theme,
167
- }
163
+ return {
164
+ "original": expression,
165
+ "colorized": colored_output,
166
+ "changed": colored_output != expression,
167
+ "theme": theme,
168
+ }
169
+ except Exception as err:
170
+ return {
171
+ "original": expression,
172
+ "error": str(err),
173
+ "changed": False,
174
+ "theme": theme,
175
+ }
168
176
 
169
177
  @server.tool(
170
178
  name="colorize_text",
@@ -199,16 +207,25 @@ def create_mcp_server() -> MCPServer:
199
207
  normalize_braces=normalize_braces,
200
208
  )
201
209
 
202
- fmt = format_name if format_name in FORMATS else "markdown"
203
- result = transform_document(text, fmt, undo=False, palette=pal, options=opts)
204
- return {
205
- "format": fmt,
206
- "theme": theme,
207
- "original_length": len(text),
208
- "colorized_length": len(result),
209
- "changed": result != text,
210
- "result": result,
211
- }
210
+ try:
211
+ fmt = format_name if format_name in FORMATS else "markdown"
212
+ result = transform_document(text, fmt, undo=False, palette=pal, options=opts)
213
+ return {
214
+ "format": fmt,
215
+ "theme": theme,
216
+ "original_length": len(text),
217
+ "colorized_length": len(result),
218
+ "changed": result != text,
219
+ "result": result,
220
+ }
221
+ except Exception as err:
222
+ return {
223
+ "format": format_name,
224
+ "theme": theme,
225
+ "error": str(err),
226
+ "changed": False,
227
+ "result": text,
228
+ }
212
229
 
213
230
  @server.tool(
214
231
  name="uncolor_text",
@@ -221,15 +238,23 @@ def create_mcp_server() -> MCPServer:
221
238
  text: str,
222
239
  format_name: str = "markdown",
223
240
  ) -> dict[str, Any]:
224
- fmt = format_name if format_name in FORMATS else "markdown"
225
- result = transform_document(text, fmt, undo=True)
226
- return {
227
- "format": fmt,
228
- "original_length": len(text),
229
- "cleaned_length": len(result),
230
- "changed": result != text,
231
- "result": result,
232
- }
241
+ try:
242
+ fmt = format_name if format_name in FORMATS else "markdown"
243
+ result = transform_document(text, fmt, undo=True)
244
+ return {
245
+ "format": fmt,
246
+ "original_length": len(text),
247
+ "cleaned_length": len(result),
248
+ "changed": result != text,
249
+ "result": result,
250
+ }
251
+ except Exception as err:
252
+ return {
253
+ "format": format_name,
254
+ "error": str(err),
255
+ "changed": False,
256
+ "result": text,
257
+ }
233
258
 
234
259
  @server.tool(
235
260
  name="process_file",
@@ -271,47 +296,56 @@ def create_mcp_server() -> MCPServer:
271
296
  normalize_braces=normalize_braces,
272
297
  )
273
298
 
274
- fmt = detect_format(path)
275
- original_text, raw_bytes = read_utf8(path)
276
- transformed = transform_document(
277
- original_text, fmt, undo=undo, palette=pal, options=opts
278
- )
299
+ try:
300
+ fmt = detect_format(path)
301
+ original_text, raw_bytes = read_utf8(path)
302
+ transformed = transform_document(
303
+ original_text, fmt, undo=undo, palette=pal, options=opts
304
+ )
279
305
 
280
- changed = transformed != original_text
281
- diff_output = ""
282
- if changed:
283
- diff_lines = list(
284
- difflib.unified_diff(
285
- original_text.splitlines(keepends=True),
286
- transformed.splitlines(keepends=True),
287
- fromfile=str(path),
288
- tofile=str(path),
306
+ changed = transformed != original_text
307
+ diff_output = ""
308
+ if changed:
309
+ diff_lines = list(
310
+ difflib.unified_diff(
311
+ original_text.splitlines(keepends=True),
312
+ transformed.splitlines(keepends=True),
313
+ fromfile=str(path),
314
+ tofile=str(path),
315
+ )
289
316
  )
290
- )
291
- diff_output = "".join(diff_lines[:100]) # limit diff length
317
+ diff_output = "".join(diff_lines[:100]) # limit diff length
292
318
 
293
- written = False
294
- if changed and in_place:
295
- new_bytes = encode_utf8(transformed, raw_bytes)
296
- written = replace_bytes(path, new_bytes, raw_bytes)
319
+ written = False
320
+ if changed and in_place:
321
+ new_bytes = encode_utf8(transformed, raw_bytes)
322
+ written = replace_bytes(path, new_bytes, raw_bytes)
297
323
 
298
- return {
299
- "file_path": str(path),
300
- "format": fmt,
301
- "action": "undo" if undo else "colorize",
302
- "changed": changed,
303
- "written_to_disk": written,
304
- "diff": diff_output if changed else None,
305
- "message": (
306
- f"File successfully updated on disk: {path.name}"
307
- if written
308
- else (
309
- f"Dry run complete: changes detected in {path.name}"
310
- if changed
311
- else f"No changes needed: {path.name} is already up to date."
312
- )
313
- ),
314
- }
324
+ return {
325
+ "file_path": str(path),
326
+ "format": fmt,
327
+ "action": "undo" if undo else "colorize",
328
+ "changed": changed,
329
+ "written_to_disk": written,
330
+ "diff": diff_output if changed else None,
331
+ "message": (
332
+ f"File successfully updated on disk: {path.name}"
333
+ if written
334
+ else (
335
+ f"Dry run complete: changes detected in {path.name}"
336
+ if changed
337
+ else f"No changes needed: {path.name} is already up to date."
338
+ )
339
+ ),
340
+ }
341
+ except Exception as err:
342
+ return {
343
+ "file_path": str(path),
344
+ "error": str(err),
345
+ "changed": False,
346
+ "written_to_disk": False,
347
+ "message": f"Error processing {path.name}: {err}",
348
+ }
315
349
 
316
350
  @server.tool(
317
351
  name="scan_vault",
@@ -423,3 +457,8 @@ def run_mcp_server(transport: str = "stdio", **kwargs: Any) -> None:
423
457
  server.run(transport="streamable-http", **kwargs)
424
458
  else:
425
459
  raise ValueError(f"Unsupported transport: {transport}. Expected 'stdio', 'sse', or 'streamable-http'.")
460
+
461
+
462
+ if __name__ == "__main__":
463
+ run_mcp_server()
464
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-color-math
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: A fast, local semantic LaTeX colorizer for Markdown, Jupyter, and LaTeX math equations.
5
5
  Author: Aditya
6
6
  License: MIT License
@@ -232,7 +232,7 @@ Integrate `color-math` into your git workflow using [pre-commit](https://pre-com
232
232
  ```yaml
233
233
  repos:
234
234
  - repo: https://github.com/36ty-blip/color-math
235
- rev: v0.2.1
235
+ rev: v0.2.2
236
236
  hooks:
237
237
  # Formatter: colorizes modified Markdown, LaTeX, and Jupyter files in-place
238
238
  - id: color-math
@@ -1,13 +1,13 @@
1
- color_math/__init__.py,sha256=RNYZanthRaPTjF3cj4qst2qdXLlPGpM7ImicgWd4a7U,401
1
+ color_math/__init__.py,sha256=Euh1rIsFDxQn3InlS_a08llorK5KF5PzWcazwXq_0HU,401
2
2
  color_math/__main__.py,sha256=lU6t3BklI-5H9EdprlceWLr0UcDmfXUu3Th0tjk2ANA,81
3
3
  color_math/adapters.py,sha256=wh9oD0ZB1B6iPmLAiW09WgCA0zNnF7SV5diNT5qEynA,11247
4
4
  color_math/completions.py,sha256=Q63B8GNn71vdNohbcNs5WmXY8qFGy2T7qT9W-v8XUuQ,11010
5
5
  color_math/config.py,sha256=1EnU2kC8GnWERugtg57EAwTits-PFXsHMrKk3UJq_Rk,15081
6
6
  color_math/gui.py,sha256=cBsgNToQdZ7mNQ9JA5_jEv7QbELc4NGtgXowTxZ-IWQ,21413
7
7
  color_math/io.py,sha256=iCWMY1ufPZzFCwuHTn_axNetek8PRXGNnrmz59CrlGw,1591
8
- color_math/main.py,sha256=H5g4ZHMr1CtDvGOiSDpE-U9MYh9MrxLzhmYgOgzf5Fc,30062
8
+ color_math/main.py,sha256=p1IFAzkfdRPAu8sRgU2J2nCsLzx97NnQcaIc6xRZxaE,30062
9
9
  color_math/mcp.py,sha256=M-JTnWC-xhJemIv2F0ZI4VBF5_MUmasid5B4PIIPgSo,1112
10
- color_math/mcp_server.py,sha256=1cAAi4yB5r1gpIwTqKBNWhKKhJoeEt4u_BsZVY45FU0,14756
10
+ color_math/mcp_server.py,sha256=AyDjwKVS-7nnaFu4hBNeBrFC542bs7_WuWosgMflvDg,16086
11
11
  color_math/py.typed,sha256=bWew9mHgMy8LqMu7RuqQXFXLBxh2CRx0dUbSx-3wE48,27
12
12
  color_math/self_test.py,sha256=O-BLG2c_3jXPl9NfuMIKChUxGFih8DtVchdBMI3X2-o,7735
13
13
  color_math/tutorial.py,sha256=RuY_ltf6VNa7CTyE1qM8FCyBB1phvJE9YdYD_WEY8xo,9589
@@ -42,9 +42,9 @@ color_math/utils/latex_helpers.py,sha256=1cFj0zqv68mD-p0vej6yPrhwgqLfAWcIV1rX15F
42
42
  color_math/utils/spans.py,sha256=3Lq1_bN0s4vSYnS8Rz9tCHoFoJDY6Ff9CzawWWws3YE,3938
43
43
  python_color_math/__init__.py,sha256=Dj5YZXXjmNgbyhHKX2YQXvVggtB9UZy9zotLiV2j5So,329
44
44
  python_color_math/__main__.py,sha256=cqUM_fV0E6mtuHeBn2MjuozR2rlpev9AfXfcm2hSpi8,90
45
- python_color_math-0.2.1.dist-info/licenses/LICENSE,sha256=hveQNxqYFqK9Brs_ruH-8shF2D61hIVKYdCjiE-1wMY,1063
46
- python_color_math-0.2.1.dist-info/METADATA,sha256=j1MQy53g7d47y8_a2xFtxbKFpUzyKK93IRRTNbooQ3s,10900
47
- python_color_math-0.2.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
48
- python_color_math-0.2.1.dist-info/entry_points.txt,sha256=ZgzGbO_D3csr693Fd-tVGhls6WzsZiOhCau-liSkE_M,130
49
- python_color_math-0.2.1.dist-info/top_level.txt,sha256=dkfmCdtILDAgX4wwDW5DKHh9YRLt9Mh2RU0gh1mBDDA,29
50
- python_color_math-0.2.1.dist-info/RECORD,,
45
+ python_color_math-0.2.2.dist-info/licenses/LICENSE,sha256=hveQNxqYFqK9Brs_ruH-8shF2D61hIVKYdCjiE-1wMY,1063
46
+ python_color_math-0.2.2.dist-info/METADATA,sha256=pqqDwEh0BkD4zsCaDdYFhhXIzcUHNLaUiQMttOGD6LQ,10900
47
+ python_color_math-0.2.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
48
+ python_color_math-0.2.2.dist-info/entry_points.txt,sha256=ZgzGbO_D3csr693Fd-tVGhls6WzsZiOhCau-liSkE_M,130
49
+ python_color_math-0.2.2.dist-info/top_level.txt,sha256=dkfmCdtILDAgX4wwDW5DKHh9YRLt9Mh2RU0gh1mBDDA,29
50
+ python_color_math-0.2.2.dist-info/RECORD,,