Stacks-Editor
Stacks-Editor is a combination rich text / markdown editor that powers Stack Overflow's post editing experience.
Usage
Installation
npm install @stackoverflow/stacks-editor
Import via Modules or CommonJS
<div id="editor-container"></div>
import { StacksEditor } from "@stackoverflow/stacks-editor";
import "@stackoverflow/stacks-editor/styles.css";
new StacksEditor(
document.querySelector("#editor-container"),
"*Your* **markdown** here"
);
Import via <script> tag
<link
rel="stylesheet"
src="path/to/node_modules/@stackoverflow/stacks-editor/dist/styles.css"
/>
<div id="editor-container"></div>
<script src="//unpkg.com/@highlightjs/cdn-assets@latest/highlight.min.js"></script>
<script src="path/to/node_modules/@stackoverflow/stacks-editor/dist/app.bundle.js"></script>
<script>
new window.stacksEditor.StacksEditor(
document.querySelector("#editor-container"),
"*Your* **markdown** here",
{}
);
</script>
Development
- Install dependencies with
npm i
- Build and start using
npm start
- Your browser will show the example page automatically
Run Tests
Run all unit tests (no end-to-end tests) using
npm test
Run all end-to-end tests (written in Playwright) using
npm run test:e2e
End-to-end tests need to follow the convention of using someName.e2e.test.ts
as their filename and being saved in the test/e2e
directory. They'll automatically get picked up by the test runner this way.
Debug End-to-end tests
Understanding why end-to-end tests fail can be tricky business. There are a few ways to get a glimpse of playwright's internals:
-
Activate debug logging
With debug logging enabled, Playwright will log whatever it's currently trying to do or waiting for to the console. Activate it by running DEBUG=pw:api npm run test:e2e
-
Show the browser window
By default, playwright starts a headless browser to make things fast. If you want to follow along, you can tell playwright to show you the browser window. Go to jest-playwright.config.js
and uncomment the block containing the headless: false
setting.
Browser Bundle analysis
Generate a stats.json
file for analysis using
npm run print-stats
You can upload your stats.json
file here or here for visualization. See more resources here.