3 var entityPrefixLength = require('./entity-prefix-length');
7 var PUNCTUATION = /[-!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~_]/;
9 /* For shortcut and collapsed reference links, the contents
10 * is also an identifier, so we need to restore the original
11 * encoding and escaping that were present in the source
14 * This function takes the unescaped & unencoded value from
15 * shortcut's child nodes and the identifier and encodes
16 * the former according to the latter. */
17 function copy(value, identifier) {
18 var length = value.length;
19 var count = identifier.length;
25 while (index < length) {
26 /* Take next non-punctuation characters from `value`. */
29 while (index < length && !PUNCTUATION.test(value.charAt(index))) {
33 result.push(value.slice(start, index));
35 /* Advance `position` to the next punctuation character. */
36 while (position < count && !PUNCTUATION.test(identifier.charAt(position))) {
40 /* Take next punctuation characters from `identifier`. */
43 while (position < count && PUNCTUATION.test(identifier.charAt(position))) {
44 if (identifier.charAt(position) === '&') {
45 position += entityPrefixLength(identifier.slice(position));
51 result.push(identifier.slice(start, position));
53 /* Advance `index` to the next non-punctuation character. */
54 while (index < length && PUNCTUATION.test(value.charAt(index))) {
59 return result.join('');