diff --git a/.eslintignore b/.eslintignore index 376b268e7..aa9501fa1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,6 @@ coverage/**/*.js tests/format/**/*.sol +tests/format/Markdown/Markdown.md tests/format/RespectDefaultOptions/respect-default-options.js tests/config/**/*.js src/prettier-comments/**/*.js diff --git a/.prettierignore b/.prettierignore index d440a14dc..0f5566b60 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,5 @@ coverage/**/*.js tests/format/**/*.sol +tests/format/Markdown/Markdown.md tests/format/RespectDefaultOptions/respect-default-options.js src/prettier-comments/**/*.js diff --git a/src/nodes/SourceUnit.js b/src/nodes/SourceUnit.js index a1665e6ad..ce30aadc7 100644 --- a/src/nodes/SourceUnit.js +++ b/src/nodes/SourceUnit.js @@ -9,7 +9,7 @@ const printPreservingEmptyLines = require('./print-preserving-empty-lines'); const SourceUnit = { print: ({ options, path, print }) => [ printPreservingEmptyLines(path, 'children', options, print), - line + options.parentParser ? '' : line ] }; diff --git a/tests/config/require-standalone.js b/tests/config/require-standalone.js index 3bfc001d1..2023b8b8f 100644 --- a/tests/config/require-standalone.js +++ b/tests/config/require-standalone.js @@ -1,6 +1,7 @@ "use strict"; const prettier = require("prettier/standalone"); +const markdownPlugin = require("prettier/parser-markdown"); const babelPlugin = require("prettier/parser-babel"); const solidityPlugin = require("../../src/index"); @@ -8,7 +9,12 @@ module.exports = { formatWithCursor(input, options) { const $$$options = { ...options, - plugins: [babelPlugin, solidityPlugin, ...(options.plugins || [])], + plugins: [ + babelPlugin, + markdownPlugin, + solidityPlugin, + ...(options.plugins || []), + ], }; return prettier.formatWithCursor(input, $$$options); }, @@ -17,7 +23,12 @@ module.exports = { parse(input, options, massage) { const $$$options = { ...options, - plugins: [babelPlugin, solidityPlugin, ...(options.plugins || [])], + plugins: [ + babelPlugin, + markdownPlugin, + solidityPlugin, + ...(options.plugins || []), + ], }; return prettier.__debug.parse(input, $$$options, massage); }, diff --git a/tests/format/Markdown/Markdown.md b/tests/format/Markdown/Markdown.md new file mode 100644 index 000000000..6ca6e06ac --- /dev/null +++ b/tests/format/Markdown/Markdown.md @@ -0,0 +1,13 @@ +# Embedded Solidity Code + +- original + + +```solidity +import "./Foo.sol"; +``` + +- formatted +```solidity +import "./Foo.sol"; +``` diff --git a/tests/format/Markdown/__snapshots__/jsfmt.spec.js.snap b/tests/format/Markdown/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..3606d2bdc --- /dev/null +++ b/tests/format/Markdown/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,40 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Markdown.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 + | printWidth +=====================================input====================================== +# Embedded Solidity Code + +- original + + +\`\`\`solidity +import "./Foo.sol"; +\`\`\` + +- formatted +\`\`\`solidity +import "./Foo.sol"; +\`\`\` + +=====================================output===================================== +# Embedded Solidity Code + +- original + + +\`\`\`solidity +import "./Foo.sol"; +\`\`\` + +- formatted + +\`\`\`solidity +import "./Foo.sol"; +\`\`\` + +================================================================================ +`; diff --git a/tests/format/Markdown/jsfmt.spec.js b/tests/format/Markdown/jsfmt.spec.js new file mode 100644 index 000000000..fbebb4cf8 --- /dev/null +++ b/tests/format/Markdown/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ['markdown']);