Skip to content

Commit

Permalink
feat: added support for timestamp epoch markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMikhaelson committed Nov 2, 2023
1 parent 526303f commit 379d1ce
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/uiweb/src/lib/components/parsetext/defaultPatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ function renderLinkWithColor(matchingString: string) {
return matchingString;
}

function convertEpochToHumanReadable(matchingString: string) {
const match = matchingString.match(/\[ts: (\d+)\]/);
if (match) {
const epochTimestamp = parseInt(match[1], 10); // Extracting the epoch timestamp
const humanReadableDate = new Date(epochTimestamp * 1000).toLocaleString();
return humanReadableDate;
}
return matchingString;
}



// -------- Define the required colors
const COLORS = {
Expand Down Expand Up @@ -314,6 +325,11 @@ const DEFAULT_PATTERNS:CustomParseShape[] = [
},
renderText: renderStyles
},
{
pattern: /\[ts: (\d+)\]/g, // Match [ts: timestamp_in_epoch]
style: {},
renderText: convertEpochToHumanReadable,
},
{
pattern: /\[(w):([^\]]+)\]/i, // white
style: styles.white,
Expand Down

0 comments on commit 379d1ce

Please sign in to comment.