mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
Markdown toolbar: the Markdown box has a toolbar like the rich text editor's - headings, bold, italic, strikethrough, link, bulleted and numbered lists, checklist, quote, code, code block, table, line and picture - acting on the selection or the cursor's line and off again when already applied, with Ctrl+B, Ctrl+I and Ctrl+K, Enter continuing or ending a list, and changes undoable with Ctrl+Z; 26.12.3 changelog entries
This commit is contained in:
@@ -16,6 +16,7 @@ Update from Maintenance > Update as usual - this release has two database change
|
||||
- Admin > Settings > Security has a Passkeys switch, on. Off, passkeys already added are kept but don't sign anyone in until it's on again.
|
||||
- Resetting an agent's MFA (Admin > Users) or turning off a contact's two-step sign-in also removes their passkeys, for a lost or replaced device, and so do archiving an agent and resetting every agent's password. Agents and contacts are emailed when a passkey is added to or removed from their account, failed passkey sign-ins count towards the same lockout as passwords, and both show in the sign-in log.
|
||||
- Documents in Markdown: a document can be written in Markdown instead of the rich text editor - pick Markdown above the editor in New Document or Edit, write in the box, and Preview shows how it will look. Headings, lists, checklists, tables, code, quotes and links all work, and a picture pasted or dropped into the box is added to the document. Switching between Markdown and rich text converts what is already written, either way; switching to Markdown says when some formatting, such as colours or merged table cells, stays as HTML in it. New Document starts in whichever you used last.
|
||||
- The Markdown box has a toolbar like the rich text editor's: headings, bold, italic, struck text, link, bulleted and numbered lists, checklist, quote, code, code block, table, line and picture - each on what's picked or where the cursor is, and off again when it's already there. Ctrl+B, Ctrl+I and Ctrl+K (a link) work too, and Enter in a list, checklist or quote starts the next item, or on an empty one ends the list. Changes can be undone with Ctrl+Z. The ? at its end shows the Markdown for each.
|
||||
- Markdown files: the menu beside Upload on a client's Files has Import Markdown Files, which makes a document from each .md file picked, named by the heading it starts with or its file name. A document's page has a Markdown button beside PDF, which downloads it as a .md file - rich text documents too.
|
||||
- Markdown pasted into a document's rich text editor - copied from GitHub, VS Code, Obsidian or an AI chat - goes in as formatting. Ctrl+Shift+V pastes it as it is.
|
||||
- A document's page is easier to read: headings in proportion to the text with room between sections, and tables, code and quotes that look part of it. Under its name are its folder, its template, Markdown when it's written in it, and its review - due, or when it's next due - whose menu has Mark Reviewed and how often. The buttons are Edit, Share and Export (PDF, Markdown or Print), with the rest in the ⋮ menu, now including Template. Beside it, Contents marks the section you're reading, and Linked, Versions and History are tabs of one card: Linked shows each kind of record with its count, opening to the list.
|
||||
@@ -36,6 +37,7 @@ Update from Maintenance > Update as usual - this release has two database change
|
||||
- functions/markdown.php: markdownToHtml() (league/commonmark 2.10 GitHubFlavoredMarkdownConverter, raw HTML allowed and then passed through documentHtmlPurify(), task boxes drawn as spans, tables given the app's table classes, all in div.itflow-markdown), htmlToMarkdown() (league/html-to-markdown 5.2 with tables; tables with merged cells and sized pictures kept as HTML), markdownSaveImages(), markdownImportSplit() (front matter title, leading heading) and documentMarkdownFile(). Both libraries and their dependencies (league/config, dflydev/dot-access-data, nette/schema, nette/utils, psr/event-dispatcher) are in libs/vendor through libs/composer.json.
|
||||
- agent/ajax.php markdown_to_html and html_to_markdown back js/document_markdown.js (loaded in includes/footer.php): the form's Rich text / Markdown switch, Write / Preview, pasted pictures held as pasted:N until Preview or Save, the remembered format for New Document, and the Markdown paste handler for .tinymce and .tinymce-page editors. New handlers export_document_markdown and import_markdown_documents in agent/post/document.php; versions, version restore, documentCopy() and the API's document create and update carry the Markdown (document_markdown in the API), and the API's create and update escape each value once.
|
||||
- The document page (agent/document.php): .itflow-prose in css/itflow_custom.css styles what it says; linkGroupsHtml() (functions/links.php) takes $compact - groups that open to their rows, open already with five links or fewer, no Link per group or empty groups - and $total; js/document_contents.js marks the section in view and opens a tab of the side card from a[data-document-tab].
|
||||
- The Markdown box's toolbar ([data-markdown-toolbar] in agent/modals/document/document_form.php, data-md on each button) and its keys are in js/document_markdown.js; edits go in with document.execCommand('insertText'), falling back to setRangeText(), so the browser's undo keeps them.
|
||||
|
||||
## [26.12.2]
|
||||
|
||||
|
||||
@@ -87,15 +87,44 @@ $document_format_uid = bin2hex(random_bytes(4));
|
||||
|
||||
<?php if ($document_markdown_ready) { ?>
|
||||
<div data-editor-markdown<?= $document_is_markdown ? '' : ' hidden' ?>>
|
||||
<div class="d-flex flex-wrap align-items-end border-bottom">
|
||||
<ul class="nav nav-tabs border-bottom-0 itflow-markdown-tabs" role="tablist">
|
||||
<li class="nav-item"><button type="button" class="nav-link active" data-markdown-tab="write"><i class="fas fa-fw fa-pen me-1"></i>Write</button></li>
|
||||
<li class="nav-item"><button type="button" class="nav-link" data-markdown-tab="preview"><i class="fas fa-fw fa-eye me-1"></i>Preview</button></li>
|
||||
</ul>
|
||||
<button type="button" class="btn btn-link btn-sm ms-auto mb-1 text-decoration-none" data-bs-toggle="collapse" data-bs-target="#documentMarkdownHelp<?= $document_format_uid ?>" aria-expanded="false"><i class="far fa-fw fa-question-circle me-1"></i>Markdown help</button>
|
||||
<ul class="nav nav-tabs itflow-markdown-tabs" role="tablist">
|
||||
<li class="nav-item"><button type="button" class="nav-link active" data-markdown-tab="write"><i class="fas fa-fw fa-pen me-1"></i>Write</button></li>
|
||||
<li class="nav-item"><button type="button" class="nav-link" data-markdown-tab="preview"><i class="fas fa-fw fa-eye me-1"></i>Preview</button></li>
|
||||
</ul>
|
||||
<!-- What the rich text editor's toolbar does, as Markdown - on what is picked, or where the cursor is (js/document_markdown.js) -->
|
||||
<div class="itflow-markdown-toolbar" role="toolbar" aria-label="Formatting" data-markdown-toolbar>
|
||||
<div class="dropdown">
|
||||
<button type="button" class="itflow-markdown-button dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Heading"><i class="fas fa-fw fa-heading"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<button type="button" class="dropdown-item" data-md="h1"><span class="fs-5 fw-semibold">Heading 1</span></button>
|
||||
<button type="button" class="dropdown-item" data-md="h2"><span class="fs-6 fw-semibold">Heading 2</span></button>
|
||||
<button type="button" class="dropdown-item" data-md="h3"><span class="small fw-semibold">Heading 3</span></button>
|
||||
<button type="button" class="dropdown-item" data-md="paragraph">Normal text</button>
|
||||
</div>
|
||||
</div>
|
||||
<span class="itflow-markdown-toolbar-gap"></span>
|
||||
<button type="button" class="itflow-markdown-button" data-md="bold" title="Bold (Ctrl+B)" aria-label="Bold"><i class="fas fa-fw fa-bold"></i></button>
|
||||
<button type="button" class="itflow-markdown-button" data-md="italic" title="Italic (Ctrl+I)" aria-label="Italic"><i class="fas fa-fw fa-italic"></i></button>
|
||||
<button type="button" class="itflow-markdown-button" data-md="strike" title="Strikethrough" aria-label="Strikethrough"><i class="fas fa-fw fa-strikethrough"></i></button>
|
||||
<span class="itflow-markdown-toolbar-gap"></span>
|
||||
<button type="button" class="itflow-markdown-button" data-md="link" title="Link (Ctrl+K)" aria-label="Link"><i class="fas fa-fw fa-link"></i></button>
|
||||
<span class="itflow-markdown-toolbar-gap"></span>
|
||||
<button type="button" class="itflow-markdown-button" data-md="bullets" title="Bulleted list" aria-label="Bulleted list"><i class="fas fa-fw fa-list-ul"></i></button>
|
||||
<button type="button" class="itflow-markdown-button" data-md="numbers" title="Numbered list" aria-label="Numbered list"><i class="fas fa-fw fa-list-ol"></i></button>
|
||||
<button type="button" class="itflow-markdown-button" data-md="tasks" title="Checklist" aria-label="Checklist"><i class="fas fa-fw fa-tasks"></i></button>
|
||||
<span class="itflow-markdown-toolbar-gap"></span>
|
||||
<button type="button" class="itflow-markdown-button" data-md="quote" title="Quote" aria-label="Quote"><i class="fas fa-fw fa-quote-right"></i></button>
|
||||
<button type="button" class="itflow-markdown-button" data-md="code" title="Code" aria-label="Code"><i class="fas fa-fw fa-code"></i></button>
|
||||
<button type="button" class="itflow-markdown-button" data-md="codeblock" title="Code block" aria-label="Code block"><i class="fas fa-fw fa-file-code"></i></button>
|
||||
<span class="itflow-markdown-toolbar-gap"></span>
|
||||
<button type="button" class="itflow-markdown-button" data-md="table" title="Table" aria-label="Table"><i class="fas fa-fw fa-table"></i></button>
|
||||
<button type="button" class="itflow-markdown-button" data-md="line" title="Line across" aria-label="Line across"><i class="fas fa-fw fa-minus"></i></button>
|
||||
<button type="button" class="itflow-markdown-button" data-md="picture" title="Picture" aria-label="Picture"><i class="fas fa-fw fa-image"></i></button>
|
||||
<input type="file" class="d-none" accept="image/png,image/jpeg,image/gif,image/webp" multiple data-markdown-picture tabindex="-1" aria-hidden="true">
|
||||
<button type="button" class="itflow-markdown-button ms-auto" data-bs-toggle="collapse" data-bs-target="#documentMarkdownHelp<?= $document_format_uid ?>" aria-expanded="false" title="Markdown help" aria-label="Markdown help"><i class="far fa-fw fa-question-circle"></i></button>
|
||||
</div>
|
||||
<div class="collapse" id="documentMarkdownHelp<?= $document_format_uid ?>">
|
||||
<div class="table-responsive border border-top-0 small">
|
||||
<div class="table-responsive border border-top-0 small itflow-markdown-help-box">
|
||||
<table class="table table-sm mb-0 itflow-markdown-help">
|
||||
<tbody>
|
||||
<tr><td><code># Heading</code> <code>## Smaller</code></td><td>Headings</td><td><code>**bold**</code> <code>_italic_</code> <code>~~struck~~</code></td><td>Text</td></tr>
|
||||
|
||||
@@ -5656,6 +5656,44 @@ tr:hover .itflow-files-rename,
|
||||
padding: .35rem .8rem;
|
||||
font-size: .875rem;
|
||||
}
|
||||
/* Its toolbar - the rich text editor's, as Markdown */
|
||||
.itflow-markdown-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: .125rem;
|
||||
padding: .3rem .4rem;
|
||||
border: 1px solid var(--bs-border-color);
|
||||
border-top: 0;
|
||||
background-color: var(--bs-body-bg);
|
||||
}
|
||||
.itflow-markdown-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 2rem;
|
||||
height: 2rem;
|
||||
padding: 0 .35rem;
|
||||
border: 0;
|
||||
border-radius: .3rem;
|
||||
background: none;
|
||||
color: var(--bs-body-color);
|
||||
}
|
||||
.itflow-markdown-button:hover,
|
||||
.itflow-markdown-button:focus-visible,
|
||||
.itflow-markdown-button[aria-expanded="true"] {
|
||||
background-color: var(--bs-tertiary-bg);
|
||||
color: var(--bs-emphasis-color);
|
||||
}
|
||||
.itflow-markdown-button.dropdown-toggle::after {
|
||||
margin-left: .2rem;
|
||||
}
|
||||
.itflow-markdown-toolbar-gap {
|
||||
width: 1px;
|
||||
height: 1.25rem;
|
||||
margin: 0 .25rem;
|
||||
background-color: var(--bs-border-color);
|
||||
}
|
||||
.itflow-markdown-input {
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
* Documents written in Markdown (agent/modals/document/document_form.php, functions/markdown.php).
|
||||
*
|
||||
* A document's form has both editors - the rich text one (TinyMCE, js/app.js) and a plain box for
|
||||
* Markdown with Write and Preview - and shows the one it is written in. Switching converts what is
|
||||
* Markdown with Write and Preview - and shows the one it is written in. The Markdown box has a
|
||||
* toolbar like the rich text editor's (headings, bold, italic, struck, link, lists, checklist,
|
||||
* quote, code, table, line, picture), Ctrl+B, Ctrl+I and Ctrl+K, and Enter in a list starts the
|
||||
* next item. Switching converts what is
|
||||
* written into the other, through agent/ajax.php, so nothing has to be typed again; switching to
|
||||
* Markdown says when some of it stays as HTML, or alignment was dropped.
|
||||
*
|
||||
@@ -82,6 +85,7 @@
|
||||
var rich = box.querySelector('[data-editor-rich]');
|
||||
var markdown = box.querySelector('[data-editor-markdown]');
|
||||
var note = box.querySelector('[data-format-note]');
|
||||
var toolbar = box.querySelector('[data-markdown-toolbar]');
|
||||
var radios = box.querySelectorAll('input[name="format"]');
|
||||
if (!form || !input || !rich || !markdown) {
|
||||
return;
|
||||
@@ -175,12 +179,239 @@
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* The toolbar, and Ctrl+B, Ctrl+I and Ctrl+K - each on what is picked, or where the cursor
|
||||
* is. Changes go in as typing would, so Ctrl+Z takes them back.
|
||||
*/
|
||||
function put(start, end, text, selectStart, selectEnd) {
|
||||
input.focus();
|
||||
input.setSelectionRange(start, end);
|
||||
if (text === '' && start === end) {
|
||||
input.setSelectionRange(selectStart, selectEnd);
|
||||
return;
|
||||
}
|
||||
var typed = false;
|
||||
try {
|
||||
typed = text === '' ? document.execCommand('delete') : document.execCommand('insertText', false, text);
|
||||
} catch (e) {
|
||||
typed = false;
|
||||
}
|
||||
if (!typed || input.value.slice(start, start + text.length) !== text) {
|
||||
input.setRangeText(text, start, end, 'end');
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
}
|
||||
input.setSelectionRange(selectStart, selectEnd);
|
||||
}
|
||||
|
||||
// Around what is picked: **bold** - or taken off again when it is already there
|
||||
function wrap(before, after, example) {
|
||||
var v = input.value;
|
||||
var start = input.selectionStart;
|
||||
var end = input.selectionEnd;
|
||||
var picked = v.slice(start, end);
|
||||
if (picked.length >= before.length + after.length && picked.indexOf(before) === 0 && picked.slice(-after.length) === after) {
|
||||
var bare = picked.slice(before.length, picked.length - after.length);
|
||||
put(start, end, bare, start, start + bare.length);
|
||||
return;
|
||||
}
|
||||
if (v.slice(start - before.length, start) === before && v.slice(end, end + after.length) === after) {
|
||||
put(start - before.length, end + after.length, picked, start - before.length, end - before.length);
|
||||
return;
|
||||
}
|
||||
// Spaces picked at either end stay outside, as Markdown wants
|
||||
var lead = picked.match(/^\s*/)[0];
|
||||
var trail = picked.slice(lead.length).match(/\s*$/)[0];
|
||||
var text = picked.slice(lead.length, picked.length - trail.length) || example;
|
||||
put(start, end, lead + before + text + after + trail, start + lead.length + before.length, start + lead.length + before.length + text.length);
|
||||
}
|
||||
|
||||
// The whole lines the cursor or what is picked is on: [start, end]
|
||||
function lineRange() {
|
||||
var v = input.value;
|
||||
var start = v.lastIndexOf('\n', input.selectionStart - 1) + 1;
|
||||
var to = input.selectionEnd > input.selectionStart && v[input.selectionEnd - 1] === '\n' ? input.selectionEnd - 1 : input.selectionEnd;
|
||||
var end = v.indexOf('\n', to);
|
||||
return [start, end === -1 ? v.length : end];
|
||||
}
|
||||
|
||||
var MARKS = {
|
||||
bullets: /^(\s*)[-*+] (?!\[[ xX]\] )/,
|
||||
numbers: /^(\s*)\d+[.)] /,
|
||||
tasks: /^(\s*)[-*+] \[[ xX]\] /,
|
||||
quote: /^(\s*)> ?/
|
||||
};
|
||||
var ANY_LIST = /^(\s*)([-*+] \[[ xX]\] |[-*+] |\d+[.)] )/;
|
||||
|
||||
// Each line made a list item, a checklist item or a quote - or back to text when all of them were
|
||||
function prefixLines(kind) {
|
||||
var range = lineRange();
|
||||
var lines = input.value.slice(range[0], range[1]).split('\n');
|
||||
var filled = lines.filter(function (line) { return line.trim() !== ''; });
|
||||
var all = filled.length > 0 && filled.every(function (line) { return MARKS[kind].test(line); });
|
||||
var number = 0;
|
||||
var out = lines.map(function (line) {
|
||||
if (all) {
|
||||
return line.replace(MARKS[kind], '$1');
|
||||
}
|
||||
if (line.trim() === '' && lines.length > 1) {
|
||||
return line;
|
||||
}
|
||||
var indent = line.match(/^\s*/)[0];
|
||||
var text = kind === 'quote' ? line.replace(MARKS.quote, '$1').slice(indent.length) : line.replace(ANY_LIST, '$1').slice(indent.length);
|
||||
number += 1;
|
||||
var mark = kind === 'bullets' ? '- ' : kind === 'numbers' ? number + '. ' : kind === 'tasks' ? '- [ ] ' : '> ';
|
||||
return indent + mark + text;
|
||||
}).join('\n');
|
||||
if (lines.length === 1) {
|
||||
put(range[0], range[1], out, range[0] + out.length, range[0] + out.length);
|
||||
} else {
|
||||
put(range[0], range[1], out, range[0], range[0] + out.length);
|
||||
}
|
||||
}
|
||||
|
||||
// The lines made a heading of that level - again, or Normal text, back to text
|
||||
function heading(level) {
|
||||
var range = lineRange();
|
||||
var lines = input.value.slice(range[0], range[1]).split('\n');
|
||||
var filled = lines.filter(function (line) { return line.trim() !== ''; });
|
||||
var same = level > 0 && filled.length > 0 && filled.every(function (line) { return new RegExp('^#{' + level + '} ').test(line); });
|
||||
var out = lines.map(function (line) {
|
||||
var text = line.replace(/^#{1,6}\s+/, '');
|
||||
if (level === 0 || same || (line.trim() === '' && lines.length > 1)) {
|
||||
return text;
|
||||
}
|
||||
return '#'.repeat(level) + ' ' + text;
|
||||
}).join('\n');
|
||||
put(range[0], range[1], out, range[0] + out.length, range[0] + out.length);
|
||||
}
|
||||
|
||||
// Something that goes on lines of its own - a blank line before and after it
|
||||
function block(text, selectFrom, selectTo) {
|
||||
var v = input.value;
|
||||
var start = input.selectionStart;
|
||||
var end = input.selectionEnd;
|
||||
var before = v.slice(0, start);
|
||||
var gap = before === '' || /\n\n$/.test(before) ? '' : (/\n$/.test(before) ? '\n' : '\n\n');
|
||||
var after = v.slice(end);
|
||||
var tail = after === '' || /^\n\n/.test(after) ? '\n' : (/^\n/.test(after) ? '\n' : '\n\n');
|
||||
put(start, end, gap + text + tail, start + gap.length + selectFrom, start + gap.length + selectTo);
|
||||
}
|
||||
|
||||
var actions = {
|
||||
h1: function () { heading(1); },
|
||||
h2: function () { heading(2); },
|
||||
h3: function () { heading(3); },
|
||||
paragraph: function () { heading(0); },
|
||||
bold: function () { wrap('**', '**', 'bold text'); },
|
||||
italic: function () { wrap('_', '_', 'italic text'); },
|
||||
strike: function () { wrap('~~', '~~', 'struck text'); },
|
||||
code: function () {
|
||||
var picked = input.value.slice(input.selectionStart, input.selectionEnd);
|
||||
if (picked.indexOf('\n') !== -1) {
|
||||
actions.codeblock();
|
||||
} else {
|
||||
wrap('`', '`', 'code');
|
||||
}
|
||||
},
|
||||
codeblock: function () {
|
||||
var picked = input.value.slice(input.selectionStart, input.selectionEnd).replace(/\n$/, '');
|
||||
block('```\n' + picked + '\n```', 4, 4 + picked.length);
|
||||
},
|
||||
link: function () {
|
||||
var start = input.selectionStart;
|
||||
var end = input.selectionEnd;
|
||||
var picked = input.value.slice(start, end);
|
||||
if (/^(https?:\/\/|mailto:)\S+$/i.test(picked)) {
|
||||
put(start, end, '[](' + picked + ')', start + 1, start + 1);
|
||||
} else {
|
||||
var words = picked || 'link text';
|
||||
var text = '[' + words + '](https://)';
|
||||
// The address to type over - or the words, when there were none
|
||||
var at = picked ? start + words.length + 3 : start + 1;
|
||||
put(start, end, text, at, picked ? at + 8 : at + words.length);
|
||||
}
|
||||
},
|
||||
bullets: function () { prefixLines('bullets'); },
|
||||
numbers: function () { prefixLines('numbers'); },
|
||||
tasks: function () { prefixLines('tasks'); },
|
||||
quote: function () { prefixLines('quote'); },
|
||||
table: function () {
|
||||
block('| Column 1 | Column 2 |\n|---|---|\n| | |', 2, 10);
|
||||
},
|
||||
line: function () {
|
||||
block('---', 3, 3);
|
||||
},
|
||||
picture: function () {
|
||||
var picker = box.querySelector('[data-markdown-picture]');
|
||||
if (picker) {
|
||||
picker.click();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (toolbar) {
|
||||
toolbar.addEventListener('click', function (e) {
|
||||
var button = e.target.closest('[data-md]');
|
||||
if (!button || !actions[button.getAttribute('data-md')]) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
actions[button.getAttribute('data-md')]();
|
||||
});
|
||||
// Keeps what is picked in the box picked while a button is pressed
|
||||
toolbar.addEventListener('mousedown', function (e) {
|
||||
if (e.target.closest('.itflow-markdown-button[data-md]')) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
var picker = box.querySelector('[data-markdown-picture]');
|
||||
if (picker) {
|
||||
picker.addEventListener('change', function () {
|
||||
Array.prototype.forEach.call(picker.files || [], addPicture);
|
||||
picker.value = '';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
input.addEventListener('keydown', function (e) {
|
||||
var key = (e.key || '').toLowerCase();
|
||||
if ((e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey && (key === 'b' || key === 'i' || key === 'k')) {
|
||||
e.preventDefault();
|
||||
actions[key === 'b' ? 'bold' : key === 'i' ? 'italic' : 'link']();
|
||||
return;
|
||||
}
|
||||
// Enter in a list, checklist or quote starts the next item - and on an empty one, ends it
|
||||
if (e.key !== 'Enter' || e.shiftKey || e.ctrlKey || e.metaKey || e.altKey || e.isComposing || input.selectionStart !== input.selectionEnd) {
|
||||
return;
|
||||
}
|
||||
var v = input.value;
|
||||
var at = input.selectionStart;
|
||||
var lineStart = v.lastIndexOf('\n', at - 1) + 1;
|
||||
var lineEnd = v.indexOf('\n', at);
|
||||
var line = v.slice(lineStart, lineEnd === -1 ? v.length : lineEnd);
|
||||
var m = line.match(/^(\s*)([-*+] \[[ xX]\] |[-*+] |(\d+)([.)]) |> )/);
|
||||
if (!m || at < lineStart + m[0].length) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
// An empty item ends the list, with a blank line after it, so what comes next isn't part of it
|
||||
if (line.slice(m[0].length).trim() === '') {
|
||||
put(lineStart, lineStart + line.length, '\n', lineStart + 1, lineStart + 1);
|
||||
return;
|
||||
}
|
||||
var mark = m[3] ? m[1] + (parseInt(m[3], 10) + 1) + m[4] + ' ' : m[1] + m[2].replace(/\[[xX]\]/, '[ ]');
|
||||
put(at, at, '\n' + mark, at + 1 + mark.length, at + 1 + mark.length);
|
||||
});
|
||||
|
||||
// Write and Preview
|
||||
function showTab(which) {
|
||||
box.querySelectorAll('[data-markdown-tab]').forEach(function (tab) {
|
||||
tab.classList.toggle('active', tab.getAttribute('data-markdown-tab') === which);
|
||||
});
|
||||
input.hidden = which === 'preview';
|
||||
if (toolbar) {
|
||||
toolbar.hidden = which === 'preview';
|
||||
}
|
||||
preview.hidden = which !== 'preview';
|
||||
if (which !== 'preview') {
|
||||
input.focus();
|
||||
|
||||
Reference in New Issue
Block a user