Skip to content

Commit

Permalink
Merge pull request #10 from the-grid/support/fix-overencode
Browse files Browse the repository at this point in the history
fix overencode; fix double-decode
  • Loading branch information
bergie committed Mar 16, 2016
2 parents c20a2d4 + 800d7f0 commit e9ad0f6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ document.addEventListener('DOMContentLoaded', function () {
programmingLanguage: 'text/javascript'
},
id: 'd4be36b0-d18e-438c-8564-9ae79963b5e4',
html: '<pre>let foo = \'bar\';\n&lt;blink&gt;Hello&lt;/blink&gt;</pre>'
html: '<pre>&amp;amp;\nlet foo = \'bar\';\n&lt;blink&gt;Hello&period;&period;&period;&lt;/blink&gt;</pre>'
}
}, '*');
});
// Receiving content from the editor
window.addEventListener('message', function (message) {
let iframe = document.getElementById('demo');
let preview = document.getElementById('preview');
let block = document.getElementById('block');

switch (message.data.topic) {
case 'changed':
block.textContent = JSON.stringify(message.data.payload, null, 2)
preview.innerHTML = message.data.payload.html
let previewLang = document.getElementById('preview_language')
previewLang.innerHTML = message.data.payload.metadata.programmingLanguage
Expand Down
2 changes: 2 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ <h2>Editor</h2>
<iframe id="demo" src="../editor/index.html"></iframe>
<h2>Results <span id="preview_language"></span></h2>
<div id="preview"></div>
<h2>Block</h2>
<pre id="block"></pre>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"codemirror": "^5.10.0",
"entities": "^1.1.1"
"he": "^0.5.0"
},
"devDependencies": {
"babel-core": "^6.3.26",
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {encode} from 'he'
encode.options.useNamedReferences = true

import * as CodeMirror from 'codemirror'
import {encodeHTML,decodeHTML} from 'entities'
import 'codemirror/lib/codemirror.css'
import 'codemirror/theme/monokai.css'

Expand All @@ -15,6 +17,7 @@ import 'codemirror/mode/shell/shell'
import 'codemirror/mode/swift/swift'
import 'codemirror/mode/yaml/yaml'


export default class CEd {
constructor (options) {
if (!options) options = {}
Expand Down Expand Up @@ -62,7 +65,7 @@ export default class CEd {
}

prepareHTML (code, mime) {
return '<pre><code class="' + this.mimeToMode(mime) + '">' + encodeHTML(code) + '</code></pre>'
return '<pre><code class="' + this.mimeToMode(mime) + '">' + encode(code) + '</code></pre>'
}

set mode (mode) {
Expand All @@ -76,7 +79,7 @@ export default class CEd {
this.id = block.id
let el = document.createElement('div')
el.innerHTML = this.block.html
this.editor.setValue(decodeHTML(el.textContent))
this.editor.setValue(el.textContent)
if (this.block.metadata && this.block.metadata.programmingLanguage) {
this.mode = this.block.metadata.programmingLanguage
if (this.selector) this.selector.value = this.block.metadata.programmingLanguage
Expand Down

0 comments on commit e9ad0f6

Please sign in to comment.