Skip to content

Commit adf7211

Browse files
authored
Merge pull request #126 from curveball/json-viewer
New JSON viewer
2 parents 37b6003 + a59143c commit adf7211

File tree

11 files changed

+313
-32
lines changed

11 files changed

+313
-32
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ on:
1010
branches: [ main ]
1111

1212
jobs:
13-
build:
13+
test:
14+
name: Run tests
1415

1516
runs-on: ubuntu-latest
1617

@@ -28,3 +29,17 @@ jobs:
2829
- run: npm ci
2930
- run: npm run build --if-present
3031
- run: npm test
32+
33+
lint:
34+
name: Lint
35+
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- uses: actions/checkout@v2
40+
- name: Use Node.js
41+
uses: actions/setup-node@v1
42+
with:
43+
node-version: 16.x
44+
- run: npm ci
45+
- run: npm run lint

assets/themes/curveball/main.css

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ body, td, input, th {
77
color: #444;
88
}
99

10-
pre {
10+
.hljs, code {
1111
font-family: 'JetBrains Mono', 'Fira Code', 'Inconsolata', 'Ubuntu Mono', monospace;
1212
}
1313

@@ -319,3 +319,41 @@ button {
319319
line-height: 2;
320320
border-radius: .25ex;
321321
}
322+
323+
.hljs ul {
324+
list-style: none;
325+
padding-left: 10px;
326+
margin: 0;
327+
}
328+
.hljs ul li {
329+
padding-left: 10px;
330+
margin: 0;
331+
line-height: normal;
332+
}
333+
.hljs a {
334+
color: inherit;
335+
}
336+
337+
.hljs details {
338+
border: 0;
339+
margin: 0;
340+
padding: 0;
341+
}
342+
.hljs summary {
343+
margin: 0;
344+
padding: 0;
345+
}
346+
347+
.hljs details[open] .hidden-when-open {
348+
display: none;
349+
}
350+
351+
.hljs summary .teaser {
352+
border: 1px dotted #ccc;
353+
}
354+
355+
.hidden-copy-paste {
356+
font-size: 0;
357+
}
358+
359+

package-lock.json

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "dist/index.js",
66
"scripts": {
77
"prepublishOnly": "make build",
8-
"test": "make lint test",
8+
"test": "make test",
9+
"lint": "make lint",
910
"tsc": "tsc"
1011
},
1112
"repository": {
@@ -41,6 +42,7 @@
4142
"@types/markdown-it": "^12.0.1",
4243
"@types/mocha": "^9.0.0",
4344
"@types/node": "^12.20.4",
45+
"@types/node-fetch": "^2.6.1",
4446
"@types/react": "^17.0.3",
4547
"@types/react-dom": "^17.0.1",
4648
"@typescript-eslint/eslint-plugin": "^5.9.1",
@@ -65,6 +67,7 @@
6567
"highlight.js": "^11.2.0",
6668
"ketting": "^7.3.0",
6769
"markdown-it": "^12.3.2",
70+
"node-fetch": "^2.6.7",
6871
"react": "^17.0.1",
6972
"react-dom": "^17.0.1"
7073
},

src/components/embedded.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ export function Embedded(props: PageProps) {
99

1010
return <>
1111
<h2>Embedded</h2>
12-
{ embeds.map( embeddedState => <Embed resourceState={embeddedState} options={props.options} csrfToken={props.csrfToken} />) }
12+
{ embeds.map( embeddedState => <Embed
13+
resourceState={embeddedState}
14+
options={props.options}
15+
csrfToken={props.csrfToken}
16+
originalBody={embeddedState.serializeBody() as string}
17+
/>) }
1318
</>;
1419

1520
}

src/components/hal-body.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
import * as React from 'react';
22
import { PageProps } from '../types';
3-
import { highlightJson } from '../util';
43

5-
export function HalBody(props: PageProps) {
6-
7-
let tmpBody = Object.assign({}, props.resourceState.data);
4+
import JsonViewer from './json-viewer';
85

9-
if (props.options.fullBody) {
10-
tmpBody = JSON.parse(props.resourceState.serializeBody() as string);
11-
}
12-
13-
if (Object.keys(tmpBody).length === 0) {
14-
return <></>;
15-
}
6+
export function HalBody(props: PageProps) {
167

17-
const html = {
18-
__html: highlightJson(tmpBody)
19-
};
8+
const body = props.originalBody;
209

2110
return <>
2211
<h2>Contents</h2>
23-
<code className="hljs"><pre dangerouslySetInnerHTML={html}></pre></code>
12+
<code className="hljs"><JsonViewer data={body} /></code>
2413
</>;
2514

2615
}

0 commit comments

Comments
 (0)