Baroque triplets + dotted rhythms
I'm trying to typeset some Baroque music, where triplets are accompanied by dotted rhythms. It is a very common notation convention: a dotted eighth note + sixteenth note is understood as a quarter note + eighth note under a triplet. The first example here is from the Prelude in D major, from WTC2, BWV 874. On the left is the example in modern notation, and on the right is the original notation, but with wrong vertical spacing (and wrong playback).
The second example is how it should look like, taken from a scan of the Bach-Gesellschaft Ausgabe edition.
Could you please guide me, step by step, how to do this?