Skip to content

Commit

Permalink
publish 1.8.5 - Fix code wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
stulip committed Jun 3, 2021
1 parent cbfaa79 commit 069b47d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/src/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const initHTML = `<br/>
<br/>
<div><center><img src="${imageList[0]}" onclick="_.sendEvent('ImgClick')" contenteditable="false" height="170px"/></center></div>
<div>
<pre type="javascript"><code>const editor = ReactNative;</code><code>console.log(editor);</code></pre>
<br/>Click the picture to switch<br/><br/>
</div>
`;
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ export class RichEditor extends React.Component<RichEditorProps> {
insertText: (text: string) => void;

insertHTML: (html: string) => void;

preCode: (type: string) => void;

/**
* 1 = 10px, 2 = 13px, 3 = 16px, 4 = 18px, 5 = 24px, 6 = 32px, 7 = 48px;
Expand Down
4 changes: 4 additions & 0 deletions src/RichEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ export default class RichTextEditor extends Component {
}
}

preCode (type){
this.sendAction(actions.code, 'result', type);
}

setFontSize(size) {
this.sendAction(actions.fontSize, 'result', size);
}
Expand Down
16 changes: 14 additions & 2 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function getContentCSS() {
.x-todo-box input{position: absolute;}
blockquote{border-left: 6px solid #ddd;padding: 5px 0 5px 10px;margin: 15px 0 15px 15px;}
hr{display: block;height: 0; border: 0;border-top: 1px solid #ccc; margin: 15px 0; padding: 0;}
pre{padding: 10px 5px 10px 10px;margin: 15px 0;display: block;line-height: 18px;background: #F0F0F0;border-radius: 3px;font-size: 13px; font-family: 'monaco', 'Consolas', "Liberation Mono", Courier, monospace; white-space: pre; word-wrap: normal;overflow-x: auto;}
pre{padding: 10px 5px 10px 10px;margin: 15px 0;display: block;line-height: 18px;background: #F0F0F0;border-radius: 6px;font-size: 13px; font-family: 'monaco', 'Consolas', "Liberation Mono", Courier, monospace; word-break: break-all; word-wrap: break-word;overflow-x: auto;}
pre code {display: block;font-size: inherit;white-space: pre-wrap;color: inherit;}
</style>
`;
}
Expand Down Expand Up @@ -266,7 +267,18 @@ function createHTML(options = {}) {
state: function() { return queryCommandState('insertUnorderedList');},
result: function() { if (!!checkboxNode(window.getSelection().anchorNode)) return; return exec('insertUnorderedList');}
},
code: { result: function() { return exec(formatBlock, '<pre>'); }},
code: { result: function(type) {
var flag = exec(formatBlock, '<pre>');
var node = anchorNode.nodeName === "PRE" ? anchorNode: anchorNode.parentNode;
if (node.nodeName === 'PRE'){
type && node.setAttribute("type", type);
node.innerHTML = "<code type='"+(type || '') +"'>" + node.innerHTML + "</code>";
setTimeout(function (){
setCollapse(node.firstChild);
});
}
return flag;
}},
line: { result: function() { return exec('insertHorizontalRule'); }},
redo: { result: function() { return exec('redo'); }},
undo: { result: function() { return exec('undo'); }},
Expand Down
1 change: 1 addition & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
const HTML = createHTML({
cssText: 'html {overflow-y: auto;}',
pasteAsPlainText: false,
useContainer: false,
});
window.actions = actions;
const initHTML = `
Expand Down

0 comments on commit 069b47d

Please sign in to comment.