mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Working CopyHTML shortcut
closes #3481 - Pressing Ctrl/CMD+Shift+C in the editor will open up a modal that contains the generated HTML for either the selected text or the whole post
This commit is contained in:
parent
8f5875a55c
commit
6710a1da89
5 changed files with 27 additions and 16 deletions
7
core/client/controllers/modals/copy-html.js
Normal file
7
core/client/controllers/modals/copy-html.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
var CopyHTMLController = Ember.Controller.extend({
|
||||||
|
|
||||||
|
generatedHTML: Ember.computed.alias('model.generatedHTML')
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export default CopyHTMLController;
|
|
@ -16,7 +16,7 @@
|
||||||
<a class="markdown-help" href="" {{action "openModal" "markdown"}}><span class="hidden">What is Markdown?</span></a>
|
<a class="markdown-help" href="" {{action "openModal" "markdown"}}><span class="hidden">What is Markdown?</span></a>
|
||||||
</header>
|
</header>
|
||||||
<section id="entry-markdown-content" class="entry-markdown-content">
|
<section id="entry-markdown-content" class="entry-markdown-content">
|
||||||
{{gh-codemirror value=scratch scrollInfo=view.markdownScrollInfo setCodeMirror="setCodeMirror"}}
|
{{gh-codemirror value=scratch scrollInfo=view.markdownScrollInfo setCodeMirror="setCodeMirror" openModal="openModal"}}
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
</header>
|
</header>
|
||||||
<section class="entry-preview-content">
|
<section class="entry-preview-content">
|
||||||
{{gh-markdown markdown=scratch scrollPosition=view.scrollPosition
|
{{gh-markdown markdown=scratch scrollPosition=view.scrollPosition
|
||||||
uploadStarted="disableCodeMirror" uploadFinished="enableCodeMirror" uploadSuccess="handleImgUpload"}}
|
uploadStarted="disableCodeMirror" uploadFinished="enableCodeMirror" uploadSuccess="handleImgUpload"}}
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
6
core/client/templates/modals/copy-html.hbs
Normal file
6
core/client/templates/modals/copy-html.hbs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{{#gh-modal-dialog action="closeModal" showClose=true type="action" animation="fade"
|
||||||
|
title="Generated HTML" confirm=confirm class="copy-html"}}
|
||||||
|
|
||||||
|
{{textarea value=generatedHTML rows="6"}}
|
||||||
|
|
||||||
|
{{/gh-modal-dialog}}
|
|
@ -1,4 +1,4 @@
|
||||||
/* global CodeMirror, moment */
|
/* global CodeMirror, moment, Showdown */
|
||||||
/** Set up a shortcut function to be called via router actions.
|
/** Set up a shortcut function to be called via router actions.
|
||||||
* See editor-route-base
|
* See editor-route-base
|
||||||
*/
|
*/
|
||||||
|
@ -23,7 +23,9 @@ function init() {
|
||||||
line = this.getLine(cursor.line),
|
line = this.getLine(cursor.line),
|
||||||
fromLineStart = {line: cursor.line, ch: 0},
|
fromLineStart = {line: cursor.line, ch: 0},
|
||||||
toLineEnd = {line: cursor.line, ch: line.length},
|
toLineEnd = {line: cursor.line, ch: line.length},
|
||||||
md, letterCount, textIndex, position;
|
md, letterCount, textIndex, position, converter,
|
||||||
|
generatedHTML;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'h1':
|
case 'h1':
|
||||||
line = line.replace(/^#* /, '');
|
line = line.replace(/^#* /, '');
|
||||||
|
@ -98,18 +100,19 @@ function init() {
|
||||||
case 'titlecase':
|
case 'titlecase':
|
||||||
md = titleize(text);
|
md = titleize(text);
|
||||||
break;
|
break;
|
||||||
/** @TODO
|
|
||||||
case 'copyHTML':
|
case 'copyHTML':
|
||||||
converter = new Showdown.converter();
|
converter = new Showdown.converter();
|
||||||
|
|
||||||
if (text) {
|
if (text) {
|
||||||
md = converter.makeHtml(text);
|
generatedHTML = converter.makeHtml(text);
|
||||||
} else {
|
} else {
|
||||||
md = converter.makeHtml(this.getValue());
|
generatedHTML = converter.makeHtml(this.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".modal-copyToHTML-content").text(md).selectText();
|
// Talk to Ember
|
||||||
|
this.component.sendAction('openModal', 'copy-html', { generatedHTML: generatedHTML });
|
||||||
|
|
||||||
break;
|
break;
|
||||||
*/
|
|
||||||
default:
|
default:
|
||||||
if (this.simpleShortcutSyntax[type]) {
|
if (this.simpleShortcutSyntax[type]) {
|
||||||
md = this.simpleShortcutSyntax[type].replace('$1', text);
|
md = this.simpleShortcutSyntax[type].replace('$1', text);
|
||||||
|
|
|
@ -20,6 +20,7 @@ shortcuts[ctrlOrCmd + '+i'] = {action: 'codeMirrorShortcut', options: {type: 'it
|
||||||
shortcuts['ctrl+U'] = {action: 'codeMirrorShortcut', options: {type: 'uppercase'}};
|
shortcuts['ctrl+U'] = {action: 'codeMirrorShortcut', options: {type: 'uppercase'}};
|
||||||
shortcuts['ctrl+shift+U'] = {action: 'codeMirrorShortcut', options: {type: 'lowercase'}};
|
shortcuts['ctrl+shift+U'] = {action: 'codeMirrorShortcut', options: {type: 'lowercase'}};
|
||||||
shortcuts['ctrl+alt+shift+U'] = {action: 'codeMirrorShortcut', options: {type: 'titlecase'}};
|
shortcuts['ctrl+alt+shift+U'] = {action: 'codeMirrorShortcut', options: {type: 'titlecase'}};
|
||||||
|
shortcuts[ctrlOrCmd + '+shift+c'] = {action: 'codeMirrorShortcut', options: {type: 'copyHTML'}};
|
||||||
|
|
||||||
//Headings
|
//Headings
|
||||||
shortcuts['ctrl+alt+1'] = {action: 'codeMirrorShortcut', options: {type: 'h1'}};
|
shortcuts['ctrl+alt+1'] = {action: 'codeMirrorShortcut', options: {type: 'h1'}};
|
||||||
|
@ -39,10 +40,4 @@ shortcuts[ctrlOrCmd + '+k'] = {action: 'codeMirrorShortcut', options: {type: 'li
|
||||||
shortcuts[ctrlOrCmd + '+shift+i'] = {action: 'codeMirrorShortcut', options: {type: 'image'}};
|
shortcuts[ctrlOrCmd + '+shift+i'] = {action: 'codeMirrorShortcut', options: {type: 'image'}};
|
||||||
shortcuts[ctrlOrCmd + '+shift+k'] = {action: 'codeMirrorShortcut', options: {type: 'code'}};
|
shortcuts[ctrlOrCmd + '+shift+k'] = {action: 'codeMirrorShortcut', options: {type: 'code'}};
|
||||||
|
|
||||||
//Currently broken CodeMirror Markdown shortcuts.
|
|
||||||
// Some may be broken due to a conflict with CodeMirror commands.
|
|
||||||
// (see http://codemirror.net/doc/manual.html#commands)
|
|
||||||
//
|
|
||||||
//shortcuts[ctrlOrCmd + '+c'] = {action: 'codeMirrorShortcut', options: {type: 'copyHTML'}};
|
|
||||||
|
|
||||||
export default shortcuts;
|
export default shortcuts;
|
||||||
|
|
Loading…
Add table
Reference in a new issue