Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove double snippet from formatted snippets #108

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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