Skip to content

Commit 11dfc2f

Browse files
laobubumarijnh
authored andcommitted
[markdown mode] support line-breaks in tags, and CDATA/comment blocks
1 parent e96f384 commit 11dfc2f

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

mode/markdown/markdown.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
126126
// Reset state.indentedCode
127127
state.indentedCode = false;
128128
if (state.f == htmlBlock) {
129-
state.f = inlineNormal;
130-
state.block = blockNormal;
129+
var htmlState = state.htmlState;
130+
while ('htmlState' in htmlState) htmlState = htmlState.htmlState; // htmlmixed -> xml
131+
if (!htmlState || !htmlState.tokenize || !htmlState.tokenize.isInBlock) {
132+
state.f = inlineNormal;
133+
state.block = blockNormal;
134+
state.htmlState = null;
135+
}
131136
}
132137
// Reset state.trailingSpace
133138
state.trailingSpace = 0;
@@ -534,7 +539,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
534539
return type + tokenTypes.linkEmail;
535540
}
536541

537-
if (modeCfg.xml && ch === '<' && stream.match(/^(!--|[a-z][a-z0-9-]*(?:\s+[a-z_:.\-]+(?:\s*=\s*[^>]+)?)*\s*>)/i, false)) {
542+
if (modeCfg.xml && ch === '<' && stream.match(/^(!--|\?|!\[CDATA\[|[a-z][a-z0-9-]*(?:\s+[a-z_:.\-]+(?:\s*=\s*[^>]+)?)*\s*(?:>|$))/i, false)) {
538543
var end = stream.string.indexOf(">", stream.pos);
539544
if (end != -1) {
540545
var atts = stream.string.substring(stream.start, end);

mode/markdown/test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,25 @@
12831283
"[tag&bracket <][tag div][tag&bracket >]",
12841284
"[tag&bracket </][tag div][tag&bracket >]");
12851285

1286+
MT("xmlModeLineBreakInTags",
1287+
"[tag&bracket <][tag div] [attribute id]=[string \"1\"]",
1288+
" [attribute class]=[string \"sth\"][tag&bracket >]xxx",
1289+
"[tag&bracket </][tag div][tag&bracket >]");
1290+
1291+
MT("xmlModeCommentWithBlankLine",
1292+
"[comment <!-- Hello]",
1293+
"",
1294+
"[comment World -->]");
1295+
1296+
MT("xmlModeCDATA",
1297+
"[atom <![CDATA[ Hello]",
1298+
"",
1299+
"[atom FooBar]",
1300+
"[atom Test ]]]]>]");
1301+
1302+
MT("xmlModePreprocessor",
1303+
"[meta <?php] [meta echo '1234'; ?>]");
1304+
12861305
MT_noXml("xmlHighlightDisabled",
12871306
"<div>foo</div>");
12881307

mode/xml/xml.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ CodeMirror.defineMode("xml", function(editorConf, config_) {
154154
}
155155

156156
function inBlock(style, terminator) {
157-
return function(stream, state) {
157+
var closure = function(stream, state) {
158158
while (!stream.eol()) {
159159
if (stream.match(terminator)) {
160160
state.tokenize = inText;
@@ -164,7 +164,10 @@ CodeMirror.defineMode("xml", function(editorConf, config_) {
164164
}
165165
return style;
166166
};
167+
closure.isInBlock = true;
168+
return closure;
167169
}
170+
168171
function doctype(depth) {
169172
return function(stream, state) {
170173
var ch;

0 commit comments

Comments
 (0)