From 01e7a56dc2d7ac77befc021b23a95e163fe7558a Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 1 Mar 2023 17:17:48 +0100 Subject: [PATCH] start parsing headers of org file counts --- org-parse/index.js | 51 ++++++++-- org-parse/input.org | 4 +- org-parse/output.txt | 233 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 278 insertions(+), 10 deletions(-) diff --git a/org-parse/index.js b/org-parse/index.js index 15172e31..4fd52481 100644 --- a/org-parse/index.js +++ b/org-parse/index.js @@ -16,13 +16,52 @@ fs.readFile(input_orgmode_file_name, 'utf8', function read(err, data) { var parser = new org.Parser(); var orgDocument = parser.parse(org_content); - console.log('le fichier input.org a ce nombre de'); - console.log(' SOMEDAY:', org_content.toString().match(/SOMEDAY/g)?.length); - console.log(' TODO:', org_content.toString().match(/TODO/g)?.length); - console.log(' NEXT:', org_content.toString().match(/NEXT/g)?.length); - console.log(' CANCELLED:', org_content.toString().match(/CANCELLED/g)?.length); - console.log(' DONE:', org_content.toString().match(/DONE/g)?.length); + // console.log('orgDocument', orgDocument) + orgDocument.nodes.forEach(node => { + + if (node.type === 'header') { + console.log('header') + + searchForChildren(node) + } + }) + + console.log('headerTexts', headerTexts); + + let all_headers = headerTexts.join('\n') + console.log('le fichier input.org a ce nombre de type de tâches'); + console.log(' SOMEDAY:', all_headers.toString().match(/SOMEDAY/g)?.length); + console.log(' TODO:', all_headers.toString().match(/TODO/g)?.length); + console.log(' NEXT:', all_headers.toString().match(/NEXT/g)?.length); + console.log(' CANCELLED:', all_headers.toString().match(/CANCELLED/g)?.length); + console.log(' DONE:', all_headers.toString().match(/DONE/g)?.length); }); +let headerTexts = [] + +function logTextOfNode(node) { + if (node.value && node.type==='text') { + console.log(' -- ', node.value) + headerTexts.push(node.value) + } +} + +function searchForChildren(node) { + logTextOfNode(node) + + if (node.children) { + + node.children.forEach(child => { + console.log(' -- ', child) + searchForChildren(child) + }) + } +} + +// trouver les propriétés de date de cloture pour grouper les tâches par section de temps +// afin de savoir ce qui a été réalisé ces X derniers jours + +let interval_report_days = 30; + diff --git a/org-parse/input.org b/org-parse/input.org index 6f3e9627..3f7ed654 100644 --- a/org-parse/input.org +++ b/org-parse/input.org @@ -1,11 +1,13 @@ * des choses ** TODO faire un truc +CLOSED: [2023-03-01 mer. 10:42] une tâche de niveau 2 sans tag, properties ni logbook ** TODO faire un autre truc :autre: +CLOSED: [2023-02-01 mer. 10:42] :LOGBOOK: - State "CANCELLED" from "TODO" [2023-02-28 mar. 11:50] :END: ya du logbook ici wohoo *** SOMEDAY avoir une idée :idea: -** CANCELLED envoyer un justificatif médical :ARCHIVE: +**** CANCELLED envoyer un justificatif médical :ARCHIVE: héééééé oui le texte de note \ No newline at end of file diff --git a/org-parse/output.txt b/org-parse/output.txt index 0bf31d64..a76142ff 100644 --- a/org-parse/output.txt +++ b/org-parse/output.txt @@ -1,6 +1,233 @@ -le fichier input.org a ce nombre de +header + -- { + type: 'inlineContainer', + children: [ + { + type: 'text', + children: [], + value: 'des choses', + previousSibling: null, + parent: [Circular *1] + } + ], + previousSibling: null, + parent: { + type: 'header', + children: [ [Circular *1] ], + level: 1, + fromLineNumber: 1, + previousSibling: null + } +} + -- { + type: 'text', + children: [], + value: 'des choses', + previousSibling: null, + parent: { + type: 'inlineContainer', + children: [ [Circular *1] ], + previousSibling: null, + parent: { + type: 'header', + children: [Array], + level: 1, + fromLineNumber: 1, + previousSibling: null + } + } +} + -- des choses +header + -- { + type: 'inlineContainer', + children: [ + { + type: 'text', + children: [], + value: 'TODO faire un truc', + previousSibling: null, + parent: [Circular *1] + } + ], + previousSibling: null, + parent: { + type: 'header', + children: [ [Circular *1] ], + level: 2, + fromLineNumber: 2, + previousSibling: { + type: 'header', + children: [Array], + level: 1, + fromLineNumber: 1, + previousSibling: null + } + } +} + -- { + type: 'text', + children: [], + value: 'TODO faire un truc', + previousSibling: null, + parent: { + type: 'inlineContainer', + children: [ [Circular *1] ], + previousSibling: null, + parent: { + type: 'header', + children: [Array], + level: 2, + fromLineNumber: 2, + previousSibling: [Object] + } + } +} + -- TODO faire un truc +header + -- { + type: 'inlineContainer', + children: [ + { + type: 'text', + children: [], + value: 'TODO faire un autre truc :autre:', + previousSibling: null, + parent: [Circular *1] + } + ], + previousSibling: null, + parent: { + type: 'header', + children: [ [Circular *1] ], + level: 2, + fromLineNumber: 4, + previousSibling: { + type: 'inlineContainer', + children: [Array], + previousSibling: [Object] + } + } +} + -- { + type: 'text', + children: [], + value: 'TODO faire un autre truc :autre:', + previousSibling: null, + parent: { + type: 'inlineContainer', + children: [ [Circular *1] ], + previousSibling: null, + parent: { + type: 'header', + children: [Array], + level: 2, + fromLineNumber: 4, + previousSibling: [Object] + } + } +} + -- TODO faire un autre truc :autre: +header + -- { + type: 'inlineContainer', + children: [ + { + type: 'text', + children: [], + value: 'SOMEDAY avoir une idée :idea:', + previousSibling: null, + parent: [Circular *1] + } + ], + previousSibling: null, + parent: { + type: 'header', + children: [ [Circular *1] ], + level: 3, + fromLineNumber: 9, + previousSibling: { + type: 'inlineContainer', + children: [Array], + previousSibling: [Object] + } + } +} + -- { + type: 'text', + children: [], + value: 'SOMEDAY avoir une idée :idea:', + previousSibling: null, + parent: { + type: 'inlineContainer', + children: [ [Circular *1] ], + previousSibling: null, + parent: { + type: 'header', + children: [Array], + level: 3, + fromLineNumber: 9, + previousSibling: [Object] + } + } +} + -- SOMEDAY avoir une idée :idea: +header + -- { + type: 'inlineContainer', + children: [ + { + type: 'text', + children: [], + value: 'CANCELLED envoyer un justificatif médical :ARCHIVE:', + previousSibling: null, + parent: [Circular *1] + } + ], + previousSibling: null, + parent: { + type: 'header', + children: [ [Circular *1] ], + level: 4, + fromLineNumber: 10, + previousSibling: { + type: 'header', + children: [Array], + level: 3, + fromLineNumber: 9, + previousSibling: [Object] + } + } +} + -- { + type: 'text', + children: [], + value: 'CANCELLED envoyer un justificatif médical :ARCHIVE:', + previousSibling: null, + parent: { + type: 'inlineContainer', + children: [ [Circular *1] ], + previousSibling: null, + parent: { + type: 'header', + children: [Array], + level: 4, + fromLineNumber: 10, + previousSibling: [Object] + } + } +} + -- CANCELLED envoyer un justificatif médical :ARCHIVE: +headerTexts [ + 'des choses', + 'TODO faire un truc', + 'TODO faire un autre truc :autre:', + 'SOMEDAY avoir une idée :idea:', + 'CANCELLED envoyer un justificatif médical :ARCHIVE:' +] +le fichier input.org a ce nombre de type de tâches SOMEDAY: 1 - TODO: 3 + TODO: 2 NEXT: undefined - CANCELLED: 2 + CANCELLED: 1 DONE: undefined