fix markdown preview
parent
49274536a4
commit
1dbe820b42
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -337,6 +337,12 @@ fieldset input {
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#editor-preview {
|
||||||
|
padding: 4% 13%;
|
||||||
|
display: block;
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
}
|
||||||
|
|
||||||
.ace_editor {
|
.ace_editor {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
border-bottom-left-radius: .5em;
|
border-bottom-left-radius: .5em;
|
||||||
|
|
|
@ -28,9 +28,9 @@ $(document).on('ready pjax:success', function() {
|
||||||
//TODO: navbar titles changing effect when changing page
|
//TODO: navbar titles changing effect when changing page
|
||||||
|
|
||||||
// Auto Grow Textarea
|
// Auto Grow Textarea
|
||||||
function autoGrow(element) {
|
function autoGrow() {
|
||||||
this.style.height = "5px";
|
this.style.height = '5px';
|
||||||
this.style.height = (this.scrollHeight) + "px";
|
this.style.height = this.scrollHeight + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
$("textarea").each(autoGrow);
|
$("textarea").each(autoGrow);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
$(document).on('page:editor', function() {
|
$(document).on('page:editor', function() {
|
||||||
var mode = $("#source-area").data('mode');
|
var mode = $("#editor-source").data('mode');
|
||||||
var editor = ace.edit("source-area");
|
var aceEditor = ace.edit("editor-source");
|
||||||
editor.getSession().setMode("ace/mode/" + mode);
|
aceEditor.getSession().setMode("ace/mode/" + mode);
|
||||||
editor.setOptions({
|
aceEditor.setOptions({
|
||||||
wrap: true,
|
wrap: true,
|
||||||
maxLines: Infinity,
|
maxLines: Infinity,
|
||||||
theme: "ace/theme/github",
|
theme: "ace/theme/github",
|
||||||
|
@ -10,11 +10,7 @@ $(document).on('page:editor', function() {
|
||||||
fontSize: "1em"
|
fontSize: "1em"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('body').off('keypress', 'input').on('keypress', 'input', function(event) {
|
||||||
preview = $("#preview-area");
|
|
||||||
textarea = $("#content-area");
|
|
||||||
|
|
||||||
$('body').on('keypress', 'input', function(event) {
|
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$('input[value="Save"]').focus().click();
|
$('input[value="Save"]').focus().click();
|
||||||
|
@ -22,6 +18,50 @@ $(document).on('page:editor', function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#site-title').keyup(function() {
|
||||||
|
$('.frontmatter #title').val($(this).val());
|
||||||
|
});
|
||||||
|
|
||||||
|
// Toggles between preview and editing mode
|
||||||
|
$("#see-preview").off('click').click(function(event) {
|
||||||
|
var preview = $('#editor-preview');
|
||||||
|
var editor = $('pre.ace_editor');
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
// If it currently in the preview mode, hide the preview
|
||||||
|
// and show the editor
|
||||||
|
if ($(this).data("previewing") == "true") {
|
||||||
|
preview.hide();
|
||||||
|
editor.fadeIn();
|
||||||
|
$(this).data("previewing", "false");
|
||||||
|
notification({
|
||||||
|
text: "Think, relax and do the better you can!",
|
||||||
|
type: 'information',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// If it's in editing mode, convert the markdown to html
|
||||||
|
// and show it
|
||||||
|
var converter = new showdown.Converter(),
|
||||||
|
text = aceEditor.getValue(),
|
||||||
|
html = converter.makeHtml(text);
|
||||||
|
|
||||||
|
// Hide the editor and show the preview
|
||||||
|
editor.hide();
|
||||||
|
preview.html(html).fadeIn();
|
||||||
|
|
||||||
|
$(this).data("previewing", "true");
|
||||||
|
notification({
|
||||||
|
text: "This is how your post looks like.",
|
||||||
|
type: 'information',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
//TODO: reform this
|
//TODO: reform this
|
||||||
// Submites any form in the page in JSON format
|
// Submites any form in the page in JSON format
|
||||||
$('form').submit(function(event) {
|
$('form').submit(function(event) {
|
||||||
|
@ -188,64 +228,6 @@ $(document).on('page:editor', function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// If it has a textarea
|
|
||||||
if (textarea[0]) {
|
|
||||||
options = {
|
|
||||||
mode: textarea.data("mode"),
|
|
||||||
theme: 'ttcn',
|
|
||||||
lineWrapping: true,
|
|
||||||
lineNumbers: true,
|
|
||||||
scrollbarStyle: null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textarea.data("mode") == "markdown") {
|
|
||||||
options.lineNumbers = false
|
|
||||||
}
|
|
||||||
|
|
||||||
editor = CodeMirror.fromTextArea(textarea[0], options);
|
|
||||||
codemirror = $('.CodeMirror');
|
|
||||||
|
|
||||||
// Toggles between preview and editing mode
|
|
||||||
$("#preview").click(function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
// If it currently in the preview mode, hide the preview
|
|
||||||
// and show the editor
|
|
||||||
if ($(this).data("previewing") == "true") {
|
|
||||||
preview.hide();
|
|
||||||
codemirror.fadeIn();
|
|
||||||
$(this).data("previewing", "false");
|
|
||||||
notification({
|
|
||||||
text: "Think, relax and do the better you can!",
|
|
||||||
type: 'information',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Copy the editor content to texteare
|
|
||||||
editor.save()
|
|
||||||
|
|
||||||
// If it's in editing mode, convert the markdown to html
|
|
||||||
// and show it
|
|
||||||
var converter = new showdown.Converter(),
|
|
||||||
text = textarea.val(),
|
|
||||||
html = converter.makeHtml(text);
|
|
||||||
|
|
||||||
// Hide the editor and show the preview
|
|
||||||
codemirror.hide();
|
|
||||||
preview.html(html).fadeIn();
|
|
||||||
|
|
||||||
$(this).data("previewing", "true");
|
|
||||||
notification({
|
|
||||||
text: "This is how your post looks like.",
|
|
||||||
type: 'information',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$("body").on('click', '.delete', function(event) {
|
$("body").on('click', '.delete', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
button = $(this);
|
button = $(this);
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{ else if eq .Class "content-only" }}
|
{{ else if eq .Class "content-only" }}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<textarea id="source-area" name="content" data-mode="{{ .Mode }}">{{ .Content }}</textarea>
|
<textarea id="editor-source" name="content" data-mode="{{ .Mode }}">{{ .Content }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<div class="frontmatter">
|
<div class="frontmatter">
|
||||||
|
@ -39,8 +39,8 @@
|
||||||
<a id="see-preview"><i class="fa fa-eye"></i> Preview</a>
|
<a id="see-preview"><i class="fa fa-eye"></i> Preview</a>
|
||||||
</nav>
|
</nav>
|
||||||
{{ end}}
|
{{ end}}
|
||||||
<textarea id="source-area" name="content" data-mode="{{ .Mode }}">{{ .Content }}</textarea>
|
<textarea id="editor-source" name="content" data-mode="{{ .Mode }}">{{ .Content }}</textarea>
|
||||||
<div id="preview-area"></div>
|
<div id="editor-preview"></div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue