wickedest/Mergely

Support for CodeMirror modes in CDN install

Closed this issue · 2 comments

logut commented

When using CDN to load Mergely, there is no access to the CodeMirror object so using modes like https://github.com/codemirror/codemirror5/blob/master/mode/javascript/javascript.js doesn't work

for example

<script src="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.css"></script>
<script src="https://unpkg.com/codemirror@5.65.14/mode/javascript/javascript.js"></script>

results in :

javascript.js:10 Uncaught ReferenceError: CodeMirror is not defined
    at javascript.js:10:9
    at javascript.js:11:3

Is there a way to add modes when using the CDN install ?

@logut, note that the CDN you have is wrong. It should be:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.css" />

But I also could not get mode working. I think it is an unintentional consequence of bundling codemirror. I will need to look into a way to try to make it work.

@logut, released 5.1 that adds support for mode. You do not need to load the mode from CDN, just specify the mode during in options.cmsettings:

const mergely = new Mergely('#compare', {
  cmsettings: {
    mode: 'javascript'
  }
});

Thanks for reporting the issue.