UNPKG

md-curcuma

Version:

A Typescript library for transporting and converting markdown and other data.

134 lines (133 loc) 4.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MD_Callout_Task = void 0; const MD_Template_1 = require("./helpers/MD_Template"); const MD_Observable_Abstract_TaskBase_1 = require("./MD_Observable_Abstract_TaskBase"); class MD_Callout_Task extends MD_Observable_Abstract_TaskBase_1.MD_Observable_Abstract_TaskBase { constructor(parameter) { super(); this.collection = null; this.counter = 0; this.doCollect = false; this.template_values = { context: "", title: "", icon: "", content: "", }; this.a_mapping = { source_field_name: "type", target_field_name: "context", transformations: [ { "note, seealso, example, quote, cite": "note" }, { "info, todo, tip": "tip" }, { "warning,caution, attention": "caution" }, { "danger, failure, fail, missing": "danger" }, ], }; this.b_mapping = { source_field_name: "title", target_field_name: "title", transformations: "{value}", }; this.c_mapping = { source_field_name: "icon", target_field_name: "title", transformations: "{value}", }; this.mappings = [ { "note, seealso": { context: "", icon: "", }, "abstract, summary, tldr": { context: "", icon: "", }, "info, todo": { context: "", icon: "", }, "tip, hint, important": { context: "", icon: "", }, "success, check, done": { context: "", icon: "", }, "question, help, faq": { context: "", icon: "", }, " warning, caution, attention": { context: "", icon: "", }, "failure, fail, missing": { context: "", icon: "", }, "danger, error": { context: "", icon: "", }, bug: { context: "", icon: "", }, example: { context: "", icon: "", }, "quote, cite": { context: "", icon: "", }, }, ]; this.parameter = parameter; } perform(dao) { return super.perform(dao); } transform(mdfc, index) { let item = mdfc.body_array[index]; if (!this.doCollect && item.indexOf(this.parameter.tag_obsidian_prefix) >= 0) { this.doCollect = true; console.group("callout task"); console.log("#### callout: found!"); this.collection = []; const separator_pos = item.indexOf(this.parameter.tag_obsidian_suffix); this.template_values.context = item.substring(this.parameter.tag_obsidian_prefix.length, separator_pos); this.template_values.title = item .substring(separator_pos + 1, item.length) .trim(); mdfc.body_array.splice(index, 1); mdfc.index = mdfc.index - 1; } else if (this.doCollect) { const token_pos = item.indexOf(">"); if (token_pos >= 0) { let next_item = mdfc.body_array[index + 1]; if (next_item.indexOf(">") >= 0) { this.collection.push(item.substring(token_pos + 1, item.length).trim()); mdfc.body_array.splice(index, 1); mdfc.index = mdfc.index - 1; } } else { this.doCollect = false; console.log("#### callout: process!", this.collection, this.template_values); console.groupEnd(); this.template_values.content = this.collection.join("\n"); const template = new MD_Template_1.MD_Template(this.parameter.replace_template); mdfc.body_array[index] = template.fill(this.template_values); } } return mdfc; } } exports.MD_Callout_Task = MD_Callout_Task;