allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [10/13] allura git commit: [#7955] style section headers preceding lines
Date Mon, 14 Sep 2015 18:30:44 GMT
[#7955] style section headers preceding lines


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/8547c0f9
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/8547c0f9
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/8547c0f9

Branch: refs/heads/db/7955
Commit: 8547c0f91af757acda90d51234961b4a9dc62080
Parents: c8e9e5c
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Mon Sep 14 14:45:57 2015 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Sep 14 18:29:40 2015 +0000

----------------------------------------------------------------------
 .../lib/widgets/resources/js/sf_markitup.js     | 29 ++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/8547c0f9/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 0ee45ee..7677757 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -67,6 +67,35 @@ $(window).load(function() {
             });
             editor.render();
 
+            // shared at https://github.com/codemirror/CodeMirror/issues/2143#issuecomment-140100969
+            function updateSectionHeaderStyles(cm, change) {
+              var lines = cm.lineCount();
+              for (var i = Math.max(0, change.from.line-1); i <= Math.min(change.to.line+1,
lines-1); i++) {
+                var line = cm.getLineHandle(i);
+                cm.removeLineClass(line, 'text', 'cm-header');
+                cm.removeLineClass(line, 'text', 'cm-header-1');
+                cm.removeLineClass(line, 'text', 'cm-header-2');
+                var lineTokens = cm.getLineTokens(i);
+                var tok = lineTokens[0];
+                if (!tok || !tok.type || tok.type.indexOf('header') === -1) {
+                  // first token could be some spaces, try 2nd
+                  tok = lineTokens[1];
+                }
+                if (tok && tok.type && tok.type.indexOf('header') !== -1
+                  && tok.string !== '#') { // not ATX header style, which starts
with #
+                  var classes = tok.type.
+                    split(' ').
+                    filter(function(cls) { return cls.indexOf('header') === 0; }).
+                    map(function (cls) { return 'cm-' + cls; }).
+                    join(' ');
+                  var prev_line = cm.getLineHandle(i-1);
+                  cm.addLineClass(prev_line, 'text', classes);
+                }
+              }
+            }
+            editor.codemirror.on("change", updateSectionHeaderStyles);
+            updateSectionHeaderStyles(editor.codemirror, {from: {line: 0}, to: {line: editor.codemirror.lineCount()}});
+
             function drawTable(editor) {
               var cm = editor.codemirror;
               _replaceSelection(cm, false, '',


Mime
View raw message