Permalink
Browse files

[markdown mode] Fix highlighting for code blocks with internal indent…

…ation.
  • Loading branch information...
1 parent 986b40d commit 984e15502fb54aebdf6c272910a7543ed1efe0e7 @0b10011 0b10011 committed with marijnh Sep 17, 2012
Showing with 51 additions and 0 deletions.
  1. +3 −0 mode/markdown/markdown.js
  2. +48 −0 mode/markdown/test.js
@@ -374,6 +374,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.f = state.block;
var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length;
+ var difference = Math.floor((indentation - state.indentation) / 4) * 4;
+ if (difference > 4) difference = 4;
+ indentation = state.indentation + difference;
state.indentationDiff = indentation - state.indentation;
state.indentation = indentation;
if (indentation > 0) { return null; }
View
@@ -20,6 +20,36 @@ MT.testMode(
'comment', 'foo'
]
);
+// Code blocks using 4 spaces with internal indentation
+MT.testMode(
+ 'codeBlocksUsing4SpacesIndentation',
+ ' bar\n hello\n world\n foo\nbar',
+ [
+ null, ' ',
+ 'comment', 'bar',
+ null, ' ',
+ 'comment', 'hello',
+ null, ' ',
+ 'comment', 'world',
+ null, ' ',
+ 'comment', 'foo',
+ null, 'bar'
+ ]
+);
+// Code blocks using 4 spaces with internal indentation
+MT.testMode(
+ 'codeBlocksUsing4SpacesIndentation',
+ ' foo\n bar\n hello\n world',
+ [
+ null, ' foo',
+ null, ' ',
+ 'comment', 'bar',
+ null, ' ',
+ 'comment', 'hello',
+ null, ' ',
+ 'comment', 'world'
+ ]
+);
// Code blocks using 1 tab (regardless of CodeMirror.indentWithTabs value)
MT.testMode(
@@ -584,6 +614,24 @@ MT.testMode(
'comment', 'hello'
]
);
+// Code with internal indentation
+MT.testMode(
+ 'listCodeIndentation',
+ '* foo\n\n bar\n hello\n world\n foo\n bar',
+ [
+ 'string', '* foo',
+ null, ' ',
+ 'comment', 'bar',
+ null, ' ',
+ 'comment', 'hello',
+ null, ' ',
+ 'comment', 'world',
+ null, ' ',
+ 'comment', 'foo',
+ null, ' ',
+ 'string', 'bar'
+ ]
+);
// Code followed by text
MT.testMode(
'listCodeText',

0 comments on commit 984e155

Please sign in to comment.