Skip to content

Commit

Permalink
Fix replacement issue with dollar signs.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondfrancis committed Aug 23, 2021
1 parent 47bf4b8 commit 851db56
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@torchlight-api/torchlight-cli",
"version": "0.0.7",
"version": "0.0.8",
"description": "A CLI for Torchlight - the syntax highlighting API",
"main": "index.js",
"scripts": {
Expand All @@ -14,6 +14,11 @@
"highlighting",
"torchlight"
],
"standard": {
"ignore": [
"tests"
]
},
"author": "Aaron Francis <[email protected]> (https://torchlight.dev)",
"license": "MIT",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (torchlight, options) {
***************************************
* Torchlight is watching files... *
***************************************
`)
`)
}

const input = path.resolve(options.input)
Expand Down Expand Up @@ -142,7 +142,7 @@ function highlight (torchlight, source) {
}

Object.keys(swap).forEach(key => {
highlighted = highlighted.replace(key, swap[key])
highlighted = highlighted.replace(key, () => swap[key])
})
})

Expand Down
17 changes: 17 additions & 0 deletions tests/__snapshots__/highlight.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ exports[`decipher-language.html -------- it deciphers languages based on attribu
<pre data-custom=\\"foobar\\" class=\\"torchlight\\" style=\\"\\" data-torchlight-processed=\\"3449c9e5e332f1dbb81505cd739fbf3f\\"><code><div class=\\"line\\">foobar</div><textarea data-torchlight-original=\\"true\\" style=\\"display: none !important;\\">foobar</textarea></code></pre>"
`;
exports[`keygen.html ------------------- fixes zekes issue: keygen.html keygen.html ------------------- fixes zekes issue 1`] = `
"<pre data-lang=\\"csharp\\" class=\\"torchlight\\" style=\\"\\" data-torchlight-processed=\\"3449c9e5e332f1dbb81505cd739fbf3f\\"><code><div class=\\"line\\">using RestSharp;</div><div class=\\"line\\">using System;</div><div class=\\"line\\">using System.Text;</div><div class=\\"line\\"></div><div class=\\"line\\">var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(&quot;{EMAIL}:{PASSWORD}&quot;));</div><div class=\\"line\\"></div><div class=\\"line\\">var client = new RestClient(&quot;https://api.keygen.sh/v1/accounts/{ACCOUNT}&quot;);</div><div class=\\"line\\">var request = new RestRequest(&quot;tokens&quot;, Method.POST);</div><div class=\\"line\\"></div><div class=\\"line\\">request.AddHeader(&quot;Accept&quot;, &quot;application/vnd.api+json&quot;);</div><div class=\\"line\\">request.AddHeader(&quot;Authorization&quot;, $&quot;Basic {credentials}&quot;);</div><div class=\\"line\\"></div><div class=\\"line\\">var response = client.Execute(request);</div><textarea data-torchlight-original=\\"true\\" style=\\"display: none !important;\\">using RestSharp;
using System;
using System.Text;
var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(\\"{EMAIL}:{PASSWORD}\\"));
var client = new RestClient(\\"https://api.keygen.sh/v1/accounts/{ACCOUNT}\\");
var request = new RestRequest(\\"tokens\\", Method.POST);
request.AddHeader(\\"Accept\\", \\"application/vnd.api+json\\");
request.AddHeader(\\"Authorization\\", $\\"Basic {credentials}\\");
var response = client.Execute(request);</textarea></code></pre>
"
`;
exports[`multiple-blocks.html ---------- three blocks in one pre tag: multiple-blocks.html multiple-blocks.html ---------- three blocks in one pre tag 1`] = `
"<pre class=\\"torchlight torchlight torchlight\\" style=\\" \\" data-torchlight-processed=\\"3449c9e5e332f1dbb81505cd739fbf3f\\"><code data-lang=\\"php\\"><div class=\\"line\\">php</div><textarea data-torchlight-original=\\"true\\" style=\\"display: none !important;\\">php</textarea></code><code data-lang=\\"html\\"><div class=\\"line\\">html</div><textarea data-torchlight-original=\\"true\\" style=\\"display: none !important;\\">html</textarea></code><code data-lang=\\"js\\"><div class=\\"line\\">js</div><textarea data-torchlight-original=\\"true\\" style=\\"display: none !important;\\">js</textarea></code></pre>
"
Expand Down
13 changes: 13 additions & 0 deletions tests/fixtures/keygen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<pre data-lang="csharp"><code>using RestSharp;
using System;
using System.Text;

var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes("{EMAIL}:{PASSWORD}"));

var client = new RestClient("https://api.keygen.sh/v1/accounts/{ACCOUNT}");
var request = new RestRequest("tokens", Method.POST);

request.AddHeader("Accept", "application/vnd.api+json");
request.AddHeader("Authorization", $"Basic {credentials}");

var response = client.Execute(request);</code></pre>
4 changes: 3 additions & 1 deletion tests/highlight.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ beforeEach(() => {
torchlight.initialized = false
})

fixture('keygen: fixes zekes issue')

fixture('multiple-blocks: three blocks in one pre tag', () => {
const mock = mockApi(data => {
expect(data.blocks).toHaveLength(3)
Expand Down Expand Up @@ -91,4 +93,4 @@ fixture('decipher-language: it deciphers languages based on attributes', () => {
})

return () => expect(mock).toHaveBeenCalledTimes(1)
})
})
7 changes: 7 additions & 0 deletions tests/support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ function fixture (file, callback, options = {}) {

description = `${path} ${dashes} ${description.trim()}`

// If there was no callback, it's just a snapshot test.
callback = callback ?? function () {
const mock = mockApi(() => [])

return () => expect(mock).toHaveBeenCalledTimes(1)
}

test(description, done => {
const after = callback()

Expand Down

0 comments on commit 851db56

Please sign in to comment.