Highlight all org-mode task states in HTML. Not just TODO, DONE.

- Make logic to extract, mark todo state in org.js more generic
- Add default todo state styling to html
This commit is contained in:
Debanjum Singh Solanky
2022-07-28 19:04:42 +04:00
parent f040b3f65c
commit 9f59897eeb
2 changed files with 15 additions and 16 deletions

View File

@@ -163,13 +163,15 @@
span.task-status { span.task-status {
color: white; color: white;
padding: 3.5px 3.5px 0; padding: 3.5px 3.5px 0;
margin: 5px; margin-right: 5px;
border-radius: 5px;
background-color: #ed6f00;
} }
span.task-status.todo { span.task-status.todo {
background-color: rgb(39, 149, 182); background-color: #048ba8
} }
span.task-status.done { span.task-status.done {
background-color: rgb(81, 143, 31); background-color: #06a77d;
} }
</style> </style>

View File

@@ -1124,13 +1124,6 @@ var Org = (function () {
switch (node.type) { switch (node.type) {
case Node.types.header: case Node.types.header:
// Parse task status
var taskStatus = null;
if (childText.indexOf("TODO ") === 0)
taskStatus = "todo";
else if (childText.indexOf("DONE ") === 0)
taskStatus = "done";
// Compute section number // Compute section number
var sectionNumberText = null; var sectionNumberText = null;
if (recordHeader) { if (recordHeader) {
@@ -1150,8 +1143,7 @@ var Org = (function () {
node.sectionNumberText = sectionNumberText; // Can be used in ToC node.sectionNumberText = sectionNumberText; // Can be used in ToC
} }
text = this.convertHeader(node, childText, auxData, text = this.convertHeader(node, childText, auxData, sectionNumberText);
taskStatus, sectionNumberText);
if (recordHeader) if (recordHeader)
this.headers.push(node); this.headers.push(node);
@@ -1493,14 +1485,19 @@ var Org = (function () {
// Node conversion // Node conversion
// ---------------------------------------------------- // ----------------------------------------------------
convertHeader: function (node, childText, auxData, convertHeader: function (node, childText, auxData, sectionNumberText) {
taskStatus, sectionNumberText) {
var headerAttributes = {}; var headerAttributes = {};
// Parse task status
taskStatusRegex = /^\s*([A-Z]+) /
taskStatusMatch = childText.match(taskStatusRegex);
taskStatus = taskStatusMatch && taskStatusMatch[1];
childText = childText.replace(taskStatusRegex, "");
if (taskStatus) { if (taskStatus) {
childText = this.inlineTag("span", childText.substring(0, 4), { childText = this.inlineTag("span", taskStatus, {
"class": "task-status " + taskStatus "class": "task-status " + taskStatus
}) + childText.substring(5); }) + childText;
} }
if (sectionNumberText) { if (sectionNumberText) {