diff --git a/src/commands/interface-manager/DeadDocument.ts b/src/commands/interface-manager/DeadDocument.ts index dc3f9780..5018b089 100644 --- a/src/commands/interface-manager/DeadDocument.ts +++ b/src/commands/interface-manager/DeadDocument.ts @@ -35,7 +35,8 @@ export enum NodeTag { Paragraph = 'p', HeadingOne = 'h1', UnorderedList = 'ul', - ListItem = 'li' + ListItem = 'li', + LineBreak = 'br', } /** diff --git a/src/commands/interface-manager/DeadDocumentHtml.ts b/src/commands/interface-manager/DeadDocumentHtml.ts index 4dcbabbc..ff6201a5 100644 --- a/src/commands/interface-manager/DeadDocumentHtml.ts +++ b/src/commands/interface-manager/DeadDocumentHtml.ts @@ -4,7 +4,7 @@ */ import { FringeLeafRenderFunction, FringeType, LeafNode, NodeTag, SimpleFringeRenderer } from "./DeadDocument"; -import { staticString, TransactionalOutputContext } from "./DeadDocumentMarkdown"; +import { blank, staticString, TransactionalOutputContext } from "./DeadDocumentMarkdown"; export const HTML_RENDERER = new SimpleFringeRenderer(); @@ -38,4 +38,7 @@ HTML_RENDERER.registerRenderer'), staticString('') +).registerInnerNode(NodeTag.LineBreak, + blank, + staticString('
'), ); diff --git a/src/commands/interface-manager/DeadDocumentMarkdown.ts b/src/commands/interface-manager/DeadDocumentMarkdown.ts index 0f7a8a01..f4c6e47b 100644 --- a/src/commands/interface-manager/DeadDocumentMarkdown.ts +++ b/src/commands/interface-manager/DeadDocumentMarkdown.ts @@ -3,7 +3,7 @@ * All rights reserved. */ -import { DocumentNode, FringeInnerRenderFunction, FringeLeafRenderFunction, FringeType, LeafNode, NodeTag, SimpleFringeRenderer, TagDynamicEnvironment, TagDynamicEnvironmentEntry } from "./DeadDocument"; +import { DocumentNode, FringeInnerRenderFunction, FringeLeafRenderFunction, FringeType, LeafNode, NodeTag, SimpleFringeRenderer, TagDynamicEnvironment } from "./DeadDocument"; /** * Ideally this would call a callback when a page is ready @@ -47,8 +47,10 @@ export class PagedDuplexStream { * Creates a new page from the previously committed text * @returns A page with all committed text. */ - public forceNewPage(): void { - this.pages.push(''); + public ensureNewPage(): void { + if (this.currentPage.length !== 0) { + this.pages.push(''); + } } /** @@ -65,7 +67,7 @@ export class PagedDuplexStream { if (this.currentPage.length === 0 && (this.buffer.length > this.sizeLimit)) { throw new TypeError('Commit is too large, could not write a page for this commit'); } - this.forceNewPage(); + this.ensureNewPage(); this.appendToCurrentPage(this.buffer); this.lastCommittedNode = node; } else { @@ -158,4 +160,7 @@ MARKDOWN_RENDERER.registerRenderer o.peekPage()); - if (outputsWithNewPage.length !== 0) { + if (outputs.some(o => o.peekPage())) { // Ensure each stream has the same nodes in the new page. - for (const output of outputs) { - if (!outputsWithNewPage.includes(output)) { - output.forceNewPage(); - } - } + // I'm really worried that somehow a stream can have a page waiting + // while also having buffered output? so when it is ensured, that output is appended? + // that means there's an implementation issue in the walker's though. + outputs.forEach(o => o.ensureNewPage()); // Send the new pages as an event. await cb(markdownOutput.readPage()!, htmlOutput.readPage()!); } @@ -56,3 +55,15 @@ export async function renderMatrix(node: DocumentNode, cb: SendMatrixEventCB) { checkEqual(currentHtmlNode, currentMarkdownNode); } } + +export async function renderMatrixAndSend(node: DocumentNode, roomId: string, event: any, client: MatrixSendClient): Promise { + // We desperatley need support for threads to make this work in a non-shit way. + await renderMatrix(node, async (text: string, html: string) => { + await client.sendMessage(roomId, { + msgtype: "m.notice", + body: text, + format: "org.matrix.custom.html", + formatted_body: html, + }); + }); +} \ No newline at end of file diff --git a/src/commands/interface-manager/JSXFactory.ts b/src/commands/interface-manager/JSXFactory.ts index 49427953..e9a36743 100644 --- a/src/commands/interface-manager/JSXFactory.ts +++ b/src/commands/interface-manager/JSXFactory.ts @@ -5,7 +5,13 @@ import { DocumentNode, LeafNode, makeDocumentNode, makeLeafNode, NodeTag, TextNode } from "./DeadDocument"; - +declare global { + namespace JSX { + interface IntrinsicElements { + [elemName: string]: any; + } + } +} export function JSXFactory(tag: NodeTag, properties: any, ...rawChildren: (DocumentNode|LeafNode|string)[]) { const node = makeDocumentNode(tag); @@ -20,3 +26,11 @@ export function JSXFactory(tag: NodeTag, properties: any, ...rawChildren: (Docum rawChildren.forEach(ensureChild); return node; } + + +namespace JSXFactory { + export interface IntrinsicElements { + [elemName: string]: any; + } +} +