Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix overencode; fix double-decode #10

Merged
merged 6 commits into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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