punkweb-bb 0.2.3__py3-none-any.whl → 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. punkweb_bb/__pycache__/admin.cpython-311.pyc +0 -0
  2. punkweb_bb/__pycache__/admin_forms.cpython-311.pyc +0 -0
  3. punkweb_bb/__pycache__/forms.cpython-311.pyc +0 -0
  4. punkweb_bb/__pycache__/models.cpython-311.pyc +0 -0
  5. punkweb_bb/__pycache__/settings.cpython-311.pyc +0 -0
  6. punkweb_bb/__pycache__/tests.cpython-311.pyc +0 -0
  7. punkweb_bb/__pycache__/urls.cpython-311.pyc +0 -0
  8. punkweb_bb/__pycache__/utils.cpython-311.pyc +0 -0
  9. punkweb_bb/__pycache__/views.cpython-311.pyc +0 -0
  10. punkweb_bb/__pycache__/widgets.cpython-311.pyc +0 -0
  11. punkweb_bb/admin.py +0 -4
  12. punkweb_bb/admin_forms.py +6 -5
  13. punkweb_bb/forms.py +13 -5
  14. punkweb_bb/migrations/0005_alter_thread_options.py +24 -0
  15. punkweb_bb/migrations/0006_remove_boardprofile__signature_rendered_and_more.py +60 -0
  16. punkweb_bb/migrations/__pycache__/0005_alter_thread_options.cpython-311.pyc +0 -0
  17. punkweb_bb/migrations/__pycache__/0006_remove_boardprofile__signature_rendered_and_more.cpython-311.pyc +0 -0
  18. punkweb_bb/models.py +6 -6
  19. punkweb_bb/settings.py +1 -0
  20. punkweb_bb/static/punkweb_bb/css/thread.css +24 -0
  21. punkweb_bb/static/punkweb_bb/editor/markdown-editor.js +23 -0
  22. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/.eslintrc.json +15 -0
  23. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/.gitignore +108 -0
  24. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/.prettierrc.json +1 -0
  25. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/LICENSE +21 -0
  26. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/README.md +240 -0
  27. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/babel.config.json +14 -0
  28. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/dist/blank.html +18 -0
  29. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/dist/demo.html +126 -0
  30. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/dist/tiny-mde.css +231 -0
  31. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/dist/tiny-mde.js +3086 -0
  32. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/dist/tiny-mde.min.css +1 -0
  33. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/dist/tiny-mde.min.js +1 -0
  34. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/dist/tiny-mde.tiny.js +1 -0
  35. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/docs/_config.yml +1 -0
  36. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/docs/_layouts/default.html +50 -0
  37. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/docs/index.md +174 -0
  38. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/globals.d.ts +172 -0
  39. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/gulpfile.mjs +226 -0
  40. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest/block.test.js +696 -0
  41. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest/commandbar.test.js +84 -0
  42. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest/inline.test.js +486 -0
  43. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest/interaction.test.js +31 -0
  44. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest/setup.test.js +164 -0
  45. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest/util/config.js +2 -0
  46. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest/util/server.js +9 -0
  47. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest/util/setup.js +1 -0
  48. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest/util/test-helpers.js +98 -0
  49. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest-puppeteer.config.js +8 -0
  50. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/jest.config.js +13 -0
  51. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/package-lock.json +16295 -0
  52. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/package.json +72 -0
  53. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/TinyMDE.js +1926 -0
  54. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/TinyMDECommandBar.js +256 -0
  55. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/css/commandbar.css +72 -0
  56. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/css/editor.css +157 -0
  57. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/css/index.css +3 -0
  58. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/grammar.js +300 -0
  59. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/html/blank.html +18 -0
  60. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/html/demo.html +126 -0
  61. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/index.js +4 -0
  62. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/blockquote.svg +1 -0
  63. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/bold.svg +1 -0
  64. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/clear_formatting.svg +1 -0
  65. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/code.svg +1 -0
  66. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/h1.svg +1 -0
  67. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/h2.svg +1 -0
  68. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/hr.svg +1 -0
  69. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/image.svg +1 -0
  70. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/italic.svg +1 -0
  71. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/link.svg +1 -0
  72. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/ol.svg +1 -0
  73. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/strikethrough.svg +1 -0
  74. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/svg.js +17 -0
  75. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/svg/ul.svg +1 -0
  76. punkweb_bb/static/punkweb_bb/vendor/tiny-markdown-editor/src/tiny.js +3 -0
  77. punkweb_bb/templates/punkweb_bb/base_delete_modal.html +13 -0
  78. punkweb_bb/templates/punkweb_bb/index.html +2 -2
  79. punkweb_bb/templates/punkweb_bb/partials/category_delete.html +4 -8
  80. punkweb_bb/templates/punkweb_bb/partials/post_delete.html +4 -8
  81. punkweb_bb/templates/punkweb_bb/partials/shout_delete.html +4 -8
  82. punkweb_bb/templates/punkweb_bb/partials/subcategory_delete.html +4 -8
  83. punkweb_bb/templates/punkweb_bb/partials/thread_delete.html +4 -8
  84. punkweb_bb/templates/punkweb_bb/partials/thread_move.html +24 -0
  85. punkweb_bb/templates/punkweb_bb/profile.html +2 -2
  86. punkweb_bb/templates/punkweb_bb/shoutbox/shout_list.html +2 -2
  87. punkweb_bb/templates/punkweb_bb/subcategory.html +1 -1
  88. punkweb_bb/templates/punkweb_bb/thread.html +24 -14
  89. punkweb_bb/templates/punkweb_bb/widgets/markdown-editor.html +3 -0
  90. punkweb_bb/templatetags/__pycache__/markdown.cpython-311.pyc +0 -0
  91. punkweb_bb/templatetags/__pycache__/render.cpython-311.pyc +0 -0
  92. punkweb_bb/templatetags/__pycache__/shoutbox_bbcode.cpython-311.pyc +0 -0
  93. punkweb_bb/templatetags/__pycache__/shoutbox_render.cpython-311.pyc +0 -0
  94. punkweb_bb/templatetags/render.py +48 -0
  95. punkweb_bb/templatetags/shoutbox_render.py +22 -0
  96. punkweb_bb/tests.py +3 -3
  97. punkweb_bb/urls.py +1 -0
  98. punkweb_bb/utils.py +19 -3
  99. punkweb_bb/views.py +35 -4
  100. punkweb_bb/widgets.py +20 -0
  101. {punkweb_bb-0.2.3.dist-info → punkweb_bb-0.3.0.dist-info}/METADATA +56 -41
  102. {punkweb_bb-0.2.3.dist-info → punkweb_bb-0.3.0.dist-info}/RECORD +105 -38
  103. punkweb_bb/templatetags/shoutbox_bbcode.py +0 -14
  104. {punkweb_bb-0.2.3.dist-info → punkweb_bb-0.3.0.dist-info}/LICENSE +0 -0
  105. {punkweb_bb-0.2.3.dist-info → punkweb_bb-0.3.0.dist-info}/WHEEL +0 -0
  106. {punkweb_bb-0.2.3.dist-info → punkweb_bb-0.3.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,240 @@
1
+ # tiny-markdown-editor
2
+
3
+ TinyMDE: A tiny, low-dependency<sup>(1)</sup> embeddable HTML/JavaScript Markdown editor.
4
+
5
+ <sup>(1)</sup>: TinyMDE's runtime only depends on `core-js` for polyfills to support older browsers.
6
+
7
+ Visit the [demo page](https://jefago.github.io/tiny-markdown-editor/) to see TinyMDE in action.
8
+
9
+ ## Overview
10
+
11
+ TinyMDE is an in-browser markdown editor that allows editing Markdown files with in-line formatting previews (bold, italic, headings, code etc.) as well as a toolbar with familiar point-and-click or keyboard shortcut interaction.
12
+
13
+ TinyMDE can be used as a drop-in text area replacement.
14
+
15
+ ## Motivation
16
+
17
+ TinyMDE was motivated by wanting to improve on [EasyMDE](https://github.com/Ionaru/easy-markdown-editor) which is extremely flexible but had two shortcomings:
18
+
19
+ - EasyMDE depends on [Code Mirror](https://codemirror.net/) for editing and formatting. CodeMirror is a full fledged and customizable in-browser code editor, and has a price: EasyMDE's JS file is 280kb in size. TinyMDE is less than 70kb (less than a quarter of EasyMDE's size), the "tiny" version without the toolbar even below 60kb!
20
+ - CodeMirror doesn't work well on mobile, at least not for writing prose: mobile phone OS auto-correction functionality, which many people rely on to quickly type on mobile, is not supported by CodeMirror.
21
+
22
+ ## Install TinyMDE
23
+
24
+ You can install TinyMDE from NPM (e.g., if you want to use it in a bundled JS application using Webpack or Rollup), use a hosted version, or self-host the JavaScript and CSS files.
25
+
26
+ ### Install TinyMDE from NPM
27
+
28
+ Install the `tiny-markdown-editor` package from NPM:
29
+
30
+ ```bash
31
+ npm install --save tiny-markdown-editor
32
+ ```
33
+
34
+ Then, in your JavaScript file, simply import the package like this:
35
+
36
+ ```JavaScript
37
+ const TinyMDE = require('tiny-markdown-editor');
38
+ var tinyMDE = new TinyMDE.Editor({element: 'editor'});
39
+ ```
40
+
41
+ Bundle the JavaScript with your favorite bundler like Webpack or Rollup to ensure the TinyMDE code gets included in the shipped JavaScript file.
42
+
43
+ **Please note:** If you go down the NPM package route, you will also need to make sure to [style the components](#styling-tinymde). After installing TinyMDE from NPM, you will find a CSS file `tiny-mde.css` you can use as a base in the directory `node_modules/tiny-markdown-editor/dist`.
44
+
45
+ ### Hosted version
46
+
47
+ You can simply include the JavaScript and CSS files from Unpkg on your website, using the following code:
48
+
49
+ ```html
50
+ <script src="https://unpkg.com/tiny-markdown-editor/dist/tiny-mde.min.js"></script>
51
+ <link
52
+ rel="stylesheet"
53
+ type="text/css"
54
+ href="https://unpkg.com/tiny-markdown-editor/dist/tiny-mde.min.css"
55
+ />
56
+ ```
57
+
58
+ ### Self-host
59
+
60
+ To self-host TinyMDE, follow these steps:
61
+
62
+ - [Download and build TinyMDE](#build-tinymde). Alternatively, download the newest [release](https://github.com/jefago/tiny-markdown-editor/releases) and unpack the archive.
63
+ - Copy the output JS and CSS files `tiny-mde.min.js` and `tiny-mde.min.css` from the `dist` directory to your website's directory.
64
+ - Include these files on your website:
65
+ ```html
66
+ <script src="tiny-mde.min.js"></script>
67
+ <link rel="stylesheet" type="text/css" href="tiny-mde.min.css" />
68
+ ```
69
+
70
+ ## Creating an editor and toolbar on your page
71
+
72
+ ### Simple creation
73
+
74
+ To create a simple editor as child of an HTML `div` element with the ID `editor`, use the following HTML / JS code:
75
+
76
+ ```html
77
+ <div id="editor"></div>
78
+ <script type="text/javascript">
79
+ var tinyMDE = new TinyMDE.Editor({ element: "editor" });
80
+ </script>
81
+ ```
82
+
83
+ ### Command bar creation
84
+
85
+ To create a toolbar (command bar) along with the editor, create another container div (here called `toolbar`), and instantiate editor and toolbar as follows:
86
+
87
+ ```html
88
+ <div id="toolbar"></div>
89
+ <div id="editor"></div>
90
+ <script type="text/javascript">
91
+ var tinyMDE = new TinyMDE.Editor({ element: "editor" });
92
+ var commandBar = new TinyMDE.CommandBar({
93
+ element: "toolbar",
94
+ editor: tinyMDE,
95
+ });
96
+ </script>
97
+ ```
98
+
99
+ ### Creation from a textarea
100
+
101
+ TinyMDE can be used as a drop-in textarea replacement. This means that when TinyMDE is passed a textarea, the editor will act as if the user is directly editing the textarea: The editor is initialized with the content of the textarea, and changing text in the editor changes the textarea's content. The easiest code to do so is as follows:
102
+
103
+ ```html
104
+ <div class="txtcontainer">
105
+ <textarea id="txt">This is some **Markdown** formatted text</textarea>
106
+ </div>
107
+ <script type="text/javascript">
108
+ var tinyMDE = new TinyMDE.Editor({ textarea: "txt" });
109
+ </script>
110
+ ```
111
+
112
+ Please note:
113
+
114
+ - The editor doesn't quite _replace_ the textarea. The textarea just gets hidden, and the editor content is mirrored in the textarea. If you programmatically change the contents of the textarea, the editor would get out of sync.
115
+ - The editor element will be inserted in the DOM as a sibling of the textarea element. In order to size and format the editor element properly, apply styles to the parent element of the textarea (in the example above, `div.txtcontainer`).
116
+
117
+ ## Configure TinyMDE
118
+
119
+ ### Editor constructor parameters
120
+
121
+ `TinyMDE.Editor` takes as argument a key-value object with the following possible attributes:
122
+
123
+ | Attribute | Description |
124
+ | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
125
+ | `element` | The DOM element under which the TinyMDE DOM element will be created. The `element` attribute can be given as either an ID or the DOM element itself (i.e., the result of a call to `document.getElementById()`). |
126
+ | `content` | The initial content of the editor, given as a string. May contain newlines. |
127
+ | `textarea` | The textarea that will be linked to the editor. The textarea can be given as an ID or as the DOM element itself (i.e., the result of a call to `document.getElementById()`). The content of the editor will be reflected in the value of the textarea at any given point in time. If `textarea` is given and `content` isn't, then the editor content will be initialized to the textarea's value. If `textarea` is given and `element` isn't, then the editor element will be created as the next sibling of the textarea element. |
128
+
129
+ If neither `element` not `textarea` are given, the editor element will be created as the last child element of the `body` element (probably not what you want in most cases, so you probably want to pass at least one of `element` or `textarea`).
130
+
131
+ If neither `content` nor `textarea` are given, the content of the editor is initialized with a placeholder text (`# Hello TinyMDE!\nEdit **here**`). This is probably not what you want, so you probably want to pass at least one of `content` or `textarea`.
132
+
133
+ ### CommandBar constructor parameters
134
+
135
+ `TinyMDE.Editor` takes as argument a key-value object with the following possible attributes:
136
+
137
+ | Attribute | Description |
138
+ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
139
+ | `element` | The DOM element under which the command bar DOM element will be created. The `element` attribute can be given as either an ID or the DOM element itself (i.e., the result of a call to `document.getElementById()`). If `element` is not given, the commandbar will be created as the last child of the `body` element (probably not what you want in most cases). |
140
+ | `editor` | The editor object that this command bar will be linked to (i.e., the return value of `new TinyMDE.Editor()`). |
141
+ | `commands` | The list of commands to show. See [below](#customizing-commands). |
142
+
143
+ ### Customizing commands
144
+
145
+ In order to customize the commands shown on the command bar, pass an array to the `commands` attribute. Each of the entries of the array defines one command bar element (button or separator), left to right. Each of the entries of the `commands` array can be one of the following:
146
+
147
+ - A string with the content `|` (vertical pipe), which will create a separator line.
148
+ - A string with one of the command identifiers `bold`, `italic`, `strikethrough`, `code`, `h1`, `h2`, `ul`, `ol`, `blockquote`, `hr`, `insertLink`, or `insertImage`, which will create the default button for that command
149
+ - A key-value object to create a customized or custom button.
150
+
151
+ If an entry of the `commands` array is an object, you can either customize one of the existing commands (e.g., use a different icon or keyboard shortcut for the `bold` command), or use a completely custom command. An object entry of the `commands` array can contain the following attributes:
152
+
153
+ | Attribute | Description |
154
+ | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
155
+ | `name` _mandatory_ | A string that is unique within the scope of this CommandBar instance that identifies the command. If one of the default commands (`bold`, `italic`, `strikethrough`, `code`, `h1`, `h2`, `ul`, `ol`, `blockquote`, `hr`, `insertLink`, or `insertImage`) is given as the `name` attribute, then the command is initialized with all the default values of the default commands and they can be overridden by specifying additional attributes. In other words, `{ name: 'bold' }` as a command array entry behaves the same as `'bold'`. If the `name` attribute is set to a string other than one of the default command, a custom command can be defined. |
156
+ | `title` | The title of the command, shown as a tooltip on hover. Defaults to be the same as `name`. |
157
+ | `innerHTML` | The HTML content of the command button. In the default styling, the content will have a space of 18x18 CSS pixels. |
158
+ | `action` | For custom commands, you need to set the `action` attribute to a function taking the Editor object as a parameter, for example: `action: editor => { editor.setContent('Test')}`. |
159
+ | `hotkey` | A keyboard shortcut for the command. The keyboard shortcut needs to be a string containing a key (e.g., 'A' or '1'), preceded by one or more modifier keys (`Ctrl`, `Shift`, `Alt`, `Cmd`, `Win`, `Option`), each separated with `-`. Examples: `Alt-I`, `Ctrl-Shift-3`. There are two convenience modifier keys that are recognized for easy cross-platform development: `Mod` is set to `Cmd` on macOS / iOS / iPadOS and `Ctrl` elsewhere (e.g., `Mod-B` as a shortcut for the `bold` command ends up as either `Ctrl` + `B` or `⌘` + `B`); `Mod2` is set to `Option` on macOS / iOS / iPadOS and `Alt` elsewhere. |
160
+
161
+ The default array of commands is as follows: `['bold', 'italic', 'strikethrough', '|', 'code', '|', 'h1', 'h2', '|', 'ul', 'ol', '|', 'blockquote', 'hr', '|', 'insertLink', 'insertImage']`.
162
+
163
+ ### Editor methods
164
+
165
+ Here are some methods of the Editor object that might be useful in general interaction or custom CommandBar commands:
166
+
167
+ | Method | Description |
168
+ | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
169
+ | `getContent()` | Returns the content of the editor as a string. |
170
+ | `setContent(content)` | Sets the content of the editor to the string `content`. |
171
+ | `getSelection(getAnchor)` | Gets the current selection / cursor position inside the editor. The parameter `getAnchor` (defaults to false) determines if the anchor (starting point) of the selection should be returned—if `getAnchor` is false (or omitted), the focus (end point) is returned, otherwise the starting point. If the selection is not inside the editor, `null` is returned. The method returns an object with the attributes `row` and `col` which contain the zero-based row (line) and column number of the selection position. |
172
+ | `setSelection(focus, anchor)` | Sets the selection within the editor. The parameters `focus` and `offset` are both of the format returned by `getSelection()` (containing attributes `row` and `col`). If `anchor` is `null` or omitted, a single-point selection (cursor position) will be set. |
173
+ | `paste(text, anchor, focus)` | Pastes / inserts text over either the current selection (if `anchor` and `focus` are null or omitted) or a specific range (if `anchor` and `focus` are passed in in the format as returned by `getSelection()`). |
174
+ | `wrapSelection(pre, post, anchor, focus)` | Wraps the current selection (if `anchor` and `focus` are `null` or omitted) or a specific selection (if `anchor` and `focus` are given) in the strings `pre` and `post`. For example, `wrapSelection('[', '](https://www.github.com)')` will wrap the selection with a link to GitHub. |
175
+ | `addEventListener(type, listener`) | Adds an [event listener](#event-listeners) to the editor. `type` is a string denoting the type (`change` or `selection`), and `listener` is a function which takes one parameter, the event. |
176
+
177
+ ### Event listeners
178
+
179
+ There are two event listener types that can be registered on the editor: `change` and `selection`.
180
+
181
+ #### `change` event
182
+
183
+ A `change` event is fired any time the content of the editor changes. The event object passed to the listener function contains the following properties:
184
+
185
+ | Attribute | Description |
186
+ | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
187
+ | `content` | The current content as a string. |
188
+ | `linesDirty` | An array of booleans, which for each line contains `true` if the line might have changed in terms of either its content or its block type since the last change, and `false` if the line is guaranteed to not have changed. |
189
+
190
+ #### `selection` event
191
+
192
+ A `selection` event is fired any time the selection within the editor changes. The event object passed to the listener function contains the following properties:
193
+
194
+ | Attribute | Description |
195
+ | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
196
+ | `focus` | The focus (end point) of the current selection, in the format as returned by `getSelection()` (two attributes `row` and `col` denoting the zero based row and column). |
197
+ | `anchor` | The anchor (start point) of the current selection, in the format as returned by `getSelection()` (two attributes `row` and `col` denoting the zero based row and column). |
198
+ | `commandState` | An array which contains an attribute for every default command name `bold`, `italic`, `strikethrough`, `code`, `h1`, `h2`, `ul`, `ol`, `blockquote`, `hr`, `insertLink`, and `insertImage`). The value of each attribute is one of `true`, `false`, or `null`. The value is `true` if the command is currently active (e.g., if the cursor is within a bold stretch of text, then the state for `bold` will be `true`). The value is `false` if the command is currently inactive but could be activated (e.g., if the selection encompasses a stretch of text that could be bolded, then the state for `bold` will be `false`). The value is `null` if the command is currently not applicable (e.g., if the cursor is within a code block where inline formatting is not available, the state will be `null` for `bold`). |
199
+
200
+ ### Styling TinyMDE
201
+
202
+ In order to style TinyMDE, edit the CSS file. You can see the classes that can be assigned styles within the file. For a bit more detail about the classes, read on.
203
+
204
+ #### Editor styling
205
+
206
+ There are some generally interesting CSS classes that can be formatted. Most of them start with `TM`, short for `TinyMDE`.
207
+
208
+ - `TinyMDE` is the editor element.
209
+ - `TMMark` is any markup. Any element with the class `TMMark` will also have another class called `TMMark_*`, where `*` is replaced by the class name of the respective block or inline style. For example, in a H1 line with the content `# Heading 1`, the `#` is contained in an element with the classes `TMMark TMMark_TMH1`.
210
+ - `TMInlineFormatted` contains text that is inline formatted.
211
+
212
+ The following classes denote Markdown blocks: `TMPara`, `TMBlankLine`, `TMH1`, `TMH2`, `TMH3`, `TMH4`, `TMH5`, `TMH6`, `TMBlockquote`, `TMCodeFenceBacktickOpen`, `TMFencedCodeBacktick`, `TMCodeFenceBacktickClose`, `TMCodeFenceTildeOpen`, `TMFencedCodeTilde`, `TMCodeFenceTildeClose`, `TMSetextH1`, `TMSetextH1Marker`, `TMSetextH2`, `TMSetextH2Marker`, `TMHR`, `TMUL`, `TMOL`, `TMIndentedCode`, `TMLinkReferenceDefinition`, `TMHTMLBlock`.
213
+
214
+ The following classes denote Markdown inline formatted stretches of text: `TMCode`, `TMAutolink`, `TMHTML`, `TMStrong`, `TMEm`, `TMStrikethrough`, `TMImage`, `TMLink`, (`TMLinkLabel` (also marked as `TMLinkLabel_Valid` or `TMLinkLabel_Invalid` depending on whether or not the label references a valid reference), `TMLinkDestination`, `TMLinkTitle`, `TMImageDestination`, `TMImageTitle`.
215
+
216
+ Each line of a code fenced blocks (ie. starting and ending with ` ``` ` or `~~~`) will also be wrapped in an element with the class `TMFencedCode`. Each line of an HTML block (ie. starting with an HTML element) will also be wrapped in an element with the class `TMHTMLContent`.
217
+
218
+ #### CommandBar styling
219
+
220
+ The main toolbar element has the class `TMCommandBar`. Buttons have the class `TMCommandButton`, with an additional class of `TMCommandButton_Active`, `TMCommandButton_Inactive`, or `TMCommandButton_Disabled`, depending on the state of the respective command. Divider elements have the class `TMCommandDivider`.
221
+
222
+ ## Build TinyMDE
223
+
224
+ Building TinyMDE is pretty straight forward:
225
+
226
+ 1. Clone this repository:
227
+ ```bash
228
+ git clone git@github.com:jefago/tiny-markdown-editor.git
229
+ ```
230
+ 2. In the repository directory, run the build script:
231
+ ```bash
232
+ npm run build
233
+ ```
234
+
235
+ The build output is in the `dist` directory. You will find the following files there:
236
+
237
+ - `tiny-mde.css` and `tiny-mde.min.css`: CSS files to style the editor. These can be edited at will to make the editor look like you want to. `tiny-mde.min.css` has the same content as `tiny-mde.css`, it's just minified. You will only need to use one of the files on your page. If you want to edit the CSS file, it's easier to edit `tiny-mde.css` and then minify the edited version.
238
+ - `tiny-mde.js`: Debug version of the editor. The JS file is not minified and contains a sourcemap. It is not recommended to use this in production settings, since the file is large.
239
+ - `tiny-mde.min.js`: Minified JS file for most use cases. Simply copy this to your project to use it.
240
+ - `tiny-mde.tiny.js`: Minified and stripped-down JS file. Contains only the editor itself, not the toolbar.
@@ -0,0 +1,14 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "useBuiltIns": "usage",
7
+ "targets": "> 0.25%, not dead",
8
+ "corejs": 3,
9
+ "modules": false
10
+ }
11
+ ]
12
+ ],
13
+ "exclude": "node_modules/**"
14
+ }
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>TinyMDE demo</title>
5
+ <script src="./tiny-mde.js"></script>
6
+ <link rel="stylesheet" type="text/css" href="./tiny-mde.min.css" />
7
+ <meta name="viewport" content="initial-scale=1.0">
8
+ <style type="text/css">
9
+ html, body, div {
10
+ margin: 0px;
11
+ padding: 0px;
12
+ }</style>
13
+ </head>
14
+ <body>
15
+ <div id="tinymde_commandbar"></div>
16
+ <div id="tinymde" style="height:300px; overflow-y:scroll; border:1px solid #c0c0c0"></div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,126 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>TinyMDE demo</title>
5
+ <script src="./tiny-mde.js"></script>
6
+ <link rel="stylesheet" type="text/css" href="./tiny-mde.min.css" />
7
+ <meta name="viewport" content="initial-scale=1.0">
8
+ </head>
9
+ <body>
10
+ <h1>TinyMDE demo</h1>
11
+
12
+ <div id="tinymde_commandbar"></div>
13
+ <div id="tinymde" style="height:300px; overflow-y:scroll; border:1px solid #c0c0c0">
14
+ <textarea id="txt"># Hello TinyMDE
15
+ [ref]: https://www.jefago.com
16
+ [ref link]: </this has spaces> "and a title"
17
+
18
+
19
+ Some <html> </tags> right here
20
+ <html a="b" >
21
+
22
+ More <html a="b c" d = 'e f' h = i j /> here
23
+ Comment <!-- here --> and <!-- not -- a --> comment and neither here <!---->
24
+ Test <a foo="bar" bam = 'baz <em>"</em>' _boolean zoop:33=zoop:33 /> case
25
+ Illegal HTML <__> <33> <a h*ref="hi"> <a href="hi'> <a href=hi'> < a> <a/ > <foo bar=baz bim!bop /> <a href='a'title=title>
26
+ Processing instructions <?here?> and <? h e r e ?> and <?a?> here and <??> here and <? here ? here > here ?> yup
27
+ Declarations <!DOCTYPE html> and <!DECLARE > and <!DO the OK@#( fwekof'230-2= πππ> here but <!NOT> here
28
+ A <![CDATA[section right ] freak > ing ]] here]]> but not anymore
29
+ Autolink, not inline link: [this <https://]()>
30
+ HTML, not inline link: [this <html a="]()">
31
+ More `complex` line with *one **style** within* another.
32
+ Code `ends here\` not here`
33
+ More ``difficult `code`` spans \`not code` \\"
34
+ Code `` `that starts `` with a backtick
35
+ This is [not `a ](link) right` here.
36
+
37
+ [ref]: https://www.jefago.com
38
+ [ref link]: </this has spaces> "and a title"
39
+ [ link label ]: "Only title, spaces in the label"
40
+
41
+
42
+ Autolinks
43
+ ---------
44
+ <mail@jefago.com> <https://www.jefago.com/> <a+b:>
45
+
46
+
47
+ [invalid]
48
+ [invalid][]
49
+ [in-valid][invalid]
50
+ This foo-_(bar)_ should
51
+ THis _(also)_ should
52
+ Only _underscores_ in this line
53
+ There's <html><like><tags><over><here>
54
+ A [ref link] in here.
55
+ And another [ref link][].
56
+ A valid [link to a ref][ref] here.
57
+ An invalid [ref link][nope].
58
+ An [inline link](/inline) here.
59
+ Some [inline](<links>) [inline](<link link> "title title") [inline](<link link> (title title)) [inline]( <link link> 'title \\' title') ss
60
+ [Inline]( /with invalid title text ) here.
61
+ [Inline]( </with (complex) dest> (and title text) ) here.
62
+ [Inline](<> "") link with empty delimiters
63
+ [Inline]() link completely empty
64
+ [Valid link](")))") here
65
+ [Valid link](<)))>) here
66
+ [Invalid]( ( ) here
67
+ This one [is *a](link) over* here, but not an emphasis.
68
+ Here [the [inner](one) is] the valid link.
69
+ An ![image [can](have) a](link) inside it.
70
+ This **is** a test.
71
+
72
+ *Full line emphasized*
73
+ Open ***without* close
74
+ Both __types__ of *delimiters*
75
+ __*Mixed* and matched__
76
+ __mixed*_ and *unmatched_
77
+ Close **without* open** test
78
+ ab**cd*e*f*g*h**i*j*k
79
+ Several *em* phasized *words and* some *phrases*.
80
+ Triple ***emphasis***.
81
+ One *emphasis *within* another*.
82
+
83
+ H1
84
+ ==
85
+ Hello *there*.
86
+ ~~~
87
+ Code
88
+ block
89
+ ~~~
90
+
91
+
92
+ > Quote and
93
+ Indented code block
94
+
95
+ * * *
96
+
97
+ - UL
98
+ - UL (and an empty one below)
99
+ -
100
+
101
+ 1) OL
102
+ 2) OL</textarea>
103
+ </div>
104
+ <div id="status" style="text-align:right">- : -</div>
105
+ <script>
106
+ // Create editor element, initialized to a textarea
107
+ tinyMDE = new TinyMDE.Editor({textarea: 'txt'});
108
+
109
+ // Create a command bar for that editor
110
+ cmdBar = new TinyMDE.CommandBar({
111
+ element: 'tinymde_commandbar',
112
+ editor: tinyMDE,
113
+ });
114
+
115
+ // Add a custom selection event listener
116
+ tinyMDE.addEventListener('selection', (e) => {
117
+ let st = `${e.focus ? e.focus.row : '–'} : ${e.focus ? e.focus.col : '–'}`;
118
+ for (let command in e.commandState) {
119
+ if (e.commandState[command]) st = command.concat(' ', st);
120
+ }
121
+ document.getElementById('status').innerHTML = st;
122
+ });
123
+ </script>
124
+
125
+ </body>
126
+ </html>
@@ -0,0 +1,231 @@
1
+ .TinyMDE {
2
+ background-color: #fff;
3
+ border: 1px solid var(--border);
4
+ border-bottom-left-radius: 0.25rem;
5
+ border-bottom-right-radius: 0.25rem;
6
+ color: var(--oc-gray-9);
7
+ font-size: 16px;
8
+ line-height: 1.5;
9
+ outline: none;
10
+ padding: 0.5rem 1rem;
11
+ min-height: 12rem;
12
+ }
13
+
14
+ .TMBlankLine {
15
+ height: 1.5rem;
16
+ }
17
+
18
+ .TMH1,
19
+ .TMSetextH1 {
20
+ font-size: 2rem;
21
+ line-height: 32px;
22
+ font-weight: bold;
23
+ margin-bottom: 8px;
24
+ }
25
+
26
+ .TMSetextH1 {
27
+ margin-bottom: 0px;
28
+ }
29
+
30
+ .TMSetextH1Marker {
31
+ margin-bottom: 8px;
32
+ }
33
+
34
+ .TMH2,
35
+ .TMSetextH2 {
36
+ font-size: 20px;
37
+ line-height: 28px;
38
+ font-weight: bold;
39
+ margin-bottom: 4px;
40
+ }
41
+
42
+ .TMMark_TMCode {
43
+ font-family: monospace;
44
+ font-size: 0.9em;
45
+ }
46
+
47
+ .TMFencedCodeBacktick,
48
+ .TMFencedCodeTilde,
49
+ .TMIndentedCode,
50
+ .TMCode {
51
+ font-family: monospace;
52
+ font-size: 0.9em;
53
+ background-color: #e0e0e0;
54
+ }
55
+
56
+ .TMCodeFenceBacktickOpen,
57
+ .TMCodeFenceTildeOpen {
58
+ border-bottom: 1px solid #c0c0c0;
59
+ font-family: monospace;
60
+ font-size: 0.9em;
61
+ }
62
+
63
+ .TMCodeFenceBacktickClose,
64
+ .TMCodeFenceTildeClose {
65
+ border-top: 1px solid #c0c0c0;
66
+ font-family: monospace;
67
+ font-size: 0.9em;
68
+ }
69
+
70
+ .TMInfoString {
71
+ color: #0000ff;
72
+ }
73
+
74
+ .TMCode {
75
+ border: 1px solid #c0c0c0;
76
+ border-radius: 2px;
77
+ }
78
+
79
+ .TMBlockquote {
80
+ font-style: italic;
81
+ border-left: 2px solid #c0c0c0;
82
+ padding-left: 10px;
83
+ margin-left: 10px;
84
+ }
85
+
86
+ .TMMark {
87
+ color: #a0a0a0;
88
+ }
89
+
90
+ .TMMark_TMH1,
91
+ .TMMark_TMH2 {
92
+ color: #ff8080;
93
+ }
94
+
95
+ .TMMark_TMUL,
96
+ .TMMark_TMOL {
97
+ color: #ff8080;
98
+ }
99
+
100
+ .TMImage {
101
+ text-decoration: underline;
102
+ text-decoration-color: #00ff00;
103
+ }
104
+
105
+ .TMLink {
106
+ text-decoration: underline;
107
+ text-decoration-color: #0000ff;
108
+ }
109
+
110
+ .TMLinkLabel {
111
+ text-decoration: underline;
112
+ font-family: monospace;
113
+ }
114
+
115
+ .TMLinkLabel_Definition,
116
+ .TMLinkLabel_Valid {
117
+ color: #40c040;
118
+ }
119
+
120
+ .TMLinkLabel_Invalid {
121
+ color: #ff0000;
122
+ }
123
+
124
+ .TMLinkTitle {
125
+ font-style: italic;
126
+ }
127
+
128
+ .TMLinkDestination,
129
+ .TMAutolink {
130
+ text-decoration: underline;
131
+ color: #0000ff;
132
+ }
133
+
134
+ .TMHR {
135
+ position: relative;
136
+ }
137
+
138
+ .TMHR:before {
139
+ content: "";
140
+ position: absolute;
141
+ bottom: 50%;
142
+ left: 40%;
143
+ border-bottom: 2px solid #808080;
144
+ width: 20%;
145
+ z-index: 0;
146
+ }
147
+
148
+ .TMHTML,
149
+ .TMHTMLBlock {
150
+ font-family: monospace;
151
+ font-size: 0.9em;
152
+ color: #8000ff;
153
+ }
154
+
155
+ .TMHTMLBlock {
156
+ color: #6000c0;
157
+ }
158
+
159
+ .TMCommandBar {
160
+ background-color: var(--oc-gray-1);
161
+ border: 1px solid var(--border);
162
+ border-bottom: none;
163
+ border-top-left-radius: 0.25rem;
164
+ border-top-right-radius: 0.25rem;
165
+ /* height: 24px; */
166
+ /* border:4px solid var(--oc-gray-1); */
167
+ /* box-sizing: content-box; */
168
+ display: flex;
169
+ gap: 0.25rem;
170
+ padding: 0.25rem;
171
+ -webkit-user-select: none;
172
+ user-select: none;
173
+ overflow-x: scroll;
174
+ overflow-y: hidden;
175
+ scrollbar-width: none;
176
+ -ms-overflow-style: none;
177
+ }
178
+
179
+ .TMCommandBar::-webkit-scrollbar {
180
+ display: none;
181
+ }
182
+
183
+ .TMCommandButton {
184
+ /* box-sizing: border-box; */
185
+ display: inline-block;
186
+ height: 24px;
187
+ width: 24px;
188
+ /* padding:3px; */
189
+ /* margin-right:4px; */
190
+ color: var(--oc-gray-9);
191
+ fill: var(--oc-gray-9);
192
+ text-align: center;
193
+ cursor: pointer;
194
+ vertical-align: middle;
195
+ font-size: 20px;
196
+ line-height: 18px;
197
+ font-family: sans-serif;
198
+ }
199
+
200
+ .TMCommandDivider {
201
+ /* box-sizing: content-box; */
202
+ height: 24px;
203
+ margin: 0 8px;
204
+ width: 0px;
205
+ border-left: 2px solid var(--border);
206
+ }
207
+
208
+ .TMCommandButton_Active {
209
+ font-weight: bold;
210
+ color: var(--primary-9);
211
+ background-color: var(--primary-2);
212
+ fill: var(--primary-9);
213
+ }
214
+
215
+ .TMCommandButton_Inactive {
216
+ background-color: var(--oc-gray-1);
217
+ }
218
+
219
+ .TMCommandButton_Disabled {
220
+ color: var(--oc-gray-7);
221
+ fill: var(--oc-gray-7);
222
+ }
223
+
224
+ @media (hover: hover) {
225
+ .TMCommandButton_Active:hover,
226
+ .TMCommandButton_Disabled:hover,
227
+ .TMCommandButton_Inactive:hover {
228
+ background-color: var(--primary-1);
229
+ fill: var(--oc-gray-9);
230
+ }
231
+ }