Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

feat(svg-to-pptx): add native superscript and subscript runs

hugohe35a46c0cfa09d
diff --git a/skills/ppt-master/references/shared-standards-core.md b/skills/ppt-master/references/shared-standards-core.md
index 25b402dc..b25ffc92 100644
--- a/skills/ppt-master/references/shared-standards-core.md
+++ b/skills/ppt-master/references/shared-standards-core.md
@@ -125,8 +125,10 @@ remain valid input and receive recommendation warnings rather than errors.
Conditional properties with a required XML form stay out of inline style:
write `filter="url(#id)"`, `clip-path="url(#id)"`, and
-`marker-start` / `marker-end` as direct attributes. `!important`, unknown CSS
-properties, blend modes, isolation, and backdrop filters fail quality check.
+`marker-start` / `marker-end` as direct attributes. Ordinary-text superscript
+and subscript likewise use only direct `baseline-shift="super|sub"` on
+`<tspan>`. `!important`, unknown CSS properties, blend modes, isolation, and
+backdrop filters fail quality check.
The table registers property names, not arbitrary CSS values. Ordinary generated
text uses a non-empty `font-family`, a finite positive unitless-px `font-size`,
diff --git a/skills/ppt-master/references/svg-effects.md b/skills/ppt-master/references/svg-effects.md
index 900968e0..f9978ae3 100644
--- a/skills/ppt-master/references/svg-effects.md
+++ b/skills/ppt-master/references/svg-effects.md
@@ -489,14 +489,18 @@ other value is invalid; the converter must not replace it with a default.
| `font-style` | `normal` or `italic` | None | `italic` maps to `i="1"`; oblique, angle, relative, and CSS-wide values are invalid |
| `text-anchor` | `start`, `middle`, or `end` on `<svg>`, `<g>`, or `<text>` | None | Maps to left/center/right paragraph alignment plus normalized frame position; it is invalid on `<tspan>` because run-level anchoring has no mapping |
| `text-decoration` | `none`, `underline`, `line-through`, or `underline line-through` | `line-through underline` → canonical order | Maps to the single underline and strike run properties; unknown, repeated, or substring-like tokens are invalid |
+| `baseline-shift` | Exact direct `super` or `sub` on `<tspan>` | None | Maps to editable ordinary-text `a:rPr@baseline` at `30000` or `-25000`; it does not resize the run, is invalid as inline style or on any other element, and cannot combine with an inline formula marker |
| `letter-spacing` | Finite unitless ordinary decimal SVG px | The same ordinary decimal with `px`, `pt`, or `em`; normalize to unitless px | Maps to `a:rPr@spc`; the final value must fit DrawingML `-400000..400000`, and negative tracking must leave every generated DrawingML run with a positive estimated advance and its text frame with a positive extent; keywords, percentages, exponents, leading plus signs, trailing decimal points, non-finite values, and other units are invalid |
-The registered text properties follow SVG inheritance, including declarations
-on the root `<svg>`: inline `style` overrides the same element's direct
-attribute, which overrides its ancestor. Relative font sizes and `em` tracking
-resolve against the same effective inherited size in Checker and converter.
-Every declaration is validated even when a later declaration overrides it, so
-hidden garbage cannot bypass preflight.
+The registered inheritable text properties follow SVG inheritance, including
+declarations on the root `<svg>`: inline `style` overrides the same element's
+direct attribute, which overrides its ancestor. `baseline-shift` is the narrow
+exception: declare it directly on the owning `<tspan>`; nested inline content
+inherits that run shift, while surrounding text keeps its own baseline.
+Relative font sizes and `em` tracking resolve against the same effective
+inherited size in Checker and converter. Every declaration is validated even
+when a later declaration overrides it, so hidden garbage cannot bypass
+preflight.
The DrawingML character-spacing range is necessary but not sufficient for
negative tracking. After run assembly, each output run must retain a positive
@@ -529,9 +533,10 @@ runs or a text frame from the SVG estimate.
`transform`, `xml:space`, `id`, and project `data-*` metadata.
- `<tspan>` accepts `x`, `y`, `dx`, `dy`, registered paint/alpha/run
properties, `font-family`, `font-size`, `font-weight`, `font-style`,
- `letter-spacing`, `text-decoration`, `xml:space`, `id`, and project `data-*`
- metadata. It does not accept `text-anchor`, `filter`, or `transform`.
-- `word-spacing`, `dominant-baseline`, `alignment-baseline`, `baseline-shift`,
+ `letter-spacing`, `text-decoration`, direct `baseline-shift`, `xml:space`,
+ `id`, and project `data-*` metadata. It does not accept `text-anchor`,
+ `filter`, or `transform`.
+- `word-spacing`, `dominant-baseline`, `alignment-baseline`,
font shorthand/variant/stretch/feature/variation/synthesis controls,
`font-kerning`/`kerning`, `font-size-adjust`, `line-height`, text alignment,
indent/shadow/rendering controls, white-space/word-break/hyphenation
@@ -569,6 +574,7 @@ respective sections; they do not weaken those contracts.
|---|---|---|
| Underline / strike / both | `text-decoration="underline"`, `line-through`, or both | `Native-stable`; both emits both run properties |
| Mixed runs | Non-positional `<tspan>` | One `Native-normalized` editable frame; §4.2 |
+| Superscript / subscript | Direct `baseline-shift="super|sub"` on `<tspan>` | Editable ordinary-text run at PowerPoint's native baseline offset; set `font-size` on the same run when a smaller glyph is intended |
| Font size | Generated default is a finite unitless SVG px value; compatible `px`, `pt`, `pc`/`pica`, `in`, `cm`, `mm`, `q`, `em`, and `rem` values receive a recommendation warning only | Converted to SVG px, then editable DrawingML point size; unsupported units/percentages error |
| Tracking | §6.7 closed `letter-spacing` grammar | `Native-normalized`; compatible units normalize to SVG px before DrawingML conversion |
| Transparency | `opacity` / `fill-opacity` on text/run | `Native-normalized` run alpha, not isolated compositing |
@@ -580,6 +586,8 @@ respective sections; they do not weaken those contracts.
```xml
<text x="100" y="200" font-size="20" xml:space="preserve">Current <tspan
fill="#999999" text-decoration="line-through">old</tspan> value</text>
+<text x="100" y="240" font-size="20">CO<tspan
+ baseline-shift="sub" font-size="14">2</tspan></text>
```
Use strikethrough for removed/former values; it is ordinary notation, not a
diff --git a/skills/ppt-master/scripts/svg_finalize/flatten_tspan.py b/skills/ppt-master/scripts/svg_finalize/flatten_tspan.py
index 775e2af4..2c8f052c 100644
--- a/skills/ppt-master/scripts/svg_finalize/flatten_tspan.py
+++ b/skills/ppt-master/scripts/svg_finalize/flatten_tspan.py
@@ -687,6 +687,14 @@ def _has_tspan_children(elem: ET.Element) -> bool:
)
+def _declares_baseline_shift(elem: ET.Element) -> bool:
+ """Keep tspan ownership for the project-only baseline-shift contract."""
+ return (
+ elem.get("baseline-shift") is not None
+ or "baseline-shift" in parse_style(elem.get("style"))
+ )
+
+
def _copy_inline_element(src: ET.Element, strip_line_attrs: bool) -> ET.Element:
"""Deep-copy one supported inline ``tspan`` or hyperlink subtree."""
local = src.tag.rsplit("}", 1)[-1]
@@ -761,6 +769,7 @@ def _create_text_element_from_line(
and not _has_tspan_children(tspans[0])
and not tspans[0].tail
and tspans[0].get(INLINE_FORMULA_ATTR) is None
+ and not _declares_baseline_shift(tspans[0])
):
tspan = tspans[0]
content = collect_text_content(tspan)
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
index 7266c07f..13ac4a1a 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
@@ -48,6 +48,7 @@ from .theme_fonts import theme_font_tokens
from .text_properties import (
drawingml_letter_spacing,
normalize_project_text_segments,
+ parse_project_baseline_shift,
parse_project_font_style,
parse_project_font_weight,
parse_project_letter_spacing,
@@ -2349,6 +2350,11 @@ def _override_run_attrs(
run_attrs['font_weight'] = parse_project_font_weight(
tspan_attr('font-weight')
).canonical
+ raw_baseline_shift = tspan.get('baseline-shift')
+ if raw_baseline_shift is not None:
+ run_attrs['baseline_shift'] = int(
+ parse_project_baseline_shift(raw_baseline_shift).value
+ )
if tspan_attr('fill'):
child_fill = tspan_attr('fill')
run_attrs['fill_raw'] = child_fill
@@ -2473,9 +2479,9 @@ def _build_text_runs(
) -> list[dict[str, Any]]:
"""Build a list of text runs from a <text> element, handling <tspan> children.
- Each run is a dict with keys: text, fill, fill_raw, font_weight,
- font_style, font_family, font_size, letter_spacing. Nested tspans are walked
- recursively so inline format changes inside a tspan still produce distinct runs.
+ Each run carries text plus resolved paint, typography, tracking, and baseline
+ shift. Nested tspans are walked recursively so inline format changes still
+ produce distinct runs.
"""
runs: list[dict[str, Any]] = []
xml_space = resolve_project_xml_space(elem)
@@ -2604,6 +2610,7 @@ def _build_run_properties_xml(
fstyle = run.get('font_style', '')
ff = run.get('font_family', '')
letter_spacing_px = float(run.get('letter_spacing', 0.0) or 0.0)
+ baseline_shift = int(run.get('baseline_shift', 0) or 0)
opacity = run.get('opacity')
text_dec = run.get('text_decoration', '')
@@ -2621,6 +2628,7 @@ def _build_run_properties_xml(
u_attr = ' u="sng"' if underline else ''
strike_attr = ' strike="sngStrike"' if strike else ''
spc_attr = _letter_spacing_to_drawingml_spc(letter_spacing_px)
+ baseline_attr = f' baseline="{baseline_shift}"' if baseline_shift else ''
fonts = parse_font_family(ff) if ff else default_fonts
run_fonts = (
@@ -2659,7 +2667,7 @@ def _build_run_properties_xml(
else ''
)
- return f'''<a:rPr lang="{lang}" sz="{sz}"{b_attr}{i_attr}{u_attr}{strike_attr}{spc_attr} dirty="0">
+ return f'''<a:rPr lang="{lang}" sz="{sz}"{b_attr}{i_attr}{u_attr}{strike_attr}{spc_attr}{baseline_attr} dirty="0">
{outline_xml}
{fill_xml}
{effect_xml}
@@ -2853,6 +2861,7 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
'font_style': font_style,
'text_decoration': text_decoration,
'letter_spacing': letter_spacing_px,
+ 'baseline_shift': 0,
'_scale_x': ctx.scale_x or 1.0,
'_object_opacity': object_opacity,
'_fill_opacity': fill_opacity,
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/text_properties.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/text_properties.py
index 317be3e3..a15115c4 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/text_properties.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/text_properties.py
@@ -25,6 +25,7 @@ _SVG_TEXT_PROPERTIES = frozenset({
})
_TEXT_DECLARATION_PROPERTIES = _SVG_TEXT_PROPERTIES | {
+ 'baseline-shift',
'font-family',
'font-size',
}
@@ -33,7 +34,6 @@ _TEXT_INHERITANCE_TARGETS = frozenset({'svg', 'g', 'text', 'tspan'})
_UNSUPPORTED_TEXT_PROPERTIES = frozenset({
'alignment-baseline',
- 'baseline-shift',
'direction',
'dominant-baseline',
'font-kerning',
@@ -86,6 +86,7 @@ _TEXT_DIRECT_ATTRIBUTES = frozenset({
})
_TSPAN_DIRECT_ATTRIBUTES = frozenset({
+ 'baseline-shift',
'dx',
'dy',
'fill',
@@ -315,6 +316,17 @@ def parse_project_text_decoration(raw: str) -> ParsedTextProperty:
)
+def parse_project_baseline_shift(raw: str) -> ParsedTextProperty:
+ """Map the closed superscript/subscript grammar to DrawingML baseline."""
+ values = {
+ 'super': 30_000,
+ 'sub': -25_000,
+ }
+ if raw not in values:
+ raise ValueError("expected exactly 'super' or 'sub'")
+ return ParsedTextProperty(values[raw], raw)
+
+
def parse_project_letter_spacing(
raw: str,
*,
@@ -385,6 +397,7 @@ def parse_project_text_property(
) -> ParsedTextProperty:
"""Parse one declaration from the shared text-property value contract."""
parsers = {
+ 'baseline-shift': parse_project_baseline_shift,
'font-weight': parse_project_font_weight,
'font-style': parse_project_font_style,
'text-anchor': parse_project_text_anchor,
@@ -623,6 +636,26 @@ def _diagnose_text_declaration(
"'default' or 'preserve'",
)
return True, None
+ if name == 'baseline-shift':
+ if source != 'attribute':
+ return True, TextPropertyDiagnostic(
+ 'error', label, source, name, raw,
+ f'{label} must declare baseline-shift as a direct attribute; '
+ 'inline style is not supported',
+ )
+ if tag != 'tspan':
+ return True, TextPropertyDiagnostic(
+ 'error', label, source, name, raw,
+ f'{label} can use baseline-shift only on <tspan>',
+ )
+ try:
+ parse_project_baseline_shift(raw)
+ except ValueError as exc:
+ return True, TextPropertyDiagnostic(
+ 'error', label, source, name, raw,
+ f'{label} attribute baseline-shift={raw!r}: {exc}',
+ )
+ return True, None
if _is_unregistered_prefixed_text_property(name):
return True, TextPropertyDiagnostic(
'error', label, source, name, raw,
diff --git a/skills/ppt-master/scripts/svg_to_pptx/native_objects/inline_formula.py b/skills/ppt-master/scripts/svg_to_pptx/native_objects/inline_formula.py
index cb2d28d4..aaa1e356 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/native_objects/inline_formula.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/native_objects/inline_formula.py
@@ -160,6 +160,7 @@ def inline_formula_marker_errors(root: ET.Element) -> list[str]:
inside_preserved_text = False
inside_placeholder = False
inside_skipped_transport = False
+ inside_baseline_shift = marker.get("baseline-shift") is not None
invalid_inline_container: str | None = None
non_output_ancestor: str | None = None
fixed_structure_layer: str | None = None
@@ -177,6 +178,8 @@ def inline_formula_marker_errors(root: ET.Element) -> list[str]:
non_output_ancestor = parent_tag
if parent.get(INLINE_FORMULA_ATTR) is not None:
nested_marker = True
+ if parent.get("baseline-shift") is not None:
+ inside_baseline_shift = True
replacement = (
parent.get("data-pptx-replace-with") or ""
).strip().lower()
@@ -216,6 +219,10 @@ def inline_formula_marker_errors(root: ET.Element) -> list[str]:
)
if nested_marker:
errors.append(f"{label} cannot be nested inside another inline formula marker")
+ if inside_baseline_shift:
+ errors.append(
+ f"{label} cannot combine baseline-shift with an inline formula"
+ )
if inside_block_formula:
errors.append(
f"{label} cannot be placed inside a block formula preview"
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/template_structure.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/template_structure.py
index 85a4571c..132e744a 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/template_structure.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/template_structure.py
@@ -123,6 +123,7 @@ TEMPLATE_ADHERENCE_MODES = frozenset({"strict", "adaptive"})
TEMPLATE_REUSE_SCOPES = frozenset({"mirror", "layout", "style"})
PLACEHOLDER_BINDING_MODES = frozenset({"carrier", "proxy"})
_TEMPLATE_SKIN_ATTRS = frozenset({
+ "baseline-shift",
"color",
"fill",
"fill-opacity",