Skip to content

Commit ce60649

Browse files
authored
[feature] be able to render tables from markdown (#469)
* [feature] be able to render tables from markdown * merged highlight-code-test into compile-markdown-test and adds tests to ensure table is being rendered correctly * fix failing test
1 parent 5339b68 commit ce60649

File tree

9 files changed

+115
-30
lines changed

9 files changed

+115
-30
lines changed

addon/styles/addon.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ h3 > a:before {
105105
width: 0em;
106106
margin-left: -0.9em;
107107
}
108+
109+
table {
110+
width: 100%;
111+
}

addon/styles/tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ module.exports = {
797797
position: ['responsive'],
798798
inset: ['responsive'],
799799
resize: ['responsive'],
800+
tableLayout: ['responsive', 'hover', 'focus'],
800801
boxShadow: ['responsive', 'hover'],
801802
fill: [],
802803
stroke: [],

addon/utils/compile-markdown.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,29 @@ class HBSRenderer extends marked.Renderer {
208208
`;
209209
}
210210

211+
table(header, body) {
212+
if (body) body = '<tbody>' + body + '</tbody>';
213+
214+
return '<table class="docs-table-auto">\n'
215+
+ '<thead>\n'
216+
+ header
217+
+ '</thead>\n'
218+
+ body
219+
+ '</table>\n';
220+
}
221+
222+
tablerow(content) {
223+
return '<tr class="docs-table-row">\n' + content + '</tr>\n';
224+
}
225+
226+
tablecell(content, flags) {
227+
const type = flags.header ? 'th' : 'td';
228+
const tag = flags.align
229+
? '<' + type + ' align="' + flags.align + '" class="docs-border docs-px-4 docs-py-2">'
230+
: '<' + type + ' class="docs-border docs-px-4 docs-py-2">';
231+
return tag + content + '</' + type + '>\n';
232+
}
233+
211234
hr() {
212235
return `<hr class="docs-md__hr">`;
213236
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@
8484
"liquid-fire": "^0.29.5 || ^0.30.0 || ^0.31.0",
8585
"lodash": "^4.17.15",
8686
"lunr": "^2.3.7",
87-
"marked": "^0.7.0",
87+
"marked": "^0.8.2",
8888
"pad-start": "^1.0.2",
8989
"parse-git-config": "^3.0.0",
9090
"quick-temp": "^0.1.8",
9191
"resolve": "^1.12.0",
9292
"sass": "^1.22.10",
9393
"semver": "^6.3.0",
9494
"striptags": "^3.1.1",
95-
"tailwindcss": "^1.0",
95+
"tailwindcss": "^1.2.0",
9696
"walk-sync": "^2.0.2",
9797
"yuidocjs": "^0.10.2"
9898
},

tests/acceptance/sandbox/api/guides-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module('Acceptance | Sandbox | API | Guides', function(hooks) {
1616

1717
let indexItems = modulePage.index.items.map(i => i.text);
1818

19-
assert.equal(indexItems.length, 2, 'correct number of items rendered');
19+
assert.equal(indexItems.length, 3, 'correct number of items rendered');
2020
assert.ok(indexItems.includes('Subsection') && indexItems.includes('Sub-subsection'), 'correct sections rendered');
2121
});
2222
});

tests/dummy/app/pods/sandbox/index/template.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ This is a subsection
1111
### Sub-subsection
1212

1313
This is a sub-subsection
14+
15+
### Table
16+
17+
| Dependency Name | Engine A | Host |
18+
|-----------------|----------|------|
19+
| Foo | v2 | v1 |
20+
| Bar | v1 | N\A |
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { highlightCode, default as compileMarkdown } from 'ember-cli-addon-docs/utils/compile-markdown';
2+
import { module, test } from 'qunit';
3+
4+
module('Unit | Utility | compile-markdown', function(hooks) {
5+
test('should be able to highlight javascript', function(assert) {
6+
let result = highlightCode(`let foo = 'bar';`, 'js');
7+
assert.equal(result, `<span class="hljs-keyword">let</span> foo = <span class="hljs-string">'bar'</span>;`);
8+
});
9+
10+
test('should render a table', function(assert) {
11+
let result = compileMarkdown(`
12+
| Dependency Name | Engine A | Host |
13+
|-----------------|----------|------|
14+
| Foo | v2 | v1 |
15+
`.trim());
16+
assert.equal(result, `<div class="docs-md"><table class="docs-table-auto">
17+
<thead>
18+
<tr class="docs-table-row">
19+
<th class="docs-border docs-px-4 docs-py-2">Dependency Name</th>
20+
<th class="docs-border docs-px-4 docs-py-2">Engine A</th>
21+
<th class="docs-border docs-px-4 docs-py-2">Host</th>
22+
</tr>
23+
</thead>
24+
<tbody><tr class="docs-table-row">
25+
<td class="docs-border docs-px-4 docs-py-2">Foo</td>
26+
<td class="docs-border docs-px-4 docs-py-2">v2</td>
27+
<td class="docs-border docs-px-4 docs-py-2">v1</td>
28+
</tr>
29+
</tbody></table></div>`);
30+
});
31+
});

tests/unit/utils/highlight-code-test.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

yarn.lock

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,11 +2431,25 @@ acorn-jsx@^5.2.0:
24312431
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.2.0.tgz#4c66069173d6fdd68ed85239fc256226182b2ebe"
24322432
integrity sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ==
24332433

2434+
acorn-node@^1.6.1:
2435+
version "1.8.2"
2436+
resolved "https://registry.yarnpkg.com/acorn-node/-/acorn-node-1.8.2.tgz#114c95d64539e53dede23de8b9d96df7c7ae2af8"
2437+
integrity sha512-8mt+fslDufLYntIoPAaIMUe/lrbrehIiwmR3t2k9LljIzoigEPF27eLk2hy8zSGzmR/ogr7zbRKINMo1u0yh5A==
2438+
dependencies:
2439+
acorn "^7.0.0"
2440+
acorn-walk "^7.0.0"
2441+
xtend "^4.0.2"
2442+
24342443
acorn-walk@^6.0.1:
24352444
version "6.2.0"
24362445
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-6.2.0.tgz#123cb8f3b84c2171f1f7fb252615b1c78a6b1a8c"
24372446
integrity sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==
24382447

2448+
acorn-walk@^7.0.0:
2449+
version "7.1.1"
2450+
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-7.1.1.tgz#345f0dffad5c735e7373d2fec9a1023e6a44b83e"
2451+
integrity sha512-wdlPY2tm/9XBr7QkKlq0WQVgiuGTX6YWPyRyBviSoScBuLfTVQhvwg6wJ369GJ/1nPfTLMfnrFIfjqVg6d+jQQ==
2452+
24392453
acorn@^2.1.0, acorn@^2.4.0:
24402454
version "2.7.0"
24412455
resolved "https://registry.yarnpkg.com/acorn/-/acorn-2.7.0.tgz#ab6e7d9d886aaca8b085bc3312b79a198433f0e7"
@@ -2451,16 +2465,16 @@ acorn@^6.0.1, acorn@^6.0.2:
24512465
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.0.tgz#b659d2ffbafa24baf5db1cdbb2c94a983ecd2784"
24522466
integrity sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw==
24532467

2468+
acorn@^7.0.0, acorn@^7.1.1:
2469+
version "7.1.1"
2470+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.1.tgz#e35668de0b402f359de515c5482a1ab9f89a69bf"
2471+
integrity sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==
2472+
24542473
acorn@^7.1.0:
24552474
version "7.1.0"
24562475
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.0.tgz#949d36f2c292535da602283586c2477c57eb2d6c"
24572476
integrity sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==
24582477

2459-
acorn@^7.1.1:
2460-
version "7.1.1"
2461-
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.1.tgz#e35668de0b402f359de515c5482a1ab9f89a69bf"
2462-
integrity sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==
2463-
24642478
after@0.8.2:
24652479
version "0.8.2"
24662480
resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f"
@@ -5782,6 +5796,11 @@ define-property@^2.0.2:
57825796
is-descriptor "^1.0.2"
57835797
isobject "^3.0.1"
57845798

5799+
defined@^1.0.0:
5800+
version "1.0.0"
5801+
resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693"
5802+
integrity sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=
5803+
57855804
delayed-stream@0.0.5:
57865805
version "0.0.5"
57875806
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-0.0.5.tgz#d4b1f43a93e8296dfe02694f4680bc37a313c73f"
@@ -5847,6 +5866,15 @@ detect-newline@3.1.0:
58475866
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
58485867
integrity sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==
58495868

5869+
detective@^5.2.0:
5870+
version "5.2.0"
5871+
resolved "https://registry.yarnpkg.com/detective/-/detective-5.2.0.tgz#feb2a77e85b904ecdea459ad897cc90a99bd2a7b"
5872+
integrity sha512-6SsIx+nUUbuK0EthKjv0zrdnajCCXVYGmbYYiYjFVpzcjwEs/JMDZ8tPRG29J/HhN56t3GJp2cGSWDRjjot8Pg==
5873+
dependencies:
5874+
acorn-node "^1.6.1"
5875+
defined "^1.0.0"
5876+
minimist "^1.1.1"
5877+
58505878
diff@3.5.0:
58515879
version "3.5.0"
58525880
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
@@ -10454,10 +10482,10 @@ marked@0.3.6:
1045410482
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.6.tgz#b2c6c618fccece4ef86c4fc6cb8a7cbf5aeda8d7"
1045510483
integrity sha1-ssbGGPzOzk74bE/Gy4p8v1rtqNc=
1045610484

10457-
marked@^0.7.0:
10458-
version "0.7.0"
10459-
resolved "https://registry.yarnpkg.com/marked/-/marked-0.7.0.tgz#b64201f051d271b1edc10a04d1ae9b74bb8e5c0e"
10460-
integrity sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg==
10485+
marked@^0.8.2:
10486+
version "0.8.2"
10487+
resolved "https://registry.yarnpkg.com/marked/-/marked-0.8.2.tgz#4faad28d26ede351a7a1aaa5fec67915c869e355"
10488+
integrity sha512-EGwzEeCcLniFX51DhTpmTom+dSA/MG/OBUDjnWtHbEnjAH180VzUeAw+oE4+Zv+CoYBWyRlYOTR0N8SO9R1PVw==
1046110489

1046210490
match-media@^0.2.0:
1046310491
version "0.2.0"
@@ -13642,16 +13670,17 @@ taffydb@2.7.2:
1364213670
resolved "https://registry.yarnpkg.com/taffydb/-/taffydb-2.7.2.tgz#7bf8106a5c1a48251b3e3bc0a0e1732489fd0dc8"
1364313671
integrity sha1-e/gQalwaSCUbPjvAoOFzJIn9Dcg=
1364413672

13645-
tailwindcss@^1.0:
13646-
version "1.1.4"
13647-
resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-1.1.4.tgz#786bd5faaf485c9eddcb821dd55666c56baa814e"
13648-
integrity sha512-p4AxVa4CKpX7IbNxImwNMGG9MHuLgratOaOE/iGriNd4AsRQRM2xMisoQ3KQHqShunrWuObga7rI7xbNsVoWGA==
13673+
tailwindcss@^1.2.0:
13674+
version "1.2.0"
13675+
resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-1.2.0.tgz#5df317cebac4f3131f275d258a39da1ba3a0f291"
13676+
integrity sha512-CKvY0ytB3ze5qvynG7qv4XSpQtFNGPbu9pUn8qFdkqgD8Yo/vGss8mhzbqls44YCXTl4G62p3qVZBj45qrd6FQ==
1364913677
dependencies:
1365013678
autoprefixer "^9.4.5"
1365113679
bytes "^3.0.0"
13652-
chalk "^2.4.1"
13680+
chalk "^3.0.0"
13681+
detective "^5.2.0"
1365313682
fs-extra "^8.0.0"
13654-
lodash "^4.17.11"
13683+
lodash "^4.17.15"
1365513684
node-emoji "^1.8.1"
1365613685
normalize.css "^8.0.1"
1365713686
postcss "^7.0.11"
@@ -13661,6 +13690,7 @@ tailwindcss@^1.0:
1366113690
postcss-selector-parser "^6.0.0"
1366213691
pretty-hrtime "^1.0.3"
1366313692
reduce-css-calc "^2.1.6"
13693+
resolve "^1.14.2"
1366413694

1366513695
tap-parser@^7.0.0:
1366613696
version "7.0.0"
@@ -14704,7 +14734,7 @@ xmlhttprequest-ssl@~1.5.4:
1470414734
resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e"
1470514735
integrity sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4=
1470614736

14707-
xtend@^4.0.0, xtend@~4.0.0, xtend@~4.0.1:
14737+
xtend@^4.0.0, xtend@^4.0.2, xtend@~4.0.0, xtend@~4.0.1:
1470814738
version "4.0.2"
1470914739
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
1471014740
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==

0 commit comments

Comments
 (0)