From 739e51326fd3815ccb0147d10a924493cd3fef63 Mon Sep 17 00:00:00 2001 From: artel-ksikora <55102559+artel-ksikora@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:11:11 +0200 Subject: [PATCH] feat: add tag display to Segment (#43) * feat: add tag display to Segment * feat: Fragment markdown rework * feat: Fragment markdown rework * fixL prettifer remove * fix: remove prettifer ignore --- src/tracker.ts | 24 +++++++++++++++++++++++- test-vault/test-markdown.md | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test-vault/test-markdown.md diff --git a/src/tracker.ts b/src/tracker.ts index 4d93614..6496880 100644 --- a/src/tracker.ts +++ b/src/tracker.ts @@ -1,4 +1,4 @@ -import {moment, App, MarkdownSectionInformation, ButtonComponent, TextComponent, TFile} from "obsidian"; +import {moment, App, MarkdownSectionInformation, ButtonComponent, TextComponent, TFile, MarkdownRenderer} from "obsidian"; import {SimpleTimeTrackerSettings} from "./settings"; export interface Tracker { @@ -380,6 +380,8 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle row.createEl("td", {text: entry.endTime || entry.subEntries ? formatDuration(getDuration(entry), settings) : ""}); + renderSegments(row, file); + let entryButtons = row.createEl("td"); entryButtons.addClass("simple-time-tracker-table-buttons"); new ButtonComponent(entryButtons) @@ -405,6 +407,8 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle entry.endTime = endField.getTimestamp(); await saveTracker(tracker, this.app, file, getSectionInfo()); editButton.setIcon("lucide-pencil"); + + renderSegments(row, file); } else { nameField.beginEdit(entry.name); // only allow editing start and end times if we don't have sub entries @@ -430,3 +434,21 @@ function addEditableTableRow(tracker: Tracker, entry: Entry, table: HTMLTableEle addEditableTableRow(tracker, sub, table, newSegmentNameBox, trackerRunning, file, getSectionInfo, settings, indent + 1); } } + +/** + * Render Segment as Markdown + * @param row - Html row in table + * @param path - Path to file with time tracker + */ +function renderSegments(row: any, path: string) { + // Get coluumn with Segment + const segment = row.querySelector("td:first-child span"); + if (segment) { + const htmlData = segment.innerHTML; + // Render Markdown + // Result `

_rendered_html_

` + MarkdownRenderer.renderMarkdown(htmlData, segment as HTMLElement, path, this); + // Replace current segment by rendered version + segment.innerHTML = segment.querySelector("p").innerHTML; + } +} diff --git a/test-vault/test-markdown.md b/test-vault/test-markdown.md new file mode 100644 index 0000000..ca37478 --- /dev/null +++ b/test-vault/test-markdown.md @@ -0,0 +1,4 @@ +Tested for #tag, *italic*, [link](test2), etc: +```simple-time-tracker +{"entries":[{"name":"`Segment 1`","startTime":"2022-09-27T19:51:18.000Z","endTime":"2022-09-27T19:51:24.000Z"},{"name":"Segment 2","startTime":"2022-09-27T19:51:25.000Z","endTime":"2022-09-27T19:51:26.000Z"},{"name":"#tag Seqment 3 *add* #tag1 text","startTime":null,"endTime":null,"subEntries":[{"name":"Part 1 #tagp1","startTime":"2024-03-17T11:16:00.382Z","endTime":"2024-03-17T11:16:15.966Z","subEntries":null},{"name":"Part 3","startTime":"2024-03-17T11:17:08.000Z","endTime":"2024-03-17T11:17:24.000Z","subEntries":null}]},{"name":"#tag3 Segment 4","startTime":null,"endTime":null,"subEntries":[{"name":"Part 1 #tag4","startTime":"2024-03-17T12:22:04.000Z","endTime":"2024-03-17T12:22:16.000Z","subEntries":null},{"name":"#tag5 Part 2 *italic*","startTime":"2024-03-17T12:22:20.000Z","endTime":"2024-03-17T12:22:24.000Z","subEntries":null}]},{"name":"*italic* Segment 5 #tag6 [test2](test2)","startTime":"2024-03-17T12:40:37.000Z","endTime":"2024-03-17T12:40:45.000Z","subEntries":null}]} +```