|
1 | 1 | # inline-markdown-editor
|
2 |
| -An inline wysiwyg markdown document editor based on replacing string subsections. WYSIWYG possible via woofmark. |
| 2 | + |
| 3 | +An inline wysiwyg markdown document editor based on replacing string subsections. WYSIWYG possible via the [woofmark](https://github.com/bevacqua/woofmark)-based [PublicLab.Editor](https://github.com/publiclab/PublicLab.Editor). |
| 4 | + |
| 5 | +## Basics |
| 6 | + |
| 7 | +`inline-markdown-editor` splits up a Markdown-containing string by double newlines into sections, and parses each into HTML, which it displays. |
| 8 | + |
| 9 | +It then adds an "edit button" beneath each section, which expands a nice form for editing that section either as Markdown or in rich text with a WYSIWYG editor. |
| 10 | + |
| 11 | +Upon submitting the form, an asynchronous AJAX post request is made to the specified server with parameters `before` and `after`, containing the original subsection markdown and its replacement. The form listens for a `true` or `false` response and updates the section's displayed HTML accordingly. |
| 12 | + |
| 13 | +For a demo, see: |
| 14 | + |
| 15 | +https://publiclab.github.io/inline-markdown-editor |
| 16 | + |
| 17 | +https://publiclab.github.io/inline-markdown-editor/wysiwyg |
| 18 | + |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +For an easy start, you can begin using `inline-markdown-editor` by pointing it at a markdown-containing element by its selector, and specifying a URL to send changes to. |
| 23 | + |
| 24 | +```js |
| 25 | +inlineMarkdownEditor({ |
| 26 | + replaceUrl: '/wiki/replace/', |
| 27 | + selector: '.markdown' |
| 28 | +}); |
| 29 | +``` |
| 30 | + |
| 31 | +You can also specify filters to run on the raw original markdown before display, and afterwards upon the displayed DOM element, as well as override several other defaults: |
| 32 | + |
| 33 | +```js |
| 34 | +inlineMarkdownEditor({ |
| 35 | + replaceUrl: '/wiki/replace/' + wiki_id, |
| 36 | + selector: '.markdown', |
| 37 | + preProcessor: function preProcessMarkdown(markdown) { |
| 38 | + // do things to markdown here |
| 39 | + return markdown |
| 40 | + }, |
| 41 | + postProcessor: function postProcessContent(element) { |
| 42 | + // do things to element here |
| 43 | + }, |
| 44 | + defaultMarkdown: function(markdown) {}, // a markdown parser |
| 45 | + buildSectionForm: function() {}, // return a string containing the form element |
| 46 | + onComplete: function(response, markdown, html, el, uniqueId, form, o) {}, // run on completing AJAX post |
| 47 | + isEditable: function(markdown) {} // returns boolean; whether a given subsection should get an inline form; default skips HTML and horizontal rules |
| 48 | + |
| 49 | +}); |
| 50 | +``` |
| 51 | + |
| 52 | +## Goals |
| 53 | + |
| 54 | +* configurable editors |
| 55 | +* better modularization of processSection.js |
| 56 | +* more tests |
| 57 | + |
| 58 | +## Tests we want |
| 59 | + |
| 60 | +* count sections |
| 61 | +* check that it doesn't add a form for whitespace or hrs |
| 62 | +* defaultMarkdown |
| 63 | +* preProcessor |
| 64 | +* postProcessor |
| 65 | +* insertForm: look for the form, the button |
| 66 | +* look for the textarea |
0 commit comments