Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6dc18a
commit 633f829
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CodeMirror.registerHelper("fold", "markdown", function(cm, start) { | ||
var level, end, maxDepth = 100, firstLine = cm.getLine(start.line), lastLine = cm.lastLine(); | ||
|
||
function headerLevel(line) { | ||
if (!line) return maxDepth; | ||
var match = line.match(/^#+/); | ||
return match ? match[0].length : maxDepth; | ||
} | ||
|
||
level = headerLevel(firstLine); | ||
if (level === maxDepth) return undefined; | ||
|
||
for (end = start.line + 1; end < lastLine; ++end) { | ||
if (headerLevel(cm.getLine(end + 1)) <= level) { | ||
break; | ||
} | ||
} | ||
|
||
return { | ||
from: CodeMirror.Pos(start.line, cm.getLine(start.line).length), | ||
to: CodeMirror.Pos(end, cm.getLine(end).length) | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters