Real-time code collaboration platform with instant rendering
Preview React components in real-time without needing to build your project.
Edit and render code together with team members.
Integration with Git repositories for efficient workflow.
Check how your components look on different devices.
Customize the editor appearance to your preferences.
Use CoMarkup directly in your browser.
The Firefox plugin automatically detects React code fragments on web pages and adds a "Render" button that opens a popup with the rendered component.
// Automatic React code detection:
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
const codeBlocks = node.querySelectorAll('pre, code');
codeBlocks.forEach(addRenderButton);
}
});
}
});
});
// Express server for rendering React components
const express = require('express');
const React = require('react');
const ReactDOMServer = require('react-dom/server');
app.post('/render', (req, res) => {
try {
const { code } = req.body;
// Transform and render React component
const component = eval(code);
const html = ReactDOMServer.renderToString(
React.createElement(component)
);
res.json({ html });
} catch (error) {
res.status(400).json({ error: error.message });
}
});
A local Express server that processes and renders JavaScript with React. The server takes React component code, compiles it, and returns the rendered HTML.
git clone https://github.com/comarkup/firefox
about:debugging
manifest.json
file from the directorygit clone https://github.com/comarkup/render-react
chmod +x setup.sh
./setup.sh
npm start
Use curl to test the API:
curl -X POST \
http://localhost:3001/render \
-H "Content-Type: application/json" \
-d '{"code": "function ExampleComponent() { return React.createElement('\''div'\'', null, '\''Hello'\'') }"}'
function SimpleComponent() {
return (
<div className="p-4 bg-blue-100">
<h2 className="text-xl font-bold">Hello CoMarkup!</h2>
<p>This is a simple React component.</p>
</div>
);
}
function TestComponent() {
const [count, setCount] = useState(0);
return (
<div className="p-4 bg-blue-100">
<h1 className="text-xl font-bold">Counter Component</h1>
<p>Current count: {count}</p>
<button
className="bg-blue-500 text-white px-4 py-2 rounded mt-2"
onClick={() => setCount(count + 1)}
>
Increment
</button>
</div>
);
}
The server performs secure code transformation through Babel, ensuring safe execution of React components.
Frontend uses dangerouslySetInnerHTML only for verified HTML that has been processed and validated by the server.
Secure communication between server and client is ensured through proper CORS (Cross-Origin Resource Sharing) configuration.
Create your own copy of the project to work on.
Use git checkout -b feature/amazing-feature
Use git commit -m 'Add some amazing feature'
Use git push origin feature/amazing-feature
Submit your changes for review and inclusion in the main project.