Skip to content

Commit 1dc67c0

Browse files
authored
feat(context): exporting context provider (#22)
Attempting to minimize potential provider instances, mirroring our markdown lib implementation.
1 parent 82b99ab commit 1dc67c0

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

public/index.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import syntaxHighlighter from '../src/index';
3+
import syntaxHighlighter, { cmVariableContext } from '../src/index';
44

55
ReactDOM.render(
66
<div>
77
<h1>Core Syntax Highlighter</h1>
88
<pre id="hub-reference">
9-
{syntaxHighlighter(
10-
`curl --request POST
11-
--url <<url>>
12-
--header 'authorization: Bearer 123'
13-
--header 'content-type: application/json'`,
14-
'curl',
15-
{
16-
dark: true,
17-
highlightMode: true,
18-
tokenizeVariables: true,
19-
ranges: [
20-
[
21-
{ ch: 0, line: 0 },
22-
{ ch: 0, line: 1 },
23-
],
24-
[
25-
{ ch: 0, line: 4 },
26-
{ ch: 0, line: 5 },
27-
],
9+
<cmVariableContext.Provider
10+
value={{
11+
user: {},
12+
defaults: [
13+
{
14+
name: 'url',
15+
default: 'GET',
16+
},
2817
],
29-
}
30-
)}
18+
}}
19+
>
20+
{syntaxHighlighter(
21+
`curl --request POST
22+
--url <<url>>
23+
--header 'authorization: Bearer 123'
24+
--header 'content-type: application/json'`,
25+
'curl',
26+
{
27+
dark: true,
28+
highlightMode: true,
29+
tokenizeVariables: true,
30+
ranges: [
31+
[
32+
{ ch: 0, line: 0 },
33+
{ ch: 0, line: 1 },
34+
],
35+
[
36+
{ ch: 0, line: 4 },
37+
{ ch: 0, line: 5 },
38+
],
39+
],
40+
}
41+
)}
42+
</cmVariableContext.Provider>
3143
</pre>
3244
<hr />
3345
<h1>Code Editor</h1>

src/codeMirror/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import CodeMirror from 'codemirror';
22
import React from 'react';
33
import PropTypes from 'prop-types';
4-
import Variable, { VARIABLE_REGEXP } from '@readme/variable';
4+
import Variable, { VARIABLE_REGEXP, VariablesContext } from '@readme/variable';
55
import { getMode } from '../utils/modes';
66

77
import '../utils/cm-mode-imports';
@@ -191,3 +191,4 @@ const ReadmeCodeMirror = (code, lang, opts = { tokenizeVariables: false, highlig
191191
};
192192

193193
export default ReadmeCodeMirror;
194+
export { VariablesContext };

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import codemirror from './codeMirror';
2+
import codemirror, { VariablesContext as cmVariableContext } from './codeMirror';
33
import codeEditor from './codeEditor';
44
import uppercase from './utils/uppercase';
55
import canonical from './utils/canonical';
@@ -34,4 +34,4 @@ const SyntaxHighlighter = (
3434
};
3535

3636
export default SyntaxHighlighter;
37-
export { uppercase, canonical, modes };
37+
export { uppercase, canonical, modes, cmVariableContext };

0 commit comments

Comments
 (0)