diff --git a/core/modules/parsers/wikiparser/rules/blockid.js b/core/modules/parsers/wikiparser/rules/blockid.js index ecc4e2393..84a0be41a 100644 --- a/core/modules/parsers/wikiparser/rules/blockid.js +++ b/core/modules/parsers/wikiparser/rules/blockid.js @@ -17,8 +17,10 @@ Instantiate parse rule */ exports.init = function(parser) { this.parser = parser; - // Regexp to match the block identifier located on the end of the line. - this.matchRegExp = /[ ]\^\S+$/mg; + // Regexp to match the block identifier + // 1. located on the end of the line, with a space before it, means it's the id of the current block. + // 2. located at start of the line, no space, means it's the id of the previous block. Because some block can't have id suffix, otherwise id break the block mode parser like codeblock. + this.matchRegExp = /[ ]\^(\S+)$|^\^(\S+)$/mg; }; /* @@ -27,12 +29,17 @@ Parse the most recent match exports.parse = function() { // Move past the match this.parser.pos = this.matchRegExp.lastIndex; - var id = this.match[0].slice(2); + // will be one of following case, another will be undefined + var blockId = this.match[1]; + var blockBeforeId = this.match[2]; // Parse tree nodes to return return [{ type: "blockid", attributes: { - id: {type: "string", value: id} + id: {type: "string", value: blockId || blockBeforeId}, + // `true` means the block is before this node, in parent node's children list. + // `false` means the block is this node's parent node. + before: {type: "boolean", value: Boolean(blockBeforeId)}, }, children: [] }]; diff --git a/core/modules/widgets/blockid.js b/core/modules/widgets/blockid.js index 0f33c1adb..e5902ee35 100644 --- a/core/modules/widgets/blockid.js +++ b/core/modules/widgets/blockid.js @@ -21,6 +21,9 @@ BlockIdWidget.prototype.render = function(parent,nextSibling) { // Create an invisible DOM element with data that can be accessed from JS or CSS this.spanDomNode = this.document.createElement("span"); this.spanDomNode.setAttribute("data-id",this.id); + if(this.before) { + this.spanDomNode.setAttribute("data-before","true"); + } this.spanDomNode.className = "tc-block-id"; parent.insertBefore(this.spanDomNode,nextSibling); this.domNodes.push(this.spanDomNode); @@ -32,6 +35,7 @@ Compute the internal state of the widget BlockIdWidget.prototype.execute = function() { // Get the id from the parse tree node or manually assigned attributes this.id = this.getAttribute("id"); + this.before = this.getAttribute("before"); // Make the child widgets this.makeChildWidgets(); }; diff --git a/core/ui/EditTemplate/title.tid b/core/ui/EditTemplate/title.tid index 5228ad7c0..38e75997a 100644 --- a/core/ui/EditTemplate/title.tid +++ b/core/ui/EditTemplate/title.tid @@ -4,7 +4,7 @@ tags: $:/tags/EditTemplate \whitespace trim <$edit-text field="draft.title" class="tc-titlebar tc-edit-texteditor" focus={{{ [{$:/config/AutoFocus}match[title]then[true]] ~[[false]] }}} tabindex={{$:/config/EditTabIndex}} cancelPopups="yes"/> -<$vars pattern="""[\|\[\]{}]""" bad-chars="""`| [ ] { }`"""> +<$vars pattern="""[\^\|\[\]{}]""" bad-chars="""`| ^ [ ] { }`"""> <$list filter="[all[current]regexp:draft.title]" variable="listItem">