Skip to content

Commit ea6b99a

Browse files
Fix beehiiv heading conversion (#110)
- Beehiiv expects real heading tags with anchor metadata instead of paragraphs containing bold text for headings. - The previous conversion produced `<p><strong>…</strong></p>` for `#`/`##`/... headings, which did not match Beehiiv rich media output. ### Description - Update `vscode-to-beehiiv.html` to emit actual heading tags (`<h1>`–`<h6>`) instead of paragraph wrappers for markdown headings. - Add `HEADING_STYLE` derived from `BLOCK_STYLE` and set Beehiiv-specific attributes on headings: `data-id`, `id`, `data-anchor`, `data-anchor-title`, `data-anchor-id`, `data-anchor-title-sync`, and `data-anchor-id-sync`. - Preserve heading content with `innerHTML` and set `data-pm-slice="1 1 []"` on the first block to match Beehiiv slice behavior. - Keep existing handling for paragraphs, lists, code blocks, and link attributes unchanged. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69651f115954832595089d77a600fc86)
1 parent 87c511e commit ea6b99a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

vscode-to-beehiiv.html

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ <h2>Beehiiv output</h2>
119119
const status = document.getElementById('status');
120120

121121
const BLOCK_STYLE = 'font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);';
122+
const HEADING_STYLE = BLOCK_STYLE.replace('font-weight: 400; ', '');
122123

123124
const updateStatus = (message) => {
124125
status.textContent = message;
@@ -211,11 +212,22 @@ <h2>Beehiiv output</h2>
211212
}
212213

213214
if (node.tagName.startsWith('H')) {
214-
const headingParagraph = document.createElement('p');
215-
headingParagraph.setAttribute('data-id', crypto.randomUUID());
216-
headingParagraph.setAttribute('style', BLOCK_STYLE);
217-
headingParagraph.innerHTML = `<strong>${node.textContent}</strong>`;
218-
blocks.push(headingParagraph.outerHTML);
215+
const level = Number.parseInt(node.tagName.replace('H', ''), 10);
216+
const heading = document.createElement(node.tagName.toLowerCase());
217+
const headingId = `h-${level}`;
218+
heading.setAttribute('data-id', crypto.randomUUID());
219+
heading.setAttribute('id', headingId);
220+
heading.setAttribute('data-anchor', '');
221+
heading.setAttribute('data-anchor-title', node.textContent);
222+
heading.setAttribute('data-anchor-id', headingId);
223+
heading.setAttribute('data-anchor-title-sync', 'true');
224+
heading.setAttribute('data-anchor-id-sync', 'true');
225+
heading.setAttribute('style', HEADING_STYLE);
226+
if (blocks.length === 0) {
227+
heading.setAttribute('data-pm-slice', '1 1 []');
228+
}
229+
heading.innerHTML = node.innerHTML;
230+
blocks.push(heading.outerHTML);
219231
}
220232
});
221233

0 commit comments

Comments
 (0)