Skip to content

Commit 1dc1fa1

Browse files
srguiwizmarijnh
authored andcommitted
[closetag addon] Optionally prefer empty-element tags
When user types <atomic> substitute <atomic/> if so configured.
1 parent d5906e2 commit 1dc1fa1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

addon/edit/closetag.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* An array of tag names that should, when opened, cause a
2222
* blank line to be added inside the tag, and the blank line and
2323
* closing line to be indented.
24+
* `emptyTags` (default is none)
25+
* An array of XML tag names that should be autoclosed with '/>'.
2426
*
2527
* See demos/closetag.html for a usage example.
2628
*/
@@ -76,6 +78,12 @@
7678
closingTagExists(cm, tagName, pos, state, true))
7779
return CodeMirror.Pass;
7880

81+
var emptyTags = typeof opt == "object" && opt.emptyTags;
82+
if (emptyTags && indexOf(emptyTags, tagName) > -1) {
83+
replacements[i] = { text: "/>", newPos: CodeMirror.Pos(pos.line, pos.ch + 2) };
84+
continue;
85+
}
86+
7987
var indent = indentTags && indexOf(indentTags, lowerTagName) > -1;
8088
replacements[i] = {indent: indent,
8189
text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">",

0 commit comments

Comments
 (0)