Skip to content

Commit

Permalink
Fixed import
Browse files Browse the repository at this point in the history
  • Loading branch information
siefkenj committed Jul 10, 2024
1 parent f0ff48f commit 8d6d435
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
_dastReducerActions,
flatDastSelector,
} from "../../state/redux-slices/dast";
import { doenetToPretext } from "@doenet/lsp-tools";
import { toXml } from "xast-util-to-xml";
import { _globalReducerActions } from "../../state/redux-slices/global";
import { renderToPretext } from "../../utils/pretext/render-to-pretext";
Expand All @@ -16,7 +15,6 @@ export function DownloadPretextDropdownItem() {
<DropdownItem
onClick={() => {
console.log(flatDast);
console.log(toXml(doenetToPretext(flatDast)));
console.log(renderToPretext(flatDast));
}}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import { BasicComponentWithPassthroughChildren } from "../types";
import { _PassThroughWithTag } from "./_pass-through-with-tag";

/**
* Same as `_PassThroughWithTag` except inserts newlines before and after the children.
*/
export const _PassThroughWithTagAndNewline: BasicComponentWithPassthroughChildren<{}> =
({ children, ...rest }) => {
return (
<_PassThroughWithTag {...rest}>
{"\n"}
{children}
{"\n"}
</_PassThroughWithTag>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export const Division: BasicComponentWithPassthroughChildren<{

const title =
titleElmId != null ? (
<Element id={titleElmId} ancestors={ancestors} />
// We put a newline before a title just to make the formatting of the document look a little better
<React.Fragment>
{"\n "}
<Element id={titleElmId} ancestors={ancestors} />
</React.Fragment>
) : (
""
);
Expand Down
1 change: 1 addition & 0 deletions packages/doenetml-prototype/src/renderers/pretext/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from "./ul";
export * from "./li";
export * from "./choice-input";
export * from "./_pass-through-with-tag";
export * from "./_pass-through-with-tag-and-newline";
6 changes: 3 additions & 3 deletions packages/doenetml-prototype/src/renderers/renderers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ export const PRETEXT_TEXT_MODE_COMPONENTS: RendererObject = {

// For PreTeXt compatibility
pretext: {
component: PretextComponent._PassThroughWithTag,
component: PretextComponent._PassThroughWithTagAndNewline,
passthroughChildren: true,
},
article: {
component: PretextComponent._PassThroughWithTag,
component: PretextComponent._PassThroughWithTagAndNewline,
passthroughChildren: true,
},
book: {
component: PretextComponent._PassThroughWithTag,
component: PretextComponent._PassThroughWithTagAndNewline,
passthroughChildren: true,
},
};
Expand Down
33 changes: 26 additions & 7 deletions packages/doenetml-prototype/test/pretext-export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ describe("Pretext export", async () => {
it("Wraps root in <pretext> tag", () => {
const flatDast = structuredClone(SIMPLE_FLAT_DAST);
expect(renderToPretext(flatDast)).toMatchInlineSnapshot(`
"<pretext><article><p>
"<pretext>
<article>
<p>
Hi
</p></article></pretext>"
</p>
</article>
</pretext>"
`);
});
it("passes through attributes", async () => {
Expand All @@ -75,7 +79,13 @@ describe("Pretext export", async () => {

const pretext = renderToPretext(flatDast);
expect(pretext).toMatchInlineSnapshot(
`"<pretext><article><p>How about</p></article></pretext>"`,
`
"<pretext>
<article>
<p>How about</p>
</article>
</pretext>"
`,
);
});
it("expands <text> to pretext element", async () => {
Expand All @@ -86,8 +96,12 @@ describe("Pretext export", async () => {

const pretext = renderToPretext(flatDast);
expect(pretext).toMatchInlineSnapshot(`
"<pretext><article><em>foo</em>
<p>How about foo?</p></article></pretext>"
"<pretext>
<article>
<em>foo</em>
<p>How about foo?</p>
</article>
</pretext>"
`);
});
it("expands <division> to pretext element", async () => {
Expand All @@ -100,10 +114,15 @@ describe("Pretext export", async () => {

const pretext = renderToPretext(flatDast);
expect(pretext).toMatchInlineSnapshot(`
"<pretext><article><section><title>Foo</title>
"<pretext>
<article>
<section>
<title>Foo</title>
<p>How about foo?</p>
</section></article></pretext>"
</section>
</article>
</pretext>"
`);
});
});

0 comments on commit 8d6d435

Please sign in to comment.