Skip to content

Commit

Permalink
Merge pull request #36 from cosmocode/relative
Browse files Browse the repository at this point in the history
Insert relative media references if possible
  • Loading branch information
splitbrain authored Oct 21, 2024
2 parents c37d932 + b89c16e commit 3d46600
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,20 @@
* @param {string} id The newly uploaded file ID
*/
function insertSyntax(id) {

// TODO remove the "if" check after LinkWizard.createRelativeID() is available in stable (after Kaos)
if (typeof LinkWizard !== 'undefined' && typeof LinkWizard.createRelativeID === 'function') {
id = LinkWizard.createRelativeID(JSINFO.id, id);
} else {
id = ':' + id;
}

if (typeof window.proseMirrorIsActive !== 'undefined' && window.proseMirrorIsActive === true) {
const pm = window.Prosemirror.view;
const imageNode = pm.state.schema.nodes.image.create({id: id});
pm.dispatch(pm.state.tr.replaceSelectionWith(imageNode));
} else {
insertAtCarret('wiki__text', '{{:' + id + '}}');
insertAtCarret('wiki__text', '{{' + id + '}}');
}
}

Expand Down

0 comments on commit 3d46600

Please sign in to comment.