wickedest / Mergely

Merge and diff documents online
http://www.mergely.com
Other
1.17k stars 228 forks source link

Support for CodeMirror modes in CDN install #179

Closed logut closed 1 year ago

logut commented 1 year ago

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 ?

wickedest commented 1 year ago

@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.

wickedest commented 1 year ago

@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.