Browse Source

Handle discrete headings

master
Silberengel 11 months ago
parent
commit
d62c424a10
  1. 28
      src/lib/components/Preview.svelte
  2. 15
      src/lib/parser.ts

28
src/lib/components/Preview.svelte

@ -150,6 +150,33 @@ @@ -150,6 +150,33 @@
</script>
{#snippet sectionHeading(title: string, depth: number)}
{#if $pharosInstance.isFloatingTitle(rootId)}
{#if depth === 0}
<h1 class='discrete'>
{title}
</h1>
{:else if depth === 1}
<h2 class='discrete'>
{title}
</h2>
{:else if depth === 2}
<h3 class='discrete'>
{title}
</h3>
{:else if depth === 3}
<h4 class='discrete'>
{title}
</h4>
{:else if depth === 4}
<h5 class='discrete'>
{title}
</h5>
{:else}
<h6 class='discrete'>
{title}
</h6>
{/if}
{:else}
{#if depth === 0}
<h1 class='h-leather'>
{title}
@ -175,6 +202,7 @@ @@ -175,6 +202,7 @@
{title}
</h6>
{/if}
{/if}
{/snippet}
{#snippet contentParagraph(content: string, publicationType: string)}

15
src/lib/parser.ts

@ -270,6 +270,21 @@ export default class Pharos { @@ -270,6 +270,21 @@ export default class Pharos {
return block.convert();
}
/**
* Checks if the node with the given ID is a floating title (discrete header).
* @param id The ID of the node to check.
* @returns True if the node is a floating title, false otherwise.
*/
isFloatingTitle(id: string): boolean {
const normalizedId = this.normalizeId(id);
if (!normalizedId || !this.nodes.has(normalizedId)) {
return false;
}
const context = this.eventToContextMap.get(normalizedId);
return context === 'floating_title';
}
/**
* Updates the `content` field of a Nostr event in-place.
* @param dTag The d tag of the event to update.

Loading…
Cancel
Save