|
|
@@ -1557,7 +1557,9 @@ class MDTagModifier {
|
|
1557
|
1557
|
*/
|
|
1558
|
1558
|
applyTo(node) {
|
|
1559
|
1559
|
if (node instanceof MDNode) {
|
|
1560
|
|
- node.cssClasses = node.cssClasses.concat(this.cssClasses);
|
|
|
1560
|
+ for (const cssClass of this.cssClasses) {
|
|
|
1561
|
+ node.addClass(cssClass);
|
|
|
1562
|
+ }
|
|
1561
|
1563
|
if (this.cssId) node.cssId = this.cssId;
|
|
1562
|
1564
|
for (const name in this.attributes) {
|
|
1563
|
1565
|
node.attributes[name] = this.attributes[name];
|
|
|
@@ -1575,7 +1577,7 @@ class MDTagModifier {
|
|
1575
|
1577
|
* @returns {boolean} whether the class was added
|
|
1576
|
1578
|
*/
|
|
1577
|
1579
|
addClass(cssClass) {
|
|
1578
|
|
- if (this.cssClasses.contains(cssClass)) return false;
|
|
|
1580
|
+ if (this.cssClasses.indexOf(cssClass) >= 0) return false;
|
|
1579
|
1581
|
this.cssClasses.push(cssClass);
|
|
1580
|
1582
|
return true;
|
|
1581
|
1583
|
}
|
|
|
@@ -1623,7 +1625,7 @@ class MDTagModifier {
|
|
1623
|
1625
|
for (const token of modifierTokens) {
|
|
1624
|
1626
|
if (token.trim() == '') continue;
|
|
1625
|
1627
|
if (groups = this.#classRegex.exec(token)) {
|
|
1626
|
|
- mod.cssClasses.push(groups[1]);
|
|
|
1628
|
+ mod.addClass(groups[1]);
|
|
1627
|
1629
|
} else if (groups = this.#idRegex.exec(token)) {
|
|
1628
|
1630
|
mod.cssId = groups[1];
|
|
1629
|
1631
|
} else if (groups = this.#attributeRegex.exec(token)) {
|
|
|
@@ -3188,6 +3190,30 @@ class MDNode {
|
|
3188
|
3190
|
}
|
|
3189
|
3191
|
|
|
3190
|
3192
|
/**
|
|
|
3193
|
+ * Adds a CSS class. If already present it will not be duplicated.
|
|
|
3194
|
+ *
|
|
|
3195
|
+ * @param {string} cssClass
|
|
|
3196
|
+ * @returns {boolean} whether the class was added
|
|
|
3197
|
+ */
|
|
|
3198
|
+ addClass(cssClass) {
|
|
|
3199
|
+ if (this.cssClasses.indexOf(cssClass) >= 0) return false;
|
|
|
3200
|
+ this.cssClasses.push(cssClass);
|
|
|
3201
|
+ return true;
|
|
|
3202
|
+ }
|
|
|
3203
|
+
|
|
|
3204
|
+ /**
|
|
|
3205
|
+ * Removes a CSS class.
|
|
|
3206
|
+ *
|
|
|
3207
|
+ * @param {string} cssClass
|
|
|
3208
|
+ * @returns {boolean} whether the class was present and removed
|
|
|
3209
|
+ */
|
|
|
3210
|
+ removeClass(cssClass) {
|
|
|
3211
|
+ const beforeLength = this.cssClasses.length;
|
|
|
3212
|
+ this.cssClasses = this.cssClasses.filter((val) => val !== cssClass);
|
|
|
3213
|
+ return this.cssClasses.length != beforeLength;
|
|
|
3214
|
+ }
|
|
|
3215
|
+
|
|
|
3216
|
+ /**
|
|
3191
|
3217
|
* Renders this node and any children as an HTML string. If the node has no
|
|
3192
|
3218
|
* content an empty string should be returned.
|
|
3193
|
3219
|
*
|
|
|
@@ -3383,9 +3409,7 @@ class MDHeadingNode extends MDBlockNode {
|
|
3383
|
3409
|
*/
|
|
3384
|
3410
|
class MDSubtextNode extends MDBlockNode {
|
|
3385
|
3411
|
toHTML(state) {
|
|
3386
|
|
- if (this.cssClasses.indexOf('subtext') < 0) {
|
|
3387
|
|
- this.cssClasses.push('subtext');
|
|
3388
|
|
- }
|
|
|
3412
|
+ this.addClass('subtext');
|
|
3389
|
3413
|
return this._simplePairedTagHTML(state, 'div');
|
|
3390
|
3414
|
}
|
|
3391
|
3415
|
}
|
|
|
@@ -3670,7 +3694,7 @@ class MDFootnoteListNode extends MDBlockNode {
|
|
3670
|
3694
|
if (Object.keys(footnotes).length == 0) return '';
|
|
3671
|
3695
|
const footnoteUniques = state.root.footnoteInstances;
|
|
3672
|
3696
|
var html = '';
|
|
3673
|
|
- html += '<div class="footnotes"><hr/>';
|
|
|
3697
|
+ html += '<div class="footnotes">';
|
|
3674
|
3698
|
html += '<ol>';
|
|
3675
|
3699
|
for (const symbol of symbolOrder) {
|
|
3676
|
3700
|
/** @type {MDNode[]} */
|
|
|
@@ -3678,7 +3702,7 @@ class MDFootnoteListNode extends MDBlockNode {
|
|
3678
|
3702
|
if (!content) continue;
|
|
3679
|
3703
|
let footnoteId = this.#footnoteId(state, symbol);
|
|
3680
|
3704
|
const contentHTML = MDNode.toHTML(content, state);
|
|
3681
|
|
- html += `<li value="${symbol}" id="${state.root.elementIdPrefix}footnote_${footnoteId}">${contentHTML}`;
|
|
|
3705
|
+ html += `<li value="${footnoteId}" id="${state.root.elementIdPrefix}footnote_${footnoteId}">${contentHTML}`;
|
|
3682
|
3706
|
const uniques = footnoteUniques[symbol];
|
|
3683
|
3707
|
if (uniques) {
|
|
3684
|
3708
|
for (const unique of uniques) {
|
|
|
@@ -3865,7 +3889,7 @@ class MDFootnoteNode extends MDInlineNode {
|
|
3865
|
3889
|
|
|
3866
|
3890
|
toHTML(state) {
|
|
3867
|
3891
|
if (this.differentiator !== null) {
|
|
3868
|
|
- return `<sup id="${state.root.elementIdPrefix}footnoteref_${this.occurrenceId}"${this._htmlAttributes()}>` +
|
|
|
3892
|
+ return `<sup class="footnote" id="${state.root.elementIdPrefix}footnoteref_${this.occurrenceId}"${this._htmlAttributes()}>` +
|
|
3869
|
3893
|
`<a href="#${state.root.elementIdPrefix}footnote_${this.footnoteId}">${MDUtils.escapeHTML(this.displaySymbol ?? this.symbol)}</a></sup>`;
|
|
3870
|
3894
|
}
|
|
3871
|
3895
|
return `<!--FNREF:{${this.symbol}}-->`;
|
|
|
@@ -3972,8 +3996,10 @@ class MDReferencedImageNode extends MDImageNode {
|
|
3972
|
3996
|
|
|
3973
|
3997
|
toHTML(state) {
|
|
3974
|
3998
|
if (this.src === '') {
|
|
3975
|
|
- this.src = state.urlForReference(this.reference);
|
|
3976
|
|
- this.attributes['title'] = state.urlTitleForReference(this.reference);
|
|
|
3999
|
+ const url = state.urlForReference(this.reference);
|
|
|
4000
|
+ if (url !== null) this.src = url;
|
|
|
4001
|
+ const title = state.urlTitleForReference(this.reference);
|
|
|
4002
|
+ if (title !== null) this.attributes['title'] = title;
|
|
3977
|
4003
|
}
|
|
3978
|
4004
|
return super.toHTML(state);
|
|
3979
|
4005
|
}
|