diff --git a/CHANGELOG.md b/CHANGELOG.md index 088cb4c..a0b6e6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.7.0] - 2025-12-15 + +### Removed + +- Removed SVG `` rendering for code blocks to improve portability across SVG renderers. +- Removed `foreignObject` from the `code_block_overflow` options (use `wrap`, `show`, `hide`, or `ellipsis`). + ## [0.6.3] - 2025-12-10 ### Added diff --git a/core b/core new file mode 100644 index 0000000..b256684 Binary files /dev/null and b/core differ diff --git a/examples/code.md b/examples/code.md index d032830..b698054 100644 --- a/examples/code.md +++ b/examples/code.md @@ -38,7 +38,6 @@ Long lines demonstrate overflow handling. The `code_block_overflow` style contro | `show` | Let content overflow visible | | `hide` | Clip hidden content | | `ellipsis` | Truncate with `...` | -| `foreignObject` | Scrollable HTML embed | Here's a long line: diff --git a/notes/INITIAL_PLAN.md b/notes/INITIAL_PLAN.md index 138a2d4..3d377d7 100644 --- a/notes/INITIAL_PLAN.md +++ b/notes/INITIAL_PLAN.md @@ -308,7 +308,7 @@ highlight = ["pygments"] # For syntax highlighting - **Font metrics mode**: Use actual font files for precise measurement - **Syntax highlighting**: Pygments integration for code blocks - **Themes**: Built-in dark/light themes -- **HTML fallback**: Option to embed `` for complex content +- **HTML fallback**: Avoid ``; prefer pure SVG primitives for portability ## Timeline diff --git a/pyproject.toml b/pyproject.toml index b027290..441c7fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "markdown-svg" -version = "0.6.3" +version = "0.7.0" description = "Convert Markdown to SVG with automatic text wrapping" readme = "README.md" license = { text = "MIT" } diff --git a/src/mdsvg/__init__.py b/src/mdsvg/__init__.py index 37c9670..fef6ff3 100644 --- a/src/mdsvg/__init__.py +++ b/src/mdsvg/__init__.py @@ -6,7 +6,7 @@ Basic usage: >>> from mdsvg import render - >>> svg = render("# Hello World\\n\\nThis is **bold** text.") + >>> svg = render("# Hello World\n\nThis is **bold** text.") With custom styling: >>> from mdsvg import render, Style @@ -14,7 +14,7 @@ Measure dimensions without rendering: >>> from mdsvg import measure - >>> size = measure("# Hello\\n\\nLong paragraph...") + >>> size = measure("# Hello\n\nLong paragraph...") >>> print(f"Height: {size.height}px") """ @@ -70,7 +70,7 @@ UnorderedList, ) -__version__ = "0.6.3" +__version__ = "0.7.0" __all__ = [ # Main API diff --git a/src/mdsvg/renderer.py b/src/mdsvg/renderer.py index 9e33e03..857c1cc 100644 --- a/src/mdsvg/renderer.py +++ b/src/mdsvg/renderer.py @@ -370,12 +370,13 @@ def _render_code_block( """Render a code block with background.""" overflow = self.style.code_block_overflow - if overflow == "foreignObject": - return self._render_code_block_foreign_object(code, ctx) - elif overflow == "wrap": + if overflow == "wrap": return self._render_code_block_wrapped(code, ctx) - else: + elif overflow in {"show", "hide", "ellipsis"}: return self._render_code_block_simple(code, ctx, overflow) + else: + # Defensive fallback (should be unreachable due to typing) + return self._render_code_block_wrapped(code, ctx) def _render_code_block_simple( self, @@ -495,44 +496,6 @@ def _render_code_block_wrapped( return elements, total_height - def _render_code_block_foreign_object( - self, - code: CodeBlock, - ctx: RenderContext, - ) -> Tuple[List[str], float]: - """Render code block using foreignObject for scrollable HTML.""" - elements: List[str] = [] - - padding = self.style.code_block_padding - font_size = self.style.base_font_size * 0.9 - line_height = font_size * 1.4 - - lines = code.code.split("\n") - # Cap height for scrollable content - max_visible_lines = 20 - visible_lines = min(len(lines), max_visible_lines) - text_height = visible_lines * line_height - total_height = text_height + (padding * 2) - - escaped_code = escape_svg_text(code.code) - - elements.append( - f' ' - f'
' - f'
{escaped_code}
' - f"
" - ) - - return elements, total_height - def _render_blockquote( self, bq: Blockquote, diff --git a/src/mdsvg/style.py b/src/mdsvg/style.py index 443b699..403dd71 100644 --- a/src/mdsvg/style.py +++ b/src/mdsvg/style.py @@ -6,7 +6,7 @@ from typing import Any, Literal, Optional # Code block overflow options -CodeBlockOverflow = Literal["wrap", "show", "hide", "ellipsis", "foreignObject"] +CodeBlockOverflow = Literal["wrap", "show", "hide", "ellipsis"] @dataclass(frozen=True) @@ -93,7 +93,7 @@ class Style: list_item_spacing: float = 4.0 code_block_padding: float = 12.0 code_block_border_radius: float = 4.0 - code_block_overflow: CodeBlockOverflow = "wrap" # wrap, show, hide, ellipsis, foreignObject + code_block_overflow: CodeBlockOverflow = "wrap" # wrap, show, hide, ellipsis blockquote_padding: float = 16.0 blockquote_border_width: float = 3.0 diff --git a/tests/test_integration.py b/tests/test_integration.py index 4cb5c8b..f2dad77 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -154,7 +154,7 @@ def test_version(self) -> None: """Test version is available.""" from mdsvg import __version__ - assert __version__ == "0.5.0" + assert __version__ == "0.7.0" class TestRealWorldExamples: