Sha256: 4796215562e6a6695cd013ac35311eb29c18fff27147c48f2a16623d6656c4d4

Contents?: true

Size: 1.57 KB

Versions: 133

Compression:

Stored size: 1.57 KB

Contents

// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE

(function(mod) {
  if (typeof exports == "object" && typeof module == "object") // CommonJS
    mod(require("../../lib/codemirror"));
  else if (typeof define == "function" && define.amd) // AMD
    define(["../../lib/codemirror"], mod);
  else // Plain browser env
    mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.registerHelper("fold", "markdown", function(cm, start) {
  var maxDepth = 100;

  function isHeader(lineNo) {
    var tokentype = cm.getTokenTypeAt(CodeMirror.Pos(lineNo, 0));
    return tokentype && /\bheader\b/.test(tokentype);
  }

  function headerLevel(lineNo, line, nextLine) {
    var match = line && line.match(/^#+/);
    if (match && isHeader(lineNo)) return match[0].length;
    match = nextLine && nextLine.match(/^[=\-]+\s*$/);
    if (match && isHeader(lineNo + 1)) return nextLine[0] == "=" ? 1 : 2;
    return maxDepth;
  }

  var firstLine = cm.getLine(start.line), nextLine = cm.getLine(start.line + 1);
  var level = headerLevel(start.line, firstLine, nextLine);
  if (level === maxDepth) return undefined;

  var lastLineNo = cm.lastLine();
  var end = start.line, nextNextLine = cm.getLine(end + 2);
  while (end < lastLineNo) {
    if (headerLevel(end + 1, nextLine, nextNextLine) <= level) break;
    ++end;
    nextLine = nextNextLine;
    nextNextLine = cm.getLine(end + 2);
  }

  return {
    from: CodeMirror.Pos(start.line, firstLine.length),
    to: CodeMirror.Pos(end, cm.getLine(end).length)
  };
});

});

Version data entries

133 entries across 107 versions & 13 rubygems

Version Path
locomotivecms-4.2.0.alpha2 vendor/assets/javascripts/locomotive/codemirror/addons/fold/markdown-fold.js
locomotivecms-4.2.0.alpha1 vendor/assets/javascripts/locomotive/codemirror/addons/fold/markdown-fold.js
scrivito_codemirror_editor-1.1.0 vendor/assets/javascripts/codemirror/addons/fold/markdown-fold.js
jeygeethanmedia-inkpen-1.2.6.2 public/codemirror/addon/fold/markdown-fold.js
jeygeethanmedia-inkpen-1.2.6.1 public/codemirror/addon/fold/markdown-fold.js
keppler-2.1.22 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.22 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.21 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.21 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.20 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.20 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.19 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.19 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.18 testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.18 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.18 testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.18 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.17 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/markdown-fold.js
keppler-2.1.17 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/markdown-fold.js
stisla-rails-0.0.2 vendor/assets/modules/codemirror/addon/fold/markdown-fold.js