Add an attrGet method to Token
@ -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)
@ -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');