md-curcuma
Version:
A Typescript library for transporting and converting markdown and other data.
74 lines (73 loc) • 3.16 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MD_ObsidianLink_Task = void 0;
const MD_Template_1 = require("./helpers/MD_Template");
const MD_Observable_Abstract_TaskBase_1 = require("./MD_Observable_Abstract_TaskBase");
const copy_job_1 = require("../../core/copy-job");
class MD_ObsidianLink_Task extends MD_Observable_Abstract_TaskBase_1.MD_Observable_Abstract_TaskBase {
constructor(parameter) {
super();
this.tag_obsidian_prefix = "";
this.tag_obsidian_suffix = "";
this.find_rule = "";
this.replace_template = "";
this.tag = "";
this.collection = null;
this.counter = 0;
this.doCollect = false;
this.template_values = {
name_suffix: "",
name: "",
name_full: "",
};
this.parameter = parameter;
this.copy_task = parameter.copy_task;
}
perform(dao) {
dao = super.perform(dao);
return dao;
}
transform(mdfc, index) {
this.super_transform(mdfc, index);
if (this.template_values.name_suffix.match(`^(${this.find_rule})$`)) {
console.log(this.toString(`find rule '${this.find_rule}'`));
console.log(`item before : ${mdfc.body_array[index]}`);
const hugo_template = new MD_Template_1.MD_Template(this.replace_template);
mdfc.body_array[index] = mdfc.body_array[index].replace(this.tag, hugo_template.fill(this.template_values));
console.log(`item after : ${mdfc.body_array[index]}`);
console.log(``);
if (copy_job_1.CopyJob.hasCopyTask(this)) {
copy_job_1.CopyJob.perform(this.copy_task, this.template_values);
}
}
return mdfc;
}
super_transform(file_content, index) {
let item = file_content.body_array[index];
this.reset();
if (item.indexOf(this.tag_obsidian_prefix) >= 0) {
this.tag = item.substring(item.indexOf(this.tag_obsidian_prefix), item.lastIndexOf(this.tag_obsidian_suffix) + 2);
this.template_values.name_full = item.substring(item.indexOf(this.tag_obsidian_prefix) + 3, item.lastIndexOf(this.tag_obsidian_suffix));
this.template_values.name = this.template_values.name_full.substring(0, this.template_values.name_full.lastIndexOf("."));
this.template_values.name_suffix =
this.template_values.name_full.substring(this.template_values.name_full.lastIndexOf(".") + 1, this.template_values.name_full.length);
}
return file_content;
}
reset() {
this.tag = "";
this.template_values.name_full = "";
this.template_values.name = "";
this.template_values.name_suffix = "";
}
toString(what) {
return `
Transform ${what}...
tag : ${this.tag}
name_full : ${this.template_values.name_full}
name : ${this.template_values.name}
name_suffix : ${this.template_values.name_suffix}
copy_task : ${copy_job_1.CopyJob.toString(this)}`;
}
}
exports.MD_ObsidianLink_Task = MD_ObsidianLink_Task;