forked from ruivieira/obsidian-plugin-logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
162 lines (154 loc) · 34.2 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
'use strict';
var obsidian = require('obsidian');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var TaskType;
(function (TaskType) {
TaskType[TaskType["TODO"] = 0] = "TODO";
TaskType[TaskType["DONE"] = 1] = "DONE";
TaskType[TaskType["DOING"] = 2] = "DOING";
TaskType[TaskType["LATER"] = 3] = "LATER";
TaskType[TaskType["CANCELED"] = 4] = "CANCELED";
TaskType[TaskType["UNKNOWN"] = 5] = "UNKNOWN";
})(TaskType || (TaskType = {}));
var HEADING_REGEX = {
h1: /(?:\s+)?- # (?:.*)$/gms,
h2: /(?:\s+)?- ## (?:.*)$/gms,
h3: /(?:\s+)?- ### (?:.*)$/gms,
h4: /(?:\s+)?- #### (?:.*)$/gms,
h5: /(?:\s+)?- ##### (?:.*)$/gms,
};
var VERSION = "0.0.3";
function parseTaskType(content) {
if (content.startsWith("DONE ")) {
return TaskType.DONE;
}
else if (content.startsWith("TODO ")) {
return TaskType.TODO;
}
else if (content.startsWith("DOING ")) {
return TaskType.DOING;
}
else if (content.startsWith("LATER ")) {
return TaskType.LATER;
}
else if (content.startsWith("CANCELED ")) {
return TaskType.CANCELED;
}
else {
return TaskType.UNKNOWN;
}
}
function removeTimestamps(content) {
return content
.replace(/doing:: (?:\d{13})/gms, "")
.replace(/done:: (?:\d{13})/gms, "")
.replace(/todo:: (?:\d{13})/gms, "")
.replace(/doing:: (?:\d{13})/gms, "")
.replace(/later:: (?:\d{13})/gms, "")
.replace(/canceled:: (?:\d{13})/gms, "")
.replace(/id:: (?:[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12})/gims, "")
.replace(/collapsed:: (?:true|false)/gms, "")
.replace("<br>", "");
}
var blockTest = new RegExp(/\#\+BEGIN_(WARNING|IMPORTANT|QUOTE|CAUTION)/gms);
function isBlock(content) {
return blockTest.test(content);
}
function cmHeadingOverlay(cm) {
cm.addOverlay({
token: function (stream) {
if (stream.match(HEADING_REGEX["h1"])) {
return "header-1";
}
else if (stream.match(HEADING_REGEX["h2"])) {
return "header-2";
}
else if (stream.match(HEADING_REGEX["h3"])) {
return "header-3";
}
else if (stream.match(HEADING_REGEX["h4"])) {
return "header-4";
}
else if (stream.match(HEADING_REGEX["h5"])) {
return "header-5";
}
else {
stream.next();
}
},
});
}
var LogSeqPlugin = /** @class */ (function (_super) {
__extends(LogSeqPlugin, _super);
function LogSeqPlugin() {
return _super !== null && _super.apply(this, arguments) || this;
}
LogSeqPlugin.prototype.onload = function () {
console.log("Loading LogSeq plugin " + VERSION);
obsidian.MarkdownPreviewRenderer.registerPostProcessor(LogSeqPlugin.postprocessor);
// Style headings in source editing
this.registerCodeMirror(cmHeadingOverlay);
};
LogSeqPlugin.prototype.onunload = function () {
console.log("unloading LogSeq plugin " + VERSION);
obsidian.MarkdownPreviewRenderer.unregisterPostProcessor(LogSeqPlugin.postprocessor);
};
LogSeqPlugin.postprocessor = function (el, ctx) {
var entries = el.querySelectorAll("li[data-line]");
entries.forEach(function (entry) {
var taskType = parseTaskType(entry.textContent);
// Check if the entry is a org-mode block
if (isBlock(entry.innerHTML)) {
var replacedBlock = entry.innerHTML.replace(/\#\+BEGIN_(WARNING|IMPORTANT|QUOTE|CAUTION)/, "<blockquote> ☟");
replacedBlock = replacedBlock.replace(/\#\+END_(WARNING|IMPORTANT|QUOTE|CAUTION)/, "</blockquote>");
entry.innerHTML = replacedBlock;
}
if (taskType == TaskType.DONE) {
var replacedHTML = removeTimestamps(entry.innerHTML.replace("DONE", ""));
entry.innerHTML = "<span class=\"logseq-done-task\"><input type=\"checkbox\" checked> " + replacedHTML + "</span>";
}
else if (taskType == TaskType.TODO) {
var replacedHTML = removeTimestamps(entry.innerHTML.replace("TODO", ""));
entry.innerHTML = "<input type=\"checkbox\"> <span class=\"logseq-status-task\">TODO</span> " + replacedHTML;
}
else if (taskType == TaskType.DOING) {
var replacedHTML = removeTimestamps(entry.innerHTML.replace("DOING", ""));
entry.innerHTML = "<input type=\"checkbox\"> <span class=\"logseq-status-task\">DOING</span> " + replacedHTML;
}
else if (taskType == TaskType.LATER) {
var replacedHTML = removeTimestamps(entry.innerHTML.replace("LATER", ""));
entry.innerHTML = "<input type=\"checkbox\"> <span class=\"logseq-status-task\">LATER</span> " + replacedHTML;
}
else if (taskType == TaskType.CANCELED) {
var replacedHTML = removeTimestamps(entry.innerHTML.replace("CANCELED", ""));
entry.innerHTML = "<span class=\"logseq-done-task\">" + replacedHTML + "</span>";
}
});
};
return LogSeqPlugin;
}(obsidian.Plugin));
module.exports = LogSeqPlugin;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsibm9kZV9tb2R1bGVzL3RzbGliL3RzbGliLmVzNi5qcyIsIm1haW4udHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyohICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqXHJcbkNvcHlyaWdodCAoYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLlxyXG5cclxuUGVybWlzc2lvbiB0byB1c2UsIGNvcHksIG1vZGlmeSwgYW5kL29yIGRpc3RyaWJ1dGUgdGhpcyBzb2Z0d2FyZSBmb3IgYW55XHJcbnB1cnBvc2Ugd2l0aCBvciB3aXRob3V0IGZlZSBpcyBoZXJlYnkgZ3JhbnRlZC5cclxuXHJcblRIRSBTT0ZUV0FSRSBJUyBQUk9WSURFRCBcIkFTIElTXCIgQU5EIFRIRSBBVVRIT1IgRElTQ0xBSU1TIEFMTCBXQVJSQU5USUVTIFdJVEhcclxuUkVHQVJEIFRPIFRISVMgU09GVFdBUkUgSU5DTFVESU5HIEFMTCBJTVBMSUVEIFdBUlJBTlRJRVMgT0YgTUVSQ0hBTlRBQklMSVRZXHJcbkFORCBGSVRORVNTLiBJTiBOTyBFVkVOVCBTSEFMTCBUSEUgQVVUSE9SIEJFIExJQUJMRSB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Ch5KSwgMCkgOiB5Lm5leHQpICYmICEodCA9IHQuY2FsbCh5LCBvcFsxXSkpLmRvbmUpIHJldHVybiB0O1xyXG4gICAgICAgICAgICBpZiAoeSA9IDAsIHQpIG9wID0gW29wWzBdICYgMiwgdC52YWx1ZV07XHJcbiAgICAgICAgICAgIHN3aXRjaCAob3BbMF0pIHtcclxuICAgICAgICAgICAgICAgIGNhc2UgMDogY2FzZSAxOiB0ID0gb3A7IGJyZWFrO1xyXG4gICAgICAgICAgICAgICAgY2FzZSA0OiBfLmxhYmVsKys7IHJldHVybiB7IHZhbHVlOiBvcFsxXSwgZG9uZTogZmFsc2UgfTtcclxuICAgICAgICAgICAgICAgIGNhc2UgNTogXy5sYWJlbCsrOyB5ID0gb3BbMV07IG9wID0gWzBdOyBjb250aW51ZTtcclxuICAgICAgICAgICAgICAgIGNhc2UgNzogb3AgPSBfLm9wcy5wb3AoKTsgXy50cnlzLnBvcCgpOyBjb250aW51ZTtcclxuICAgICAgICAgICAgICAgIGRlZmF1bHQ6XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKCEodCA9IF8udHJ5cywgdCA9IHQubGVuZ3RoID4gMCAmJiB0W3QubGVuZ3RoIC0gMV0pICYmIChvcFswXSA9PT0gNiB8fCBvcFswXSA9PT0gMikpIHsgXyA9IDA7IGNvbnRpbnVlOyB9XHJcbiAgICAgICAgICAgICAgICAgICAgaWYgKG9wWzBdID09PSAzICYmICghdCB8fCAob3BbMV0gPiB0WzBdICYmIG9wWzFdIDwgdFszXSkpKSB7IF8ubGFiZWwgPSBvcFsxXTsgYnJlYWs7IH1cclxuICAgICAgICAgICAgICAgICAgICBpZiAob3BbMF0gPT09IDYgJiYgXy5sYWJlbCA8IHRbMV0pIHsgXy5sYWJlbCA9IHRbMV07IHQgPSBvcDsgYnJlYWs7IH1cclxuICAgICAgICAgICAgICAgICAgICBpZiAodCAmJiBfLmxhYmVsIDwgdFsyXSkgeyBfLmxhYmVsID0gdFsyXTsgXy5vcHMucH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