You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/09/10 00:06:44 UTC
[1/8] allura git commit: [#7955] Integration with SimpleMDE preview
customization.
Repository: allura
Updated Branches:
refs/heads/db/7955 e4091e027 -> d42c3364f (forced update)
[#7955] Integration with SimpleMDE preview customization.
Remove preview handling of editor elements since we don't have a way to run
toggleClass('preview-active') any more. Its hard to maintain that custom CSS
too - already scrolling wasn't right in preview mode.
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2466c7c3
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2466c7c3
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2466c7c3
Branch: refs/heads/db/7955
Commit: 2466c7c35e58755fffc681f32cf965510385ea37
Parents: 9c4c83f
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed Sep 2 20:06:48 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Sep 3 20:23:31 2015 +0000
----------------------------------------------------------------------
.../lib/widgets/resources/css/markitup_sf.css | 21 --------
.../lib/widgets/resources/js/sf_markitup.js | 55 ++------------------
2 files changed, 5 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/2466c7c3/Allura/allura/lib/widgets/resources/css/markitup_sf.css
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/css/markitup_sf.css b/Allura/allura/lib/widgets/resources/css/markitup_sf.css
index bcb6ff9..97c10e7 100644
--- a/Allura/allura/lib/widgets/resources/css/markitup_sf.css
+++ b/Allura/allura/lib/widgets/resources/css/markitup_sf.css
@@ -50,27 +50,6 @@
.markdown_edit .editor-preview pre {
font-family: monospace;
}
-.markdown_edit .editor-preview-active {
- background-color: transparent;
- position: relative;
- padding: 0;
-}
-.markdown_edit.preview-active {
- background-color: transparent;
-}
-.markdown_edit.preview-active .CodeMirror:not(.CodeMirror-fullscreen),
-.markdown_edit.preview-active .editor-toolbar:not(.fullscreen) {
- background-color: transparent;
- border: 0;
-}
-.markdown_edit.preview-active .CodeMirror-scroll,
-.markdown_edit.preview-active .editor-statusbar,
-span.arw.preview-active {
- display: none;
-}
-.markdown_edit.preview-active .editor-toolbar.disabled-for-preview a {
- background-color: transparent;
-}
.CodeMirror .CodeMirror-code .cm-comment {
font-family: monospace;
http://git-wip-us.apache.org/repos/asf/allura/blob/2466c7c3/Allura/allura/lib/widgets/resources/js/sf_markitup.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index 8666629..1fe1547 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -39,12 +39,7 @@ $(window).load(function() {
},
"horizontal-rule", "|",
"link", "image", "|",
- {
- name: 'preview',
- action: show_preview,
- className: 'fa fa-eye',
- title: 'Preview'
- },
+ "preview",
//"side-by-side",
"fullscreen",
tool = {
@@ -61,7 +56,8 @@ $(window).load(function() {
spellChecker: false, // https://forge-allura.apache.org/p/allura/tickets/7954/
indentWithTabs: false,
tabSize: 4,
- toolbar: toolbar
+ toolbar: toolbar,
+ preview_render: preview_render,
});
editor.render();
@@ -109,48 +105,8 @@ $(window).load(function() {
$help_area.lightbox_me();
}
- function show_preview(editor) {
- /*
- * This is pretty much the same as original SimpleMDE.togglePreview,
- * but rendered text is fetched from the server (see the comment bellow)
- * https://github.com/NextStepWebs/simplemde-markdown-editor/blob/1.2.1/source%20files/markdownify.js#L218-L249
- */
- var cm = editor.codemirror;
- var wrapper = cm.getWrapperElement();
- var toolbar_div = wrapper.previousSibling;
- var toolbar = editor.toolbarElements.preview;
- var parse = editor.constructor.markdown;
- var preview = wrapper.lastChild;
- if(!/editor-preview/.test(preview.className)) {
- preview = document.createElement('div');
- preview.className = 'editor-preview';
- wrapper.appendChild(preview);
- }
- if(/editor-preview-active/.test(preview.className)) {
- preview.className = preview.className.replace(
- /\s*editor-preview-active\s*/g, ''
- );
- toolbar.className = toolbar.className.replace(/\s*active\s*/g, '');
- toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview\s*/g, '');
- } else {
- /* When the preview button is clicked for the first time,
- * give some time for the transition from editor.css to fire and the view to slide from right to left,
- * instead of just appearing.
- */
- setTimeout(function() {
- preview.className += ' editor-preview-active';
- }, 1);
- toolbar.className += ' active';
- toolbar_div.className += ' disabled-for-preview';
- /* Code modified by Allura is here */
- var text = cm.getValue();
- get_rendered_text(preview, text);
- }
- $container.toggleClass('preview-active');
- $container.siblings('span.arw').toggleClass('preview-active');
- }
-
- function get_rendered_text(preview, text) {
+ function preview_render(editor, preview) {
+ var text = editor.codemirror.getValue();
preview.innerHTML = 'Loading...';
var cval = $.cookie('_session_id');
$.post('/nf/markdown_to_html', {
@@ -165,7 +121,6 @@ $(window).load(function() {
});
}
-
$('.close', $help_area).bind('click', function() {
$help_area.hide();
});
[4/8] allura git commit: [#7955] WIP on contextual code snippet button
Posted by br...@apache.org.
[#7955] WIP on contextual code snippet button
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/519a91a8
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/519a91a8
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/519a91a8
Branch: refs/heads/db/7955
Commit: 519a91a8de83e2331ea4fb41d445afdd09cd7c20
Parents: 424fad7
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Fri Sep 4 15:13:35 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Sep 4 15:13:35 2015 +0000
----------------------------------------------------------------------
.../lib/widgets/resources/js/sf_markitup.js | 78 ++++++++++++++++++++
1 file changed, 78 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/519a91a8/Allura/allura/lib/widgets/resources/js/sf_markitup.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index 3331b0e..ec84972 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -30,6 +30,12 @@ $(window).load(function() {
// Override action for "preview" & "guide" tools
var toolbar = [
"bold", "italic", "heading", "|",
+ {
+ name: 'code',
+ action: toggleCodeBlockTildes,
+ className: 'fa fa-code',
+ title: 'Code Block'
+ },
"quote", "unordered-list", "ordered-list",
{
name: 'table',
@@ -85,6 +91,78 @@ $(window).load(function() {
'Content Cell | Content Cell | Content Cell ');
}
+ function toggleCodeBlockTildes(editor) {
+ var cm = editor.codemirror,
+ start = cm.getCursor('start'),
+ end = cm.getCursor('end'),
+ tok = cm.getTokenAt(start),
+ types = tok.type ? tok.type.split(' ') : [],
+ is_code = types.indexOf('comment') !== -1,
+ is_code_block_indented = tok.state.base.indentedCode,
+ is_code_single_line = tok.state.base.code,
+ is_code_block_fenced = !is_code_block_indented && !is_code_single_line;
+
+ console.log(tok);
+ console.log(cm.getLineTokens(start.line));
+
+ if (is_code) {
+ if (is_code_single_line) {
+ // similar to some SimpleMDE _toggleBlock logic
+ text = cm.getLine(start.line);
+ start = text.slice(0, start.ch);
+ end = text.slice(start.ch);
+ start = start.replace('`','');
+ end = end.replace('`', '');
+ cm.replaceRange(start + end, {
+ line: start.line,
+ ch: 0
+ }, {
+ line: start.line,
+ ch: 99999999999999
+ })
+ } else {
+ var block_start, block_end;
+ /* FIXME need a way to find the block start and end
+ getTokenTypeAt doesn't work for indented blocks since first char is just a space
+ getLineHandle(i).styles doesn't work since there are multiple styles per line.
+ or could it?
+
+ */
+ for (block_start = start.line; block_start >= 0; block_start--) {
+ types = cm.getTokenTypeAt({line: block_start, ch:1});
+ console.log(block_start, types);
+ if (types && types.split(' ').indexOf('comment') !== -1) {
+ block_start += 1;
+ break;
+ }
+ }
+ lineCount = cm.lineCount();
+ for (block_end = start.line; block_end < lineCount; block_end++) {
+ if (types && types.split(' ').indexOf('comment') !== -1) {
+ block_end -= 1;
+ break;
+ }
+ }
+ console.log(block_start, block_end);
+ if (is_code_block_indented) {
+ for (var line = block_start, end = block_end; line <= end; ++line) {
+ cm.indentLine(line, 'subtract');
+ }
+ } else if (is_code_block_fenced) {
+ cm.replaceRange('', {line: block_start-1, ch:0}, {line: block_start, ch:0});
+ cm.replaceRange('', {line: block_end, ch:0}, {line: block_end+1, ch:0});
+ }
+ }
+ } else {
+ if (start === end || start.line !== end.line) {
+ _replaceSelection(cm, false, '~~~~\n', '\n~~~~');
+ } else {
+ _replaceSelection(cm, false, '`', '`');
+ }
+
+ }
+ }
+
function show_help(editor) {
$help_contents.html('Loading...');
$.get($help_contents.attr('data-url'), function (data) {
[7/8] allura git commit: [#7955] WIP: single-line code removal works
Posted by br...@apache.org.
[#7955] WIP: single-line code removal works
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/60bc7e0c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/60bc7e0c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/60bc7e0c
Branch: refs/heads/db/7955
Commit: 60bc7e0cfbdb83b1332a7b87a63696a4ed53ec5a
Parents: 901f3c7
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed Sep 9 17:11:36 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Sep 9 17:11:36 2015 +0000
----------------------------------------------------------------------
.../lib/widgets/resources/js/sf_markitup.js | 42 ++++++++++----------
1 file changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/60bc7e0c/Allura/allura/lib/widgets/resources/js/sf_markitup.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index 18620ed..1180ce7 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -93,9 +93,9 @@ $(window).load(function() {
function toggleCodeBlockTildes(editor) {
var cm = editor.codemirror,
- start = cm.getCursor('start'),
- end = cm.getCursor('end'),
- tok = cm.getTokenAt(start),
+ cur_start = cm.getCursor('start'),
+ cur_end = cm.getCursor('end'),
+ tok = cm.getTokenAt(cur_start),
types = tok.type ? tok.type.split(' ') : [],
is_code = types.indexOf('comment') !== -1,
is_code_block_indented = tok.state.base.indentedCode,
@@ -108,18 +108,20 @@ $(window).load(function() {
if (is_code) {
if (is_code_single_line) {
// similar to some SimpleMDE _toggleBlock logic
- text = cm.getLine(start.line);
- start = text.slice(0, start.ch);
- end = text.slice(start.ch);
- start = start.replace('`','');
- end = end.replace('`', '');
+ var text = cm.getLine(cur_start.line),
+ start = text.slice(0, cur_start.ch).replace('`',''),
+ end = text.slice(cur_start.ch).replace('`', '');
cm.replaceRange(start + end, {
- line: start.line,
+ line: cur_start.line,
ch: 0
}, {
- line: start.line,
+ line: cur_start.line,
ch: 99999999999999
- })
+ });
+ cur_start.ch--;
+ cur_end.ch--;
+ cm.setSelection(cur_start, cur_end);
+ cm.focus();
} else {
var block_start, block_end;
/* FIXME need a way to find the block start and end
@@ -128,7 +130,7 @@ $(window).load(function() {
or could it?
*/
- for (block_start = start.line; block_start >= 0; block_start--) {
+ for (block_start = cur_start.line; block_start >= 0; block_start--) {
types = cm.getTokenTypeAt({line: block_start, ch:1});
console.log(block_start, types);
if (types && types.split(' ').indexOf('comment') !== -1) {
@@ -137,7 +139,7 @@ $(window).load(function() {
}
}
lineCount = cm.lineCount();
- for (block_end = start.line; block_end < lineCount; block_end++) {
+ for (block_end = cur_start.line; block_end < lineCount; block_end++) {
if (types && types.split(' ').indexOf('comment') !== -1) {
block_end -= 1;
break;
@@ -145,7 +147,7 @@ $(window).load(function() {
}
console.log(block_start, block_end);
if (is_code_block_indented) {
- for (var line = block_start, end = block_end; line <= end; ++line) {
+ for (var line = block_start; line <= block_end; line++) {
cm.indentLine(line, 'subtract');
}
} else if (is_code_block_fenced) {
@@ -154,15 +156,15 @@ $(window).load(function() {
}
}
} else {
- var no_sel_and_starting_of_line = (start.line === end.line && start.ch === end.ch && start.ch === 0);
- var sel_multi = start.line !== end.line;
+ var no_sel_and_starting_of_line = (cur_start.line === cur_end.line && cur_start.ch === cur_end.ch && cur_start.ch === 0);
+ var sel_multi = cur_start.line !== cur_end.line;
if (no_sel_and_starting_of_line || sel_multi) {
- var start_line_sel = start.line + 1,
- end_line_sel = end.line + 1,
+ var start_line_sel = cur_start.line + 1,
+ end_line_sel = cur_end.line + 1,
repl_start = '~~~~\n',
repl_end = '\n~~~~';
// ensure a blank prev line
- if (cm.getLine(start.line-1)) {
+ if (cm.getLine(cur_start.line-1)) {
repl_start = '\n' + repl_start;
start_line_sel++;
end_line_sel++;
@@ -171,7 +173,7 @@ $(window).load(function() {
end_line_sel++;
}
// handle last char including \n or not
- if (sel_multi && end.ch === 0) {
+ if (sel_multi && cur_end.ch === 0) {
repl_end = '~~~~\n';
end_line_sel--;
}
[2/8] allura git commit: [#7955] in preview mode,
de-emphasize other buttons even more
Posted by br...@apache.org.
[#7955] in preview mode, de-emphasize other buttons even more
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/8381cb6d
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/8381cb6d
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/8381cb6d
Branch: refs/heads/db/7955
Commit: 8381cb6d03cfbaa0ab3a9f9f4ca9211d3e52c478
Parents: 2466c7c
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Thu Sep 3 20:22:29 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Sep 3 20:24:31 2015 +0000
----------------------------------------------------------------------
Allura/allura/lib/widgets/resources/css/markitup_sf.css | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/8381cb6d/Allura/allura/lib/widgets/resources/css/markitup_sf.css
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/css/markitup_sf.css b/Allura/allura/lib/widgets/resources/css/markitup_sf.css
index 97c10e7..13676a6 100644
--- a/Allura/allura/lib/widgets/resources/css/markitup_sf.css
+++ b/Allura/allura/lib/widgets/resources/css/markitup_sf.css
@@ -50,6 +50,9 @@
.markdown_edit .editor-preview pre {
font-family: monospace;
}
+.editor-toolbar.disabled-for-preview a:not(.fa-eye):not(.fa-arrows-alt):not(.fa-columns)::before {
+ color: #BBB;
+}
.CodeMirror .CodeMirror-code .cm-comment {
font-family: monospace;
[8/8] allura git commit: [#7955] wip: dedent working
Posted by br...@apache.org.
[#7955] wip: dedent working
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/d42c3364
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/d42c3364
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/d42c3364
Branch: refs/heads/db/7955
Commit: d42c3364fd897f00172b76f23a789a1bf8262e8d
Parents: 60bc7e0
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed Sep 9 22:06:20 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Sep 9 22:06:20 2015 +0000
----------------------------------------------------------------------
.../lib/widgets/resources/js/sf_markitup.js | 123 +++++++++++++------
1 file changed, 88 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/d42c3364/Allura/allura/lib/widgets/resources/js/sf_markitup.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index 1180ce7..c66562d 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -97,20 +97,22 @@ $(window).load(function() {
cur_end = cm.getCursor('end'),
tok = cm.getTokenAt(cur_start),
types = tok.type ? tok.type.split(' ') : [],
- is_code = types.indexOf('comment') !== -1,
- is_code_block_indented = tok.state.base.indentedCode,
- is_code_single_line = tok.state.base.code,
+ line = cm.getLineHandle(cur_start.line),
+ lastTok = !!line.text && cm.getTokenAt({line: cur_start.line, ch: line.text.length-1}),
+ is_code_block_indented = lastTok && lastTok.state.base.indentedCode, // have to check last char, since first chars of first line aren't marked as indented
+ is_code = types.indexOf('comment') !== -1 || is_code_block_indented, // have to also check for indented, since first chars of first indented line aren't marked
+ is_code_single_line = tok.state.base.code, // FIXME false-positive for ``` line, check for formatting-code-block
is_code_block_fenced = !is_code_block_indented && !is_code_single_line;
- console.log(tok);
- console.log(cm.getLineTokens(start.line));
+ console.log(lastTok);
+ console.log('code:', is_code, 'indented', is_code_block_indented, 'fenced', is_code_block_fenced, 'single', is_code_single_line);
+ //console.log(cm.getLineTokens(start.line));
if (is_code) {
if (is_code_single_line) {
// similar to some SimpleMDE _toggleBlock logic
- var text = cm.getLine(cur_start.line),
- start = text.slice(0, cur_start.ch).replace('`',''),
- end = text.slice(cur_start.ch).replace('`', '');
+ var start = line.text.slice(0, cur_start.ch).replace('`',''),
+ end = line.text.slice(cur_start.ch).replace('`', '');
cm.replaceRange(start + end, {
line: cur_start.line,
ch: 0
@@ -122,40 +124,91 @@ $(window).load(function() {
cur_end.ch--;
cm.setSelection(cur_start, cur_end);
cm.focus();
- } else {
+ } else if (is_code_block_fenced) {
+ /*
+ DEBUG
+ */
+ for (var i = 0; i < cm.lineCount(); i++) {
+ tok0 = cm.getTokenAt({line: i, ch: 0});
+ tok1 = cm.getTokenAt({line: i, ch: 1});
+ //types0 = cm.getTokenTypeAt({line: i, ch:0});
+ //types1 = cm.getTokenTypeAt({line: i, ch:1});
+ line = cm.getLineHandle(i);
+ //lineToks = cm.getLineTokens(i);
+ //lastTok = lineToks.length && lineToks[lineToks.length-1]
+ lastTok = line.text && cm.getTokenAt({line: i, ch: line.text.length-1});
+ console.log('line', i,
+ tok0.type, ',', tok1.type, ',',
+ //tok0.state.base.indentedCode, tok1.state.base.indentedCode,
+ 'last tok indented:', lastTok && lastTok.state.base.indentedCode,
+ 'first tok indented:', tok1.state.base.indentedCode,
+ 'last tok inline code:', lastTok && lastTok.state.base.code,
+ 'first tok inline code:', tok1.state.base.code,
+ 'last tok type:', lastTok && lastTok.type,
+ 'styles:', line && line.styles, line && line.text);
+ //console.log(cm.getLineTokens(i));
+ }
+ return;
+
+ // look for formatting-code-block with highlightFormatting turned on :(
+ // or look for whole line being "comment" and not tok.state.base.code (which means inline)
+ // FIXME what about selection?
+ cm.replaceRange('', {line: block_start-1, ch:0}, {line: block_start, ch:0});
+ cm.replaceRange('', {line: block_end, ch:0}, {line: block_end+1, ch:0});
+ } else if (is_code_block_indented) {
var block_start, block_end;
- /* FIXME need a way to find the block start and end
- getTokenTypeAt doesn't work for indented blocks since first char is just a space
- getLineHandle(i).styles doesn't work since there are multiple styles per line.
- or could it?
-
- */
- for (block_start = cur_start.line; block_start >= 0; block_start--) {
- types = cm.getTokenTypeAt({line: block_start, ch:1});
- console.log(block_start, types);
- if (types && types.split(' ').indexOf('comment') !== -1) {
- block_start += 1;
- break;
+ if (cur_start.line !== cur_end.line || cur_start.ch !== cur_end.ch) {
+ // use selection
+ block_start = cur_start.line;
+ block_end = cur_end.line;
+ if (cur_end.ch === 0) {
+ block_end--;
}
- }
- lineCount = cm.lineCount();
- for (block_end = cur_start.line; block_end < lineCount; block_end++) {
- if (types && types.split(' ').indexOf('comment') !== -1) {
- block_end -= 1;
- break;
+ } else {
+ // no selection, search for ends of this indented block
+ for (block_start = cur_start.line; block_start >= 0; block_start--) {
+ line = cm.getLineHandle(block_start);
+ if (line.text.match(/^\s*$/)) {
+ // empty or all whitespace - keep going
+ continue;
+ } else {
+ lastTok = cm.getTokenAt({line: block_start, ch: line.text.length-1});
+ if (!lastTok.state.base.indentedCode) {
+ block_start += 1;
+ break;
+ }
+ }
}
- }
- console.log(block_start, block_end);
- if (is_code_block_indented) {
- for (var line = block_start; line <= block_end; line++) {
- cm.indentLine(line, 'subtract');
+ lineCount = cm.lineCount();
+ for (block_end = cur_start.line; block_end < lineCount; block_end++) {
+ line = cm.getLineHandle(block_end);
+ if (line.text.match(/^\s*$/)) {
+ // empty or all whitespace - keep going
+ continue;
+ } else {
+ lastTok = cm.getTokenAt({line: block_end, ch: line.text.length-1});
+ if (!lastTok.state.base.indentedCode) {
+ block_end -= 1;
+ break;
+ }
+ }
}
- } else if (is_code_block_fenced) {
- cm.replaceRange('', {line: block_start-1, ch:0}, {line: block_start, ch:0});
- cm.replaceRange('', {line: block_end, ch:0}, {line: block_end+1, ch:0});
+ }
+ // if we are going to un-indent based on a selected set of lines, and the next line is indented too, we need to
+ // insert a blank line so that the next line(s) continue to be indented code
+ var next_line = cm.getLineHandle(block_end+1),
+ next_line_last_tok = next_line && cm.getTokenAt({line: block_end+1, ch: next_line.text.length-1}),
+ next_line_indented = next_line_last_tok && next_line_last_tok.state.base.indentedCode;
+ if (next_line_indented) {
+ cm.replaceRange('\n', {line: block_end+1, ch:0});
+ }
+
+ for (var i = block_start; i <= block_end; i++) {
+ cm.indentLine(i, 'subtract'); // TODO: this doesn't get tracked in the history, so can't be undone :(
}
}
} else {
+ // insert code formatting
var no_sel_and_starting_of_line = (cur_start.line === cur_end.line && cur_start.ch === cur_end.ch && cur_start.ch === 0);
var sel_multi = cur_start.line !== cur_end.line;
if (no_sel_and_starting_of_line || sel_multi) {
[3/8] allura git commit: [#7955] change previewRender option name
Posted by br...@apache.org.
[#7955] change previewRender option name
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/424fad7f
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/424fad7f
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/424fad7f
Branch: refs/heads/db/7955
Commit: 424fad7f5f2348d82503845ca00c830f643ee1c8
Parents: 8381cb6
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Fri Sep 4 15:13:19 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Sep 4 15:13:19 2015 +0000
----------------------------------------------------------------------
Allura/allura/lib/widgets/resources/js/sf_markitup.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/424fad7f/Allura/allura/lib/widgets/resources/js/sf_markitup.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index 1fe1547..3331b0e 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -57,7 +57,7 @@ $(window).load(function() {
indentWithTabs: false,
tabSize: 4,
toolbar: toolbar,
- preview_render: preview_render,
+ previewRender: preview_render,
});
editor.render();
[5/8] allura git commit: inserts working nicely
Posted by br...@apache.org.
inserts working nicely
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/34980d2c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/34980d2c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/34980d2c
Branch: refs/heads/db/7955
Commit: 34980d2c51bb40630904fff5e6f8351401001f82
Parents: 519a91a
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Fri Sep 4 16:17:48 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Sep 4 16:17:48 2015 +0000
----------------------------------------------------------------------
.../lib/widgets/resources/js/sf_markitup.js | 26 ++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/34980d2c/Allura/allura/lib/widgets/resources/js/sf_markitup.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index ec84972..38f642a 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -154,8 +154,30 @@ $(window).load(function() {
}
}
} else {
- if (start === end || start.line !== end.line) {
- _replaceSelection(cm, false, '~~~~\n', '\n~~~~');
+ var no_sel_and_starting_of_line = (start.line === end.line && start.ch === end.ch && start.ch === 0);
+ var sel_multi = start.line !== end.line;
+ if (no_sel_and_starting_of_line || sel_multi) {
+ var start_line_sel = start.line + 1,
+ end_line_sel = end.line + 1,
+ repl_start = '~~~~\n',
+ repl_end = '\n~~~~';
+ // ensure a blank prev line
+ if (cm.getLine(start.line-1)) {
+ repl_start = '\n' + repl_start;
+ start_line_sel++;
+ end_line_sel++;
+ }
+ if (sel_multi) {
+ end_line_sel++;
+ }
+ // handle last char including \n or not
+ if (sel_multi && end.ch === 0) {
+ repl_end = '~~~~\n';
+ end_line_sel--;
+ }
+ _replaceSelection(cm, false, repl_start, repl_end);
+ cm.setSelection({line: start_line_sel, ch: 0},
+ {line: end_line_sel, ch: 0});
} else {
_replaceSelection(cm, false, '`', '`');
}
[6/8] allura git commit: [#7955] change previewRender signature
Posted by br...@apache.org.
[#7955] change previewRender signature
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/901f3c77
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/901f3c77
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/901f3c77
Branch: refs/heads/db/7955
Commit: 901f3c77f7c4065adb9a40df0c1510d98cc1e2d4
Parents: 34980d2
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Tue Sep 8 20:54:58 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Tue Sep 8 20:54:58 2015 +0000
----------------------------------------------------------------------
Allura/allura/lib/widgets/resources/js/sf_markitup.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/901f3c77/Allura/allura/lib/widgets/resources/js/sf_markitup.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index 38f642a..18620ed 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -63,7 +63,7 @@ $(window).load(function() {
indentWithTabs: false,
tabSize: 4,
toolbar: toolbar,
- previewRender: preview_render,
+ previewRender: previewRender,
});
editor.render();
@@ -205,9 +205,7 @@ $(window).load(function() {
$help_area.lightbox_me();
}
- function preview_render(editor, preview) {
- var text = editor.codemirror.getValue();
- preview.innerHTML = 'Loading...';
+ function previewRender(text, preview) {
var cval = $.cookie('_session_id');
$.post('/nf/markdown_to_html', {
markdown: text,
@@ -219,6 +217,7 @@ $(window).load(function() {
function(resp) {
preview.innerHTML = resp;
});
+ return 'Loading...';
}
$('.close', $help_area).bind('click', function() {