Skip to content

Commit baf16e6

Browse files
committed
only apply split view for docs
1 parent 1c0b4e9 commit baf16e6

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

src/format/split_view.test.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import unified from "unified";
55
import markdown from "remark-parse";
66
import rehype from "remark-rehype";
77
import stringify from "rehype-stringify";
8+
import vFile from "vfile";
89

910
import { highight_code_block } from "./highlight";
1011
import { split_view } from "./split_view";
1112

1213
import u from "unist-builder";
14+
import { custom_vfile } from "./types";
1315

1416
const { process } = unified()
1517
.use(markdown)
@@ -48,7 +50,9 @@ console.log('boo')
4850
\`\`\`
4951
`;
5052

51-
const output = await process(src);
53+
const output = await process(
54+
vFile<custom_vfile>({ contents: src, data: { docs_type: "docs" } })
55+
);
5256

5357
assert.equal(
5458
output.contents,
@@ -60,7 +64,7 @@ console.log('boo')
6064
);
6165
});
6266

63-
split("wraps from hr to end of code block in split view markup", async () => {
67+
split("works with other content present", async () => {
6468
const src = `
6569
### hello
6670
@@ -77,8 +81,9 @@ console.log('boo')
7781
## hello
7882
`;
7983

80-
const output = await process(src);
81-
84+
const output = await process(
85+
vFile<custom_vfile>({ contents: src, data: { docs_type: "docs" } })
86+
);
8287
assert.equal(
8388
output.contents,
8489
"<h3>hello</h3>\n" +
@@ -89,4 +94,37 @@ console.log('boo')
8994
"<h2>hello</h2>"
9095
);
9196
});
97+
98+
split("ignore non-docs content", async () => {
99+
const src = `
100+
### hello
101+
102+
___
103+
104+
this is more text
105+
106+
and this
107+
108+
\`\`\`js
109+
console.log('boo')
110+
\`\`\`
111+
112+
## hello
113+
`;
114+
115+
const output = await process(
116+
vFile<custom_vfile>({ contents: src, data: { docs_type: "blof" } })
117+
);
118+
assert.equal(
119+
output.contents,
120+
121+
"<h3>hello</h3>\n" +
122+
"<hr>\n" +
123+
"<p>this is more text</p>\n" +
124+
"<p>and this</p>\n" +
125+
`<pre class='language-javascript'><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'boo'</span><span class="token punctuation">)</span></code></pre>\n` +
126+
"<h2>hello</h2>"
127+
);
128+
});
129+
92130
split.run();

src/format/split_view.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { Transformer } from "unified";
22
import type { Parent } from "unist";
3-
3+
import { custom_vfile } from "./types";
44
import visit from "unist-util-visit";
55

66
export function split_view(): Transformer {
7-
return function (tree) {
7+
return function (tree, vFile: custom_vfile) {
8+
if (vFile.data.docs_type !== "docs") return;
9+
810
visit(tree, "element", (node, i, parent) => {
911
if (node.tagName === "hr") {
1012
const left: Parent = {

src/format/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ export type custom_vfile = VFile & {
1111
dir: string;
1212
slugs: string[];
1313
seen_slugs: Map<string, number>;
14+
docs_type: "docs" | "faq" | "migrating" | "examples" | "tutorials" | "blog";
15+
file_type: "readme" | "other";
1416
};
1517
};

0 commit comments

Comments
 (0)