Browse Source

Merge pull request #251 from marijnh/attrGet

Add an attrGet method to Token
pull/259/head
Vitaly Puzrin 9 years ago
parent
commit
7a1d84fe99
  1. 14
      lib/token.js
  2. 13
      test/misc.js

14
lib/token.js

@ -163,6 +163,20 @@ Token.prototype.attrSet = function attrSet(name, value) {
};
/**
* Token.attrGet(name)
*
* Get the value of attribute `name`, or null if it does not exist.
**/
Token.prototype.attrGet = function attrGet(name) {
var idx = this.attrIndex(name), value = null;
if (idx >= 0) {
value = this.attrs[idx][1];
}
return value;
};
/**
* Token.attrJoin(name, value)
*

13
test/misc.js

@ -357,4 +357,17 @@ describe('Token attributes', function () {
'<pre><code class="bar"></code></pre>\n'
);
});
it('.attrGet', function () {
var md = markdownit();
var tokens = md.parse('```'),
t = tokens[0];
assert.strictEqual(t.attrGet('myattr'), null);
t.attrSet('myattr', 'myvalue');
assert.strictEqual(t.attrGet('myattr'), 'myvalue');
});
});

Loading…
Cancel
Save