You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.3 KiB

2 years ago
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// main.ts
var main_exports = {};
__export(main_exports, {
default: () => ListStylePlugin
});
module.exports = __toCommonJS(main_exports);
var import_obsidian = require("obsidian");
var shorthand = {
I: "upper-roman",
i: "lower-roman",
A: "upper-alpha",
a: "lower-alpha",
"01": "decimal-leading-zero",
"1": "decimal"
};
var STYLE_MATCHER = /^\s*\{([A-Za-z-0-9]+)\}\s*/;
var ListStylePlugin = class extends import_obsidian.Plugin {
async onload() {
this.registerMarkdownPostProcessor((el) => {
el.querySelectorAll("ol").forEach((list) => {
const firstText = getFirstTextNode(list.querySelector("li"));
let match;
if (firstText && firstText.textContent && (match = firstText.textContent.match(STYLE_MATCHER))) {
if (shorthand[match[1]]) {
list.style.listStyleType = shorthand[match[1]];
} else {
list.style.listStyleType = match[1];
}
firstText.textContent = firstText.textContent.slice(match[0].length);
}
});
});
}
};
function getFirstTextNode(node) {
if (node == null)
return null;
for (let i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeType == Node.TEXT_NODE) {
return node.childNodes[i];
} else if (node.childNodes[i].hasChildNodes()) {
const childText = getFirstTextNode(node.childNodes[i]);
if (childText) {
return childText;
}
}
}
return null;
}