From 85e0385c0907f95d1f8f720d3f323fd325b87a6d Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Fri, 5 Jul 2019 16:49:38 +0100 Subject: [PATCH 1/2] Don't collapse one of code --- collapse-test.md | 33 +++++++++++++++++++++++++++++++++ index.js | 9 ++++++--- test.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 collapse-test.md diff --git a/collapse-test.md b/collapse-test.md new file mode 100644 index 0000000..cc64b9c --- /dev/null +++ b/collapse-test.md @@ -0,0 +1,33 @@ +Instead of connecting to a real backend API or web service, we’ll use [can-fixture fixtures] +to “mock” an API. Whenever an [AJAX](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) +request is made, the fixture will “capture” the request and instead respond with mock data. + +> **Note:** if you open your browser’s Network panel, you will *not* see any network requests. +> You can see the fixture requests and responses in your browser’s Console panel. + +How fixtures work is outside the scope of this tutorial and not necessary to understand to continue, +but you can learn more in the [can-fixture] documentation. + +## Defining a custom element with CanJS + +We mentioned above that CanJS helps you define custom elements. We call these [can-component components]. + +Add the following to the **JS** tab in your CodePen: + +```js +// Creates a mock backend with 3 todos +import { todoFixture } from "//unpkg.com/can-demo-models@5"; +todoFixture(3); + +import { Component } from "//unpkg.com/can@5/core.mjs"; + +Component.extend({ + tag: "todos-app", + view: ` +

Today’s to-dos

+ `, + ViewModel: { + } +}); +``` + \ No newline at end of file diff --git a/index.js b/index.js index 3911622..e57bccb 100644 --- a/index.js +++ b/index.js @@ -66,11 +66,14 @@ var getConfig = function(lineString, lineCount) { return typeof val === 'number' && !isNaN(val); }) ; - + if (range[0] > current + padding) { - collapse.push(current + '-' + (range[0] - 1 - padding)); + var collapseEnd = (range[0] - 1 - padding); + if (collapseEnd !== current) { + collapse.push(current + '-' + collapseEnd); + } } - + current = (range[1] || range[0]) + padding + 1; } diff --git a/test.js b/test.js index 0a6ff2f..a5480d8 100644 --- a/test.js +++ b/test.js @@ -58,4 +58,38 @@ describe("bit-docs-html-highlight-line", function() { }, done); }, done); }); + + it("dosen't show expand button for one line code", function(done) { + this.timeout(60000); + + var docMap = Promise.resolve({ + index: { + name: "index", + demo: "path/to/demo.html", + body: fs.readFileSync(__dirname+"/collapse-test.md", "utf8") + } + }); + + generate(docMap, { + html: { + dependencies: { + "bit-docs-html-highlight-line": __dirname + } + }, + dest: path.join(__dirname, "temp"), + parent: "index", + forceBuild: true, + debug: true, + minifyBuild: false + }).then(function() { + open("index.html",function(browser, close) { + var doc = browser.window.document; + var collapseCodes = doc.querySelectorAll('pre[data-collapse] code'); + assert.equal(collapseCodes.length, 0); + close(); + done(); + }, done); + }, done) + + }); }); From 0167dccf3a5472e24ef9b9294571ecf0c0cfe202 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Fri, 5 Jul 2019 17:12:32 +0100 Subject: [PATCH 2/2] Upgrade bit-docs-generate-html to prevent primordials error --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 87f6292..4bf6dd3 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "prismjs": "^1.11.0" }, "devDependencies": { - "bit-docs-generate-html": "^0.1.0", + "bit-docs-generate-html": "^0.15.0", "connect": "^2.14.4", "mocha": "^2.5.3", "zombie": "^4.3.0"