-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,446 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as React from "react"; | ||
|
||
export const Html = (props: React.Props<{}>) => { | ||
return ( | ||
<html> | ||
<head> | ||
<title>App</title> | ||
</head> | ||
<body> | ||
<div id="app">{props.children}</div> | ||
<script src="/lib/react-starter/client.js" /> | ||
</body> | ||
</html> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
|
||
import { App } from "./oneshot"; | ||
|
||
ReactDOM.render(<App />, document.getElementById("app")); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as React from "react"; | ||
// import * as ReactDOM from "react-dom"; | ||
import * as remark from "remark"; | ||
import reactRenderer from "remark-react"; | ||
|
||
export class App extends React.Component<{}, { text: string }> { | ||
constructor(props: {}) { | ||
super(props); | ||
this.state = { | ||
text: "# hello world" | ||
}; | ||
} | ||
onChange(e: React.ChangeEvent<HTMLTextAreaElement>): void { | ||
this.setState({ text: e.target.value }); | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
<textarea value={this.state.text} onChange={this.onChange} /> | ||
<div id="preview"> | ||
{ | ||
// @ts-ignore | ||
remark() | ||
.use(reactRenderer) | ||
.processSync(this.state.text).contents | ||
} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as express from 'express'; | ||
import * as ReactDOMServer from 'react-dom/server'; | ||
import { App } from "./oneshot"; | ||
import { Html } from "./base"; | ||
import * as React from 'react'; | ||
import * as url from 'url'; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
|
||
const app = express(); | ||
const dirname = process.cwd(); | ||
|
||
app.get('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
ReactDOMServer.renderToNodeStream(<Html><App /></Html>).pipe(res); | ||
}); | ||
|
||
app.get('/lib/*.js', (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
const { pathname } = url.parse(req.url) | ||
if (!pathname) { | ||
return | ||
} | ||
const filePath = path.join(dirname, pathname) | ||
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) { | ||
fs.createReadStream(filePath).pipe(res) | ||
return | ||
} | ||
const data = fs.readFileSync(filePath); | ||
res.send(data); | ||
}); | ||
|
||
app.listen(3500); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import * as OneShot from '../oneshot'; | ||
import * as renderer from 'react-test-renderer'; | ||
|
||
|
||
test('React.MyComponent', () => { | ||
const comp = React.createElement(OneShot.App); | ||
expect(comp).toEqual(<OneShot.App />); | ||
}); | ||
|
||
test('レンダリングを行った結果が一致する', () => { | ||
const component = renderer.create( | ||
<OneShot.App /> | ||
); | ||
const tree = component.toJSON(); | ||
expect(tree).toEqual(`# hello world | ||
`); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as React from "react"; | ||
import * as remark from "remark"; | ||
import reactRenderer from "remark-react"; | ||
|
||
export interface AppState { | ||
text: string; | ||
} | ||
|
||
// @ts-ignore | ||
const processor = remark().use(reactRenderer, { | ||
prefix: 'md-', | ||
sanitize: true | ||
}) | ||
|
||
export class App extends React.Component<{}, AppState> { | ||
constructor(props: {}) { | ||
super(props); | ||
this.state = { | ||
text: "# hello world" | ||
}; | ||
} | ||
|
||
onChange(e: React.ChangeEvent<HTMLTextAreaElement>): void { | ||
this.setState({ text: e.target.value }); | ||
} | ||
|
||
render() { | ||
// @ts-ignore | ||
const content = processor.processSync(this.state.text).contents | ||
return content; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface Options { | ||
allowDangerousHTML: boolean | ||
commonmark: boolean | ||
handlers: Object | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as React from 'react'; | ||
|
||
export interface Options { | ||
createElement?: Function | ||
sanitize?: boolean | ||
toHast?: {} | ||
remarkReactComponents?: {} | ||
} | ||
|
||
declare function remarkReact(options: Options): any; | ||
|
||
export default remarkReact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface Parser {} | ||
interface Options {} | ||
|
||
|
||
declare function parse(options: Options): Parser; | ||
|
||
export default parse; |
Oops, something went wrong.