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

feat(gatsby-remark-embed-snippet): apply gatsby-remark-prismjs configuration to embedded snippets #13973

Merged
merged 8 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update tests
  • Loading branch information
timhagn committed May 11, 2019
commit 051a966c993553c53ba751f86170212305416917
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Object {
Object {
"children": Array [
Object {
"lang": "css",
"position": Position {
"end": Object {
"column": 24,
Expand All @@ -19,10 +20,8 @@ Object {
"offset": 0,
},
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"language-css\\"><code><span class=\\"token selector\\">html</span> <span class=\\"token punctuation\\">{</span> <span class=\\"token property\\">height</span><span class=\\"token punctuation\\">:</span> 100%<span class=\\"token punctuation\\">;</span> <span class=\\"token punctuation\\">}</span></code></pre>
</div>",
"type": "code",
"value": "html { height: 100%; }",
},
],
"position": Position {
Expand Down Expand Up @@ -63,6 +62,7 @@ Object {
Object {
"children": Array [
Object {
"lang": "html",
"position": Position {
"end": Object {
"column": 25,
Expand All @@ -76,10 +76,8 @@ Object {
"offset": 0,
},
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"language-html\\"><code><span class=\\"token tag\\"><span class=\\"token tag\\"><span class=\\"token punctuation\\">&lt;</span>html</span><span class=\\"token punctuation\\">></span></span><span class=\\"token tag\\"><span class=\\"token tag\\"><span class=\\"token punctuation\\">&lt;/</span>html</span><span class=\\"token punctuation\\">></span></span></code></pre>
</div>",
"type": "code",
"value": "<html></html>",
},
],
"position": Position {
Expand Down Expand Up @@ -120,6 +118,7 @@ Object {
Object {
"children": Array [
Object {
"lang": "jsx",
"position": Position {
"end": Object {
"column": 23,
Expand All @@ -133,10 +132,8 @@ Object {
"offset": 0,
},
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"language-jsx\\"><code><span class=\\"token keyword\\">const</span> foo <span class=\\"token operator\\">=</span> <span class=\\"token string\\">\\"bar\\"</span><span class=\\"token punctuation\\">;</span></code></pre>
</div>",
"type": "code",
"value": "const foo = \\"bar\\";",
},
],
"position": Position {
Expand Down Expand Up @@ -177,6 +174,7 @@ Object {
Object {
"children": Array [
Object {
"lang": "markup",
"position": Position {
"end": Object {
"column": 23,
Expand All @@ -190,10 +188,8 @@ Object {
"offset": 0,
},
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"language-markup\\"><code># Hi</code></pre>
</div>",
"type": "code",
"value": "# Hi",
},
],
"position": Position {
Expand Down Expand Up @@ -234,6 +230,7 @@ Object {
Object {
"children": Array [
Object {
"lang": "yaml",
"position": Position {
"end": Object {
"column": 25,
Expand All @@ -247,10 +244,8 @@ Object {
"offset": 0,
},
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"language-yaml\\"><code><span class=\\"token key atrule\\">name</span><span class=\\"token punctuation\\">:</span> Brian Vaughn</code></pre>
</div>",
"type": "code",
"value": "name: Brian Vaughn",
},
],
"position": Position {
Expand Down Expand Up @@ -291,6 +286,7 @@ Object {
Object {
"children": Array [
Object {
"lang": "bash",
"position": Position {
"end": Object {
"column": 23,
Expand All @@ -304,10 +300,8 @@ Object {
"offset": 0,
},
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"language-bash\\"><code><span class=\\"token function\\">pwd</span></code></pre>
</div>",
"type": "code",
"value": "pwd",
},
],
"position": Position {
Expand Down Expand Up @@ -348,6 +342,7 @@ Object {
Object {
"children": Array [
Object {
"lang": "none",
"position": Position {
"end": Object {
"column": 20,
Expand All @@ -361,10 +356,8 @@ Object {
"offset": 0,
},
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"language-none\\"><code>const foo = \\"bar\\";</code></pre>
</div>",
"type": "code",
"value": "const foo = \\"bar\\";",
},
],
"position": Position {
Expand Down Expand Up @@ -405,6 +398,7 @@ Object {
Object {
"children": Array [
Object {
"lang": "jsx",
"position": Position {
"end": Object {
"column": 23,
Expand All @@ -418,10 +412,8 @@ Object {
"offset": 0,
},
},
"type": "html",
"value": "<div class=\\"gatsby-highlight\\">
<pre class=\\"language-jsx\\"><code><span class=\\"token keyword\\">const</span> foo <span class=\\"token operator\\">=</span> <span class=\\"token string\\">\\"bar\\"</span><span class=\\"token punctuation\\">;</span></code></pre>
</div>",
"type": "code",
"value": "const foo = \\"bar\\";",
},
],
"position": Position {
Expand Down
10 changes: 10 additions & 0 deletions packages/gatsby-remark-embed-snippet/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ describe(`gatsby-remark-embed-snippet`, () => {
)
})

it(`should error if an invalid file path is specified`, () => {
fs.existsSync.mockImplementation(path => path !== `examples/hello-world.js`)

const markdownAST = remark.parse(`\`embed:hello-world.js\``)

expect(() => plugin({ markdownAST }, { directory: `examples` })).toThrow(
`Invalid snippet specified; no such file "examples/hello-world.js"`
)
})

it(`should not modify non-embed inlineCode nodes`, () => {
const markdownAST = remark.parse(`\`console.log("hi")\``)
const transformed = plugin({ markdownAST }, { directory: `examples` })
Expand Down