EditHelp
Automatic insertion of start-of-line wiki markups, brackets, keyboard shortcuts.
Description
Start-of-line markup auto-insertion
When a user writes wiki markup, a bulleted list is entered with the sign * before the line. When the user presses "Enter/Return", the script will examine the line and if it starts with *, it will automatically insert a * before the new line, similar to how office suites insert list items. This way the user needs to simply type the text of the new list item.
In a similar fashion, the following start-of-line markups are recognized and re-inserted automatically when the user presses "Enter":
*,**,***, ... unordered/bulleted list#,##,###, ... numbered list: :definition list(space) preformatted text->,-->,-<,--<, ... indented and hanging text||simple table row- Additionally, it inserts the characters "
-" (minus) and ">" (greater than, quote) on the new line if the current line starts with them.
Press Enter a second time to remove the auto-inserted markup (if there is nothing on the line).
The above automatic insertions are particularly useful on touch screen devices where it is more difficult to type punctuation.
Demo: the recipe is enabled on any page on pmwiki.org, you can test it for example in Main.WikiSandbox.
These edit help functions were first written for a "Structured sections editor" recipe in February 2016 (currently abandoned), but felt so natural and easy to use (a user described them as "exhilarating/addictive"), that I decided to port them to the regular PmWiki text editor. Enjoy!
Keyboard shortcuts
As of 2026-04-17 I recommend testing shortcuts with the pre-release, or here on pmwiki.org, as work is ongoing with fast changes.
Additionally, the following keyboard shortcuts might be appreciated by advanced editors with full keyboards:
| Description | Inserts* | GNU/Linux, Windows | MacOS X |
|---|---|---|---|
| Bold text (see Talk page) | '''...''' | Ctrl+B | Cmd+B |
| Cycle** Italics, bold, bold-italic, code | ''...'', '''...''', '''''...''''', @@...@@ | Ctrl+I | Cmd+I |
| Cycle** Links (press multiple times as needed) (if links are selected, removes double brackets) | [[...]], [[#...]], [[!...]], [[~...]], [[(Attach:)...]], [[(mailto:)...]]... | Ctrl+K | Cmd+K |
| Cycle** WikiStyle | %%...%%, %rfloat%...%%, %note%...%%, >><<...>><<, >>frame<<...>><< | Ctrl+Shift+S | Cmd+Shift+S |
| Cycle** Directive/MarkupExpression | (:...:), {(...)} | Ctrl+Shift+D | Cmd+Shift+D |
| Cycle** Variable (Page, Text, Template) | {*$...}, {*$:...}, {$...}, {$:...},{$$...}, {=$...}, {=$:...} | Ctrl+Shift+V | Cmd+Shift+V |
| Cycle** Escape text/code sequences | @@...@@, [=...=], [@...@],%hlt%[@...@]%%, %pmhlt%[@...@]%% | Ctrl+E | Cmd+E |
| Non-breakable space (if text is selected, toggles space- in it) | | Ctrl+Space | Cmd+Space |
| Author signature | ~~~~ | Ctrl+Shift+Enter | Cmd+Shift+Enter |
| Line break "clear both" | [[<<]] | Ctrl+Enter | Cmd+Enter |
| Line break (if text is selected, toggles \\ on-off) | \\ | Shift+Enter | Shift+Enter |
| Join lines (also removes end-of line backslashes \\) | (selection or next line) | Ctrl+J | Cmd+J |
| Cycle** lower/Title/UPPER case | (selection) | Ctrl+Shift+L | Cmd+Shift+L |
| Delete lines | (selected lines) | Ctrl+Shift+J | Cmd+Shift+J |
| Move lines up | (selected lines) | Ctrl+Shift+ArrowUp | Cmd+Shift+ArrowUp |
| Move lines down | (selected lines) | Ctrl+Shift+ArrowDown | Cmd+Shift+ArrowDown |
Jump to previous !!Heading | - | Ctrl+ArrowUp | Cmd+ArrowUp |
Jump to next !!Heading | - | Ctrl+ArrowDown | Cmd+ArrowDown |
Jump to previous [[#anchor]] | - | Alt+ArrowUp | Option+ArrowUp |
Jump to next [[#anchor]] | - | Alt+ArrowDown | Option+ArrowDown |
[*] Here "..." means the cursor or the selected text.
[**] Cycle = Press multiple times until you reach the desired result. Press Ctrl+Z to cycle back to the previous insertion.
Eventually these will be configurable both per wiki and per-user.
Auto-Brackets
# enable start-of-line auto-insert, keyboard shortcuts
$EnableEditAutoText = 1;
# if NO text is selected, when typing opening bracket,
# insert opening and closing brackets around the cursor (optional):
$EditAutoBrackets['cursor'] = '"{[('; # insert "", {}, [], or ()
# if text IS selected, when typing opening bracket, wrap the
# selected text in the opening and closing brackets (optional):
$EditAutoBrackets['selection'] = '\'`~"{[(-+@^%_=<>';
If $EditAutoBrackets['cursor'] is enabled, typing an opening character automatically inserts the corresponding closing character after the cursor.
If $EditAutoBrackets['selection'] is enabled and text is selected, typing the opening character wraps the selection with the opening and closing characters.
The opening and closing characters are the same, except for these:
( inserts ()
[ inserts []
{ inserts {}
< inserts <> (useful for HTML)
> inserts >< (useful for WikiStyles)
Eventually these will be configurable both per wiki and per-user.
Installation
For PmWiki 2.2.119 or newer, add to config.php:
$EnableEditAutoText = 1;
Since PmWiki 2.4.0, you can enable auto-brackets:
$EditAutoBrackets = array('('=>')', '['=>']', '{'=>'}', '"'=>'"');
Since PmWiki 2.5.9, auto-brackets definitions changed, see above.
Older PmWiki versions (only an older version is available):
- Place edithelp.js in your pmwiki/pub directory.
- Add to local/(farm)config.php such a line:
if($action == 'edit') $HTMLFooterFmt['edithelp'] = '<script type="text/javascript" src="$FarmPubDirUrl/edithelp.js"></script>';
Note, only start-of-line markup insertion is supported.
Notes
- A recent browser with JavaScript enabled is needed for the recipe to work.
- The recipe is likely incompatible with CodeMirror or with any of the WYSIWYG attempts.
- It does work with PmSyntax.
- Should work with SectionEdit version 20230302 or newer.
Change log / Release notes
- 20191003 added to PmWiki 2.2.119. For subsequent updates please see ChangeLog.
- 20160317 First public release, ready to be tested.
See also
- PmSyntax (Syntax highlighting for the PmWiki documentation and edit form) is compatible with this recipe.
- The CodeMirror recipe also provides automatic insertion of list items, and more. Unfortunately, select-copy and middle-click-paste does not work with it so I cannot use it.
- Worse (is better) Simple WYSIWYG editing for PmWiki
- JsEditToolbar toolbar for the edit form with regex find & replace tools
Contributors
Recipe written and maintained by Petko.
Comments
See discussion at EditHelp-Talk
User notes : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.