Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

RDMD Next #632

Merged
merged 57 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
7a26f9b
chore(markdown): skip empty magic code tabs
rafegoldberg Apr 25, 2020
6c4cb29
chore(markdown): skip empty magic callouts
rafegoldberg Apr 25, 2020
63aed06
chore(markdown): skip empty magic table blocks
rafegoldberg Apr 25, 2020
3960215
test(markdown): add test for various magic block null cases
rafegoldberg Apr 25, 2020
8ffebf1
fix(markdown): set nullcase defaults for MD callouts
rafegoldberg Apr 26, 2020
aef1ccd
style(markdown): custom callout icons base CSS
rafegoldberg Apr 26, 2020
6d4747d
feat(markdown): add copy code button
rafegoldberg Apr 24, 2020
2a8ecf7
style(markdown): variable-ize code blocks theme
rafegoldberg Apr 24, 2020
05a0e50
style(api-explorer): update RDMD style overrides
rafegoldberg Apr 24, 2020
f134144
style(markdown): add shorthand lang remapping
rafegoldberg Apr 25, 2020
a82a583
chore(markdown): update lang remapping
rafegoldberg Apr 25, 2020
bcda1e0
chore(syntaxHighlighter): add dart highlighting
rafegoldberg Apr 25, 2020
4da8c47
test(markdown): update code block expectations
rafegoldberg Apr 25, 2020
e350b2f
fix(markdown): unspaced code blocks
rafegoldberg Apr 26, 2020
d4805d0
fix(markdown): display images inline by default
rafegoldberg Apr 25, 2020
ae4bdbc
feat(markdown): add simple, vanilla lightbox solution
rafegoldberg Apr 25, 2020
54b9fb1
style(markdown): better lightbox transitions
rafegoldberg Apr 25, 2020
3779572
style(markdown): enwiden lightbox image widths
rafegoldberg Apr 25, 2020
8981db1
chore(markdown): lint
rafegoldberg Apr 25, 2020
d2ba26a
polish(markdown)
rafegoldberg Apr 25, 2020
628979c
test(markdown)
rafegoldberg Apr 25, 2020
943a129
test(markdown): update snapshots
rafegoldberg Apr 25, 2020
66b1b7b
test(markdown): update image expectations
rafegoldberg Apr 25, 2020
faa9603
fix(markdown): robust lang matching
rafegoldberg Apr 27, 2020
d02fb2a
style(markdown): rename root classes
rafegoldberg Apr 27, 2020
d8bba4c
BUILD
rafegoldberg Apr 27, 2020
73b2cd7
BUILD
rafegoldberg Apr 27, 2020
385c52b
lint(markdown): remove edge es syntax
rafegoldberg Apr 27, 2020
86ae4e0
test(markdown): update codeblock expectations
rafegoldberg Apr 27, 2020
b6ac1e8
whoops
rafegoldberg Apr 27, 2020
32c971b
BUILD
rafegoldberg Apr 27, 2020
8d9ec59
fix(explorer): set VariablesContext from new markdown package
rafegoldberg Apr 27, 2020
ea0b46c
BUILD
rafegoldberg Apr 27, 2020
082d68e
chore(markdown): nix extraneous logs
rafegoldberg Apr 27, 2020
d673c54
BUILD
rafegoldberg Apr 27, 2020
41dddee
style(markdown): clean up copy button scroll interaction
rafegoldberg Apr 27, 2020
18bfdd0
BUILD
rafegoldberg Apr 27, 2020
4654fe8
test(markdown): missing line breaks shouldn't confuse single code blo…
rafegoldberg Apr 27, 2020
2b67e73
#stablegenius
rafegoldberg Apr 27, 2020
3b6f155
#myunclewenttoMIT
rafegoldberg Apr 27, 2020
156c50e
test(markdown): update snapshots
rafegoldberg Apr 27, 2020
9207c99
chore(markdown): wrap the RDMD tree in old and new context providers
rafegoldberg Apr 27, 2020
cceb8e8
BUILD
rafegoldberg Apr 27, 2020
e554d65
Add compatibility #section- ID after all headers (#642)
domharrington Apr 27, 2020
f5783b1
BUILD
rafegoldberg Apr 27, 2020
6a24934
BUILD
rafegoldberg Apr 28, 2020
2f79297
Merge branch 'master' of https://github.com/readmeio/api-explorer int…
rafegoldberg Apr 28, 2020
b87d071
BUILD
rafegoldberg Apr 28, 2020
860d414
fix(markdown): trim trailing code tabs cruft
rafegoldberg Apr 28, 2020
8740967
BUILD
rafegoldberg Apr 28, 2020
6e0b9ba
style(markdown): add copy interaction state
rafegoldberg Apr 28, 2020
6959860
BUILD
rafegoldberg Apr 28, 2020
bed69f6
chore(markdown): simplify code parser pattern
rafegoldberg Apr 28, 2020
6a6d5a6
style(markdown): polish code copy ux
rafegoldberg Apr 28, 2020
34ba442
test(markdown): update and meet expectations
rafegoldberg Apr 28, 2020
4fa2929
chore(markdown): clean up debug cruft
rafegoldberg Apr 28, 2020
cb2d0fb
BUILD
rafegoldberg Apr 28, 2020
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
1,566 changes: 1,564 additions & 2 deletions packages/api-explorer/dist/index.js

Large diffs are not rendered by default.

997 changes: 982 additions & 15 deletions packages/api-explorer/package-lock.json

Large diffs are not rendered by default.

88 changes: 46 additions & 42 deletions packages/api-explorer/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const React = require('react');
const Cookie = require('js-cookie');
const PropTypes = require('prop-types');
const extensions = require('@readme/oas-extensions');
const VariablesContext = require('@readme/variable/contexts/Variables');
const OauthContext = require('@readme/variable/contexts/Oauth');
const SelectedAppContext = require('@readme/variable/contexts/SelectedApp');

Expand Down Expand Up @@ -173,15 +172,14 @@ class ApiExplorer extends React.Component {
});

/* eslint-disable global-require */
let BaseUrlContext;
let GlossaryTermsContext;
if (this.props.useNewMarkdownEngine) {
BaseUrlContext = require('@readme/markdown/contexts/BaseUrl');
GlossaryTermsContext = require('@readme/markdown/contexts/GlossaryTerms');
} else {
BaseUrlContext = require('@readme/markdown-magic/contexts/BaseUrl');
GlossaryTermsContext = require('@readme/markdown-magic/contexts/GlossaryTerms');
}
const BaseUrlContext = require('@readme/markdown-magic/contexts/BaseUrl');
const VariablesContext = require('@readme/variable/contexts/Variables');
const GlossaryTermsContext = require('@readme/markdown-magic/contexts/GlossaryTerms');

const { utils } = require('@readme/markdown');
const NewBaseUrlContext = utils.BaseUrlContext;
const NewVariablesContext = utils.VariablesContext;
const NewGlossaryTermsContext = utils.GlossaryContext;
/* eslint-enable global-require */

return (
Expand All @@ -192,38 +190,44 @@ class ApiExplorer extends React.Component {
>
{docs.map((doc, index) => (
<VariablesContext.Provider key={index} value={this.props.variables}>
<OauthContext.Provider value={this.props.oauth}>
<GlossaryTermsContext.Provider value={this.props.glossaryTerms}>
<BaseUrlContext.Provider value={this.props.baseUrl.replace(/\/$/, '')}>
<SelectedAppContext.Provider value={this.state.selectedApp}>
<Doc
key={doc._id}
appearance={this.props.appearance}
auth={this.state.auth}
baseUrl={this.props.baseUrl.replace(/\/$/, '')}
doc={doc}
flags={this.props.flags}
group={this.state.group}
groups={this.groups}
language={this.state.language}
lazy={this.isLazy(index)}
Logs={this.props.Logs}
maskErrorMessages={this.props.maskErrorMessages}
oas={this.getOas(doc)}
oauth={this.props.oauth}
onAuthChange={this.onAuthChange}
onAuthGroupChange={this.onAuthGroupChange}
onError={this.props.onError}
setLanguage={this.setLanguage}
suggestedEdits={this.props.suggestedEdits}
tryItMetrics={this.props.tryItMetrics}
useNewMarkdownEngine={this.props.useNewMarkdownEngine}
user={this.props.variables.user}
/>
</SelectedAppContext.Provider>
</BaseUrlContext.Provider>
</GlossaryTermsContext.Provider>
</OauthContext.Provider>
<NewVariablesContext.Provider key={index} value={this.props.variables}>
<OauthContext.Provider value={this.props.oauth}>
<GlossaryTermsContext.Provider value={this.props.glossaryTerms}>
<NewGlossaryTermsContext.Provider value={this.props.glossaryTerms}>
<BaseUrlContext.Provider value={this.props.baseUrl.replace(/\/$/, '')}>
<NewBaseUrlContext.Provider value={this.props.baseUrl.replace(/\/$/, '')}>
<SelectedAppContext.Provider value={this.state.selectedApp}>
Comment on lines +193 to +199
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erunion per some of my comments on this issue, I've double-wrapped the explorer's doc contents in both the old and new context providers. This is super verbose/redundant solution, but an interim one. I just haven't had a chance to go through and switch out all the references.

<Doc
key={doc._id}
appearance={this.props.appearance}
auth={this.state.auth}
baseUrl={this.props.baseUrl.replace(/\/$/, '')}
doc={doc}
flags={this.props.flags}
group={this.state.group}
groups={this.groups}
language={this.state.language}
lazy={this.isLazy(index)}
Logs={this.props.Logs}
maskErrorMessages={this.props.maskErrorMessages}
oas={this.getOas(doc)}
oauth={this.props.oauth}
onAuthChange={this.onAuthChange}
onAuthGroupChange={this.onAuthGroupChange}
onError={this.props.onError}
setLanguage={this.setLanguage}
suggestedEdits={this.props.suggestedEdits}
tryItMetrics={this.props.tryItMetrics}
useNewMarkdownEngine={this.props.useNewMarkdownEngine}
user={this.props.variables.user}
/>
</SelectedAppContext.Provider>
</NewBaseUrlContext.Provider>
</BaseUrlContext.Provider>
</NewGlossaryTermsContext.Provider>
</GlossaryTermsContext.Provider>
</OauthContext.Provider>
</NewVariablesContext.Provider>
</VariablesContext.Provider>
))}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/style/markdown-overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
color: #bbbec1;
p { color: inherit !important }
> .CodeTabs, > pre {
filter: invert(.9) !important;
filter: var(--md-code-text, invert(0.9)); /* ¡hacksaurz! */
}
}
}
Expand Down
30 changes: 0 additions & 30 deletions packages/markdown-magic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Components Embed 1`] = `"<div class=\\"embed\\"><a href=\\"https://gist.github.com/chaddy81/f852004d6d1510eec1f6\\" rel=\\"noopener noreferrer\\" style=\\"display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-decoration: none;\\" target=\\"_blank\\"><b style=\\"color: rgb(51, 51, 51);\\">View Embed:</b> <span style=\\"opacity: 0.75;\\">https://gist.github.com/chaddy81/f852004d6d1510eec1f6</span></a></div>"`;

exports[`Components Multi Code Block 1`] = `
"<div class=\\"CodeTabs\\"><div class=\\"CodeTabs-toolbar\\"><button type=\\"button\\">Text</button><button type=\\"button\\" class=\\"CodeTabs_active\\">Text</button></div><div class=\\"CodeTabs-inner\\"><pre><code data-lang=\\"\\" name=\\"\\"><span class=\\"cm-s-neo\\">hello
</span></code></pre><pre class=\\"CodeTabs_active\\"><code data-lang=\\"\\" name=\\"\\"><span class=\\"cm-s-neo\\">world
</span></code></pre></div></div>"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,10 @@ exports[`Parse ReadMe-Flavored Markdown Syntax Single Block 1`] = `
Object {
"children": Array [
Object {
"className": "tab-panel",
"data": Object {
"hName": "code",
"hProperties": Object {
"lang": "javascript",
"meta": "multiple.js",
},
},
"lang": "javascript",
"meta": "multiple.js",
"meta": "single.js",
"type": "code",
"value": "console.log('a multi-file code block');",
"value": "console.log('a single-file code block');",
},
Object {
"children": Array [
Expand Down
36 changes: 34 additions & 2 deletions packages/markdown/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ exports[`emojis 1`] = `

exports[`export multiple Markdown renderers allows complex compact headings 1`] = `
"<h1 id=\\"basic-text\\">Basic Text</h1>
<div id=\\"section-basic-text\\"></div>
<h2 id=\\"-oh-noes\\">🙀 oh noes!</h2>
<div id=\\"section--oh-noes\\"></div>
<h3 id=\\"6-oh-no\\"><strong>6</strong>. Oh No</h3>
<div id=\\"section-6-oh-no\\"></div>
<p>Lorem ipsum dolor!</p>"
`;

exports[`export multiple Markdown renderers renders HTML 1`] = `
"<h1 id=\\"hello-world\\">Hello World</h1>
<div id=\\"section-hello-world\\"></div>



Expand Down Expand Up @@ -92,6 +96,11 @@ exports[`export multiple Markdown renderers renders custom React components 1`]
</Unknown>


<div
id="section-hello-world"
/>





Expand Down Expand Up @@ -288,6 +297,19 @@ Object {
Object {
"type": "text",
"value": "
",
},
Object {
"children": Array [],
"properties": Object {
"id": "section-hello-world",
},
"tagName": "div",
"type": "element",
},
Object {
"type": "text",
"value": "



Expand Down Expand Up @@ -815,6 +837,11 @@ exports[`export multiple Markdown renderers renders plain markdown as React 1`]
</h1>


<div
id="section-hello-world"
/>





Expand Down Expand Up @@ -992,14 +1019,19 @@ exports[`export multiple Markdown renderers renders plain markdown as React 1`]
</React.Fragment>
`;

exports[`image 1`] = `"<p><img src=\\"http://example.com/image.png\\" alt=\\"Image\\" align=\\"\\" caption=\\"\\" height=\\"auto\\" title=\\"\\" width=\\"auto\\" loading=\\"lazy\\"></p>"`;
exports[`image 1`] = `"<p><img src=\\"http://example.com/image.png\\" alt=\\"Image\\" align=\\"\\" caption=\\"\\" height=\\"auto\\" title=\\"\\" width=\\"auto\\" loading=\\"lazy\\"><span class=\\"lightbox\\" role=\\"dialog\\"><span class=\\"lightbox-inner\\"><img src=\\"http://example.com/image.png\\" alt=\\"Image\\" align=\\"\\" caption=\\"\\" height=\\"auto\\" title=\\"Click to close...\\" width=\\"auto\\" loading=\\"lazy\\"></span></span></p>"`;

exports[`list items 1`] = `
"<ul>
<li>listitem1</li>
</ul>"
`;

exports[`magic image 1`] = `"<figure><img src=\\"https://files.readme.io/6f52e22-man-eating-pizza-and-making-an-ok-gesture.jpg\\" title=\\"man-eating-pizza-and-making-an-ok-gesture.jpg\\" class=\\"\\" width=\\"100%\\" align=\\"\\" alt=\\"\\" caption=\\"\\" height=\\"auto\\" loading=\\"lazy\\"><figcaption><p>A guy. Eating pizza. And making an OK gesture.</p></figcaption></figure>"`;
exports[`magic image 1`] = `"<figure><img src=\\"https://files.readme.io/6f52e22-man-eating-pizza-and-making-an-ok-gesture.jpg\\" title=\\"man-eating-pizza-and-making-an-ok-gesture.jpg\\" class=\\"\\" width=\\"100%\\" align=\\"\\" alt=\\"\\" caption=\\"\\" height=\\"auto\\" loading=\\"lazy\\"><span class=\\"lightbox\\" role=\\"dialog\\"><span class=\\"lightbox-inner\\"><img src=\\"https://files.readme.io/6f52e22-man-eating-pizza-and-making-an-ok-gesture.jpg\\" title=\\"Click to close...\\" class=\\"\\" width=\\"100%\\" align=\\"\\" alt=\\"\\" caption=\\"\\" height=\\"auto\\" loading=\\"lazy\\"></span></span><figcaption><p>A guy. Eating pizza. And making an OK gesture.</p></figcaption></figure>"`;

exports[`prefix anchors with section- should add a section- prefix to heading anchors 1`] = `
"<h1 id=\\"heading\\">heading</h1>
<div id=\\"section-heading\\"></div>"
`;

exports[`tables 1`] = `"<div class=\\"rdmd-table\\"><div class=\\"rdmd-table-inner\\"><table><thead><tr><th>Tables</th><th style=\\"text-align: center;\\">Are</th><th style=\\"text-align: right;\\">Cool</th></tr></thead><tbody><tr><td>col 3 is</td><td style=\\"text-align: center;\\">right-aligned</td><td style=\\"text-align: right;\\">$1600</td></tr><tr><td>col 2 is</td><td style=\\"text-align: center;\\">centered</td><td style=\\"text-align: right;\\">$12</td></tr><tr><td>zebra stripes</td><td style=\\"text-align: center;\\">are neat</td><td style=\\"text-align: right;\\">$1</td></tr></tbody></table></div></div>"`;
20 changes: 6 additions & 14 deletions packages/markdown/__tests__/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,15 @@ describe('Components', () => {
});

it('Multi Code Block', () => {
const codetabs = `

\`\`\`
hello
\`\`\`
\`\`\`
world
\`\`\`

`;

const rdmd = markdown.react(codetabs);
const tabs = '```\nhello\n```\n```php\nworld\n```\n\n';
const rdmd = markdown.react(tabs);
const wrap = mount(rdmd);

wrap.find('button').last().simulate('click').simulate('click');
expect(wrap.find('pre').at(1).getDOMNode().classList).toHaveLength(0);

expect(wrap.html()).toMatchSnapshot();
wrap.find('.CodeTabs-toolbar button').at(1).simulate('click').simulate('click');

expect(wrap.find('pre').at(1).getDOMNode().classList).toContain('CodeTabs_active');
});

it('Embed', () => {
Expand Down
11 changes: 10 additions & 1 deletion packages/markdown/__tests__/flavored-parsers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ describe('Parse ReadMe-Flavored Markdown Syntax', () => {
});

it('Single Block', () => {
const text = "\n\n```javascript multiple.js\nconsole.log('a multi-file code block');\n```\n\n&nbsp;";
const text = "\n\n```javascript single.js\nconsole.log('a single-file code block');\n```\n\n&nbsp;";
const ast = process(text);
expect(ast).toMatchSnapshot();
});

it('When fools just, like, totally disregard newlines...', () => {
// See this comment for more...
// https://github.com/readmeio/api-explorer/pull/627#discussion_r415420860
const md =
"\n\n```javascript single.js\nconsole.log('I should be a single code block');\n```\n## I Should be an H3 Tag\n```javascript single.js\nconsole.log('I\\'m also a single code block');\n```\n\n";
const ast = process(md);
expect(ast.children).toHaveLength(3);
});
});
8 changes: 7 additions & 1 deletion packages/markdown/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ test('should strip dangerous iframe tag', () => {

test('should strip dangerous img attributes', () => {
expect(mount(markdown.default('<img src="x" onerror="alert(\'charlie\')">')).html()).toBe(
'<img src="x" align="" alt="" caption="" height="auto" title="" width="auto" loading="lazy">'
'<img src="x" align="" alt="" caption="" height="auto" title="" width="auto" loading="lazy"><span class="lightbox" role="dialog"><span class="lightbox-inner"><img src="x" align="" alt="" caption="" height="auto" title="Click to close..." width="auto" loading="lazy"></span></span>'
);
});

Expand Down Expand Up @@ -270,3 +270,9 @@ Lorem ipsum dolor!`;
expect(markdown.md('')).toBeNull();
});
});

describe('prefix anchors with section-', () => {
it('should add a section- prefix to heading anchors', () => {
expect(markdown.html('# heading')).toMatchSnapshot();
});
});
40 changes: 40 additions & 0 deletions packages/markdown/__tests__/magic-block-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,46 @@ test('Blank Magic Blocks', () => {
{ "title": "No Level" }
[/block]`;
expect(process(noLevel)).toMatchSnapshot();

const emptyTable = `[block:parameters]
{
"data": {},
"cols": 3,
"rows": 1
}
[/block]`;
expect(process(emptyTable).children).toHaveLength(0);

const emptyCallout = `[block:callout]
{
"type": "info",
"title": ""
}
[/block]`;
expect(process(emptyCallout).children).toHaveLength(0);

const emptyCodeTabs = `[block:code]
{
"codes": [
{
"code": "",
"language": "text"
}
]
}
[/block]`;
expect(process(emptyCodeTabs).children).toHaveLength(0);

const emptyImage = `[block:image]
{
"images": [
{
"image": []
}
]
}
[/block]`;
expect(process(emptyImage).children).toHaveLength(0);
});

test('Sanitize Schema', () => {
Expand Down
Loading