Skip to content

feat(chem): re-align Chem/OLE insertion onto upstream v0.4.3#10

Merged
PiTrem merged 2 commits into
v0.4.3-xfrom
realign-v0.4.3
Jun 26, 2026
Merged

feat(chem): re-align Chem/OLE insertion onto upstream v0.4.3#10
PiTrem merged 2 commits into
v0.4.3-xfrom
realign-v0.4.3

Conversation

@PiTrem

@PiTrem PiTrem commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

Re-aligns ComPlat's custom Chem/OLE insertion feature with the upstream
v0.4.3 release. realign-v0.4.3 has been rebased onto the current v0.4.3-x
tip (which now carries the release-branch CI workflow), so this PR's checks run
against the latest base.

v0.4.3-x tracks the pristine upstream v0.4.3 tag plus our CI workflow. This
PR adds the feature on top so we can cut a custom release (e.g. v0.4.3-1) from it.

What's in here

Two commits on top of v0.4.3-x:

  1. Re-port Chem/OLE insertion onto upstream v0.4.3 architecture — realigns the
    embedded ChemDraw object + preview image ($$expr:start/:end merge fields)
    with upstream's rewritten HTML converter, template pipeline and field-handler/DOM
    systems, using the new extension points instead of the fork's hand-rolled
    rels/zip manipulation:

    • ChemHandler < FieldHandler, registered via register_field_handler :chem
    • ChemBlock < Block, scanning start/body/end nodes like the native ImageBlock
      and rewriting placeholder VML (v:imagedata/v:shape/o:OLEObject) ids consistently
    • Statement::Chem#evaluate(env) adds the preview via the DOM model's add_media
      and the OLE payload to word/embeddings with an oleObject relationship + content type
    • Sablon::Chem/Ole/Image kept as public value objects so the chemotion_ELN
      API (Chem.create/Ole/Image) is preserved
  2. Bridge Image::Definition to native image insertion; cover multi-chem loop
    duck-types the retained Image::Definition value object onto upstream's
    Content::Image contract (rid_by_file, local_rid, EMU width/height) so
    @field image merges (report status icon, spectrum attachments) work through the
    native path. Pixels scaled by PX_TO_EMU = 3000 to preserve legacy fork sizing.

Tests

  • chem_test.rb — full render of the Chem/OLE feature plus a loop case inserting
    three chem objects (distinct embeddings, unique v:shape ids)
  • image_bridge_test.rb — renders Image::Definition through the native @field
    path (incl. a loop), asserting embeds resolve and px→EMU scaling applies
  • Self-contained .docx fixtures built by test/support/build_chem_fixture.rb

Full suite green (210 runs).

PiTrem added 2 commits June 26, 2026 15:26
Proof-of-concept realigning ComPlat's custom Chem/OLE feature (embedded
ChemDraw object + preview image via `$$expr:start`/`:end` merge fields)
with senny/sablon v0.4.3, whose HTML converter, template pipeline and
field-handler/DOM systems were rewritten since the v0.0.19 fork point.

Rather than the fork's hand-rolled rels/zip manipulation, this uses the
new extension points, mirroring upstream's native image support:

- ChemHandler < FieldHandler, registered via `register_field_handler :chem`
- ChemBlock < Block, scanning start/body/end nodes like the native
  ImageBlock and rewriting the placeholder VML (v:imagedata/v:shape/
  o:OLEObject) ids consistently
- Statement::Chem#evaluate(env) (new signature) adds the preview image via
  the DOM model's add_media and the OLE payload to word/embeddings with an
  oleObject relationship + content type
- Sablon::Chem/Ole/Image kept as public value objects so the
  chemotion_ELN API (Chem.create/Ole/Image) is preserved

Adds a self-contained chem_template.docx fixture (built by
test/support/build_chem_fixture.rb) and chem_test.rb covering the full
render: embeddings/media parts, relationships, content type, rewritten
references and field removal. Full suite green (207 runs, 0 failures).
…loop

886f0bf re-ported the Chem/OLE ($$field) feature onto upstream v0.4.3 but
dropped the fork's standalone @field image handling in favour of upstream's
native Statement::Image/ImageBlock. Those expect a Content::Image-like value
(rid_by_file, local_rid, EMU width/height), so the retained ELN-facing
Sablon::Image::Definition value object raised NoMethodError when fed through
an @field merge field (the report status icon and spectrum attachments).

Duck-type Image::Definition onto that contract: a memoized rid_by_file, a
local_rid alias over the existing rid slot (kept consistent with the chem
preview path), and width/height that expose the stored pixel dimensions in
EMU. Pixels are scaled by PX_TO_EMU = 3000 to preserve the legacy fork's
image sizing so existing reports do not reflow (an intentional dpi-compat
constant, not the OOXML-canonical 9525).

Tests: image_bridge_test renders Image::Definition objects through the native
@field path (incl. a loop) and asserts every embed resolves and px->EMU
scaling applies. chem_test gains a loop case inserting three chem objects,
asserting distinct embeddings/media, a declared OLE content type, fully
resolved references and unique v:shape ids - the inconsistent rewriting that
made MS Word report unreadable content. Full suite green (210 runs).
@PiTrem PiTrem changed the title Re-align Chem/OLE feature onto upstream v0.4.3 (v0.4.3-x release base) feat(chem): re-align Chem/OLE insertion onto upstream v0.4.3 Jun 26, 2026
@PiTrem PiTrem merged commit 8683185 into v0.4.3-x Jun 26, 2026
1 check passed
@PiTrem PiTrem deleted the realign-v0.4.3 branch June 26, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant