Skip to content

Commit

Permalink
Remove double snippet from formatted snippets (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbush authored May 20, 2022
1 parent c57a6a4 commit e854e19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/docs/reference/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ bluehawk snip Main.java -o . --format=rst

Produces the following output:

`Main.snippet.modulo.java.snippet.rst`:
`Main.snippet.modulo.java.rst`:

```rst
.. code-block:: java
Expand Down
30 changes: 12 additions & 18 deletions src/bluehawk/actions/snip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ describe("snip", () => {
const outputList = await System.fs.readdir(outputPath);
expect(outputList).toStrictEqual([
"test.snippet.foo.js",
"test.snippet.foo.js.snippet.md",
"test.snippet.foo.js.snippet.rst",
"test.snippet.foo.js.md",
"test.snippet.foo.js.rst",
]);

const rstFileContents = await System.fs.readFile(
Path.join(outputPath, "test.snippet.foo.js.snippet.rst"),
Path.join(outputPath, "test.snippet.foo.js.rst"),
"utf8"
);
expect(rstFileContents).toStrictEqual(`.. code-block:: javascript
Expand All @@ -73,7 +73,7 @@ describe("snip", () => {
`);

const mdFileContents = await System.fs.readFile(
Path.join(outputPath, "test.snippet.foo.js.snippet.md"),
Path.join(outputPath, "test.snippet.foo.js.md"),
"utf8"
);
expect(mdFileContents).toStrictEqual(`const bar = "foo"
Expand Down Expand Up @@ -215,11 +215,11 @@ console.log(bar);
const outputList = await System.fs.readdir(outputPath);
expect(outputList).toStrictEqual([
"test.snippet.foo.js",
"test.snippet.foo.js.snippet.md",
"test.snippet.foo.js.md",
]);

const fileContents = await System.fs.readFile(
Path.join(outputPath, "test.snippet.foo.js.snippet.md"),
Path.join(outputPath, "test.snippet.foo.js.md"),
"utf8"
);
expect(fileContents).toStrictEqual(`// highlight-start
Expand Down Expand Up @@ -281,11 +281,11 @@ line 9
const outputList = await System.fs.readdir(outputPath);
expect(outputList).toStrictEqual([
"test.snippet.foo.js",
"test.snippet.foo.js.snippet.rst",
"test.snippet.foo.js.rst",
]);

const fileContents = await System.fs.readFile(
Path.join(outputPath, "test.snippet.foo.js.snippet.rst"),
Path.join(outputPath, "test.snippet.foo.js.rst"),
"utf8"
);
expect(fileContents).toStrictEqual(`.. code-block:: javascript
Expand Down Expand Up @@ -350,11 +350,11 @@ line 9
const outputList = await System.fs.readdir(outputPath);
expect(outputList).toStrictEqual([
"test.snippet.foo.js",
"test.snippet.foo.js.snippet.md",
"test.snippet.foo.js.md",
]);

const fileContents = await System.fs.readFile(
Path.join(outputPath, "test.snippet.foo.js.snippet.md"),
Path.join(outputPath, "test.snippet.foo.js.md"),
"utf8"
);
expect(fileContents).toStrictEqual(`line 1
Expand Down Expand Up @@ -512,10 +512,7 @@ struct ContentView: SwiftUI.App {
);
// Now check states for rst version
fileContentsSync = await System.fs.readFile(
Path.join(
outputPathSync,
"test.snippet.content-view.swift.snippet.rst"
),
Path.join(outputPathSync, "test.snippet.content-view.swift.rst"),
"utf8"
);
expect(fileContentsSync).toStrictEqual(
Expand All @@ -540,10 +537,7 @@ struct ContentView: SwiftUI.App {
);

const fileContentsLocal = await System.fs.readFile(
Path.join(
outputPathLocal,
"test.snippet.content-view.swift.snippet.rst"
),
Path.join(outputPathLocal, "test.snippet.content-view.swift.rst"),
"utf8"
);
// TODO: Expect this not to emphasize lines, since the :emphasize: tag was
Expand Down
4 changes: 2 additions & 2 deletions src/bluehawk/actions/snip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createFormattedCodeBlock = async ({
const formattedSnippet = await formatInRst(result);

const { document } = result;
const targetPath = path.join(output, `${document.basename}.snippet.rst`);
const targetPath = path.join(output, `${document.basename}.rst`);
await System.fs.writeFile(targetPath, formattedSnippet, "utf8");

reporter.onFileWritten({
Expand All @@ -44,7 +44,7 @@ export const createFormattedCodeBlock = async ({
const formattedSnippet = await formatInDocusaurus(result);

const { document } = result;
const targetPath = path.join(output, `${document.basename}.snippet.md`);
const targetPath = path.join(output, `${document.basename}.md`);
await System.fs.writeFile(targetPath, formattedSnippet, "utf8");
reporter.onFileWritten({
type: "text",
Expand Down

0 comments on commit e854e19

Please sign in to comment.