yarle-evernote-to-md
Version:
Yet Another Rope Ladder from Evernote
51 lines • 2.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.taskListRule = void 0;
const output_format_1 = require("../../output-format");
const yarle_1 = require("../../yarle");
const LanguageFactory_1 = require("./../../outputLanguages/LanguageFactory");
const get_attribute_proxy_1 = require("./get-attribute-proxy");
const constants_1 = require("./../../constants");
const indentCharacter = ' ';
exports.taskListRule = {
filter: 'li',
replacement: (content, node, options) => {
var _a, _b;
const isTodoDoneBlock = (node) => {
const nodeProxy = (0, get_attribute_proxy_1.getAttributeProxy)(node);
const taskFlag = '--en-checked:true;';
return nodeProxy.style && nodeProxy.style.value.indexOf(taskFlag) >= 0;
};
const isTodoBlock = (node) => {
const nodeProxy = (0, get_attribute_proxy_1.getAttributeProxy)(node);
const taskFlag = '--en-checked:false;';
return nodeProxy.style && nodeProxy.style.value.indexOf(taskFlag) >= 0;
};
const indentCount = content.match(/^\n*/)[0].length || 0;
const indentChars = indentCharacter.repeat(indentCount);
const todoPrefix = yarle_1.yarleOptions.outputFormat === output_format_1.OutputFormat.LogSeqMD ? '' :
((_b = (_a = node.parentElement) === null || _a === void 0 ? void 0 : _a.nodeName) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'LI' ? '' : `${indentChars}- `;
const singleLineContent = content
.replace(/^\n+/, '') // Remove leading newlines
.replace(/\n+$/, '\n') // Replace trailing newlines with just a single one
.replace(/\n/gm, `\n${indentCharacter}`); // Indent
const languageItems = (0, LanguageFactory_1.getLanguageItems)(yarle_1.yarleOptions.outputFormat);
let prefix = indentCount > 0
? indentChars
: (isTodoDoneBlock(node)
? `${constants_1.checkboxDone} `
: (isTodoBlock(node)
? `${constants_1.checkboxTodo} `
: languageItems.listItem));
const parent = node.parentNode;
if (parent.nodeName === 'OL') {
const start = parent.getAttribute('start');
const index = Array.prototype.indexOf.call(parent.children, node);
prefix = `${(start ? Number(start) + index : index + 1)}. `;
}
let ret;
ret = (prefix + singleLineContent + (node.nextSibling && !/\n$/.test(singleLineContent) ? '\n' : ''));
return ret;
}
};
//# sourceMappingURL=task-list-rule.js.map