mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
Documents in Markdown: a document can be written in Markdown with Write and Preview or in the rich text editor and switched either way, pictures pasted or dropped into the Markdown are kept as files, New Document starts in the way last used, Import Markdown Files beside Upload makes a document from each .md file, a Markdown button beside PDF downloads a document as a .md file, and Markdown pasted into a document's rich text editor goes in as formatting; versions, restore, copy and the API carry the Markdown, and the API's document create and update no longer escape values twice; database 4.2.3 adds documents.document_markdown and document_versions.document_version_markdown, and league/commonmark 2.10 and league/html-to-markdown 5.2 are added to libs/vendor through composer; 26.12.3 changelog entries
This commit is contained in:
@@ -8,8 +8,19 @@
|
||||
* Expects $document_form_mode ('add' or 'edit'), $client_id, and the
|
||||
* escaped $document_name, $document_description, $document_content,
|
||||
* $document_folder_id, $document_client_visible - and $document_id when
|
||||
* editing, for its tags.
|
||||
* editing, for its tags. $document_markdown is what a Markdown document says,
|
||||
* raw - unset or null for one in the rich text editor - and with
|
||||
* $document_format_remember (New Document) it starts in the way of writing the
|
||||
* agent used last.
|
||||
*
|
||||
* It is written in the rich text editor or in Markdown, picked above the editor
|
||||
* and switched either way as it is written (js/document_markdown.js); the form
|
||||
* posts format, with content or markdown.
|
||||
*/
|
||||
|
||||
$document_markdown_ready = documentMarkdownReady();
|
||||
$document_is_markdown = $document_markdown_ready && isset($document_markdown) && $document_markdown !== null;
|
||||
$document_format_uid = bin2hex(random_bytes(4));
|
||||
?>
|
||||
|
||||
<div class="row g-3 mb-3">
|
||||
@@ -57,7 +68,58 @@
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<textarea class="form-control tinymce" name="content" aria-label="Content"><?= $document_content ?></textarea>
|
||||
<div data-document-editors<?= !empty($document_format_remember) ? ' data-format-remember' : '' ?>>
|
||||
<?php if ($document_markdown_ready) { ?>
|
||||
<div class="d-flex flex-wrap align-items-center gap-2 mb-2">
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Write it in">
|
||||
<input type="radio" class="btn-check" name="format" value="html" id="documentFormatRich<?= $document_format_uid ?>" autocomplete="off" <?= $document_is_markdown ? '' : 'checked' ?>>
|
||||
<label class="btn btn-outline-secondary" for="documentFormatRich<?= $document_format_uid ?>"><i class="fas fa-fw fa-font me-1"></i>Rich text</label>
|
||||
<input type="radio" class="btn-check" name="format" value="markdown" id="documentFormatMarkdown<?= $document_format_uid ?>" autocomplete="off" <?= $document_is_markdown ? 'checked' : '' ?>>
|
||||
<label class="btn btn-outline-secondary" for="documentFormatMarkdown<?= $document_format_uid ?>"><i class="fab fa-fw fa-markdown me-1"></i>Markdown</label>
|
||||
</div>
|
||||
<span class="small" data-format-note></span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div data-editor-rich<?= $document_is_markdown ? ' hidden' : '' ?>>
|
||||
<textarea class="form-control tinymce" name="content" aria-label="Content"><?= $document_content ?></textarea>
|
||||
</div>
|
||||
|
||||
<?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>
|
||||
</div>
|
||||
<div class="collapse" id="documentMarkdownHelp<?= $document_format_uid ?>">
|
||||
<div class="table-responsive border border-top-0 small">
|
||||
<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>
|
||||
<tr><td><code>- item</code> <code>1. item</code></td><td>Lists - indent for a list inside one</td><td><code>- [ ] to do</code> <code>- [x] done</code></td><td>Checklist</td></tr>
|
||||
<tr><td><code>[words](https://...)</code></td><td>Link</td><td><code>`code`</code>, or <code>```</code> on the lines above and below</td><td>Code</td></tr>
|
||||
<tr><td><code>| A | B |</code> then <code>|---|---|</code></td><td>Table</td><td><code>> quote</code> <code>---</code></td><td>Quote, line</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<textarea class="form-control font-monospace itflow-markdown-input" name="markdown" rows="18" aria-label="Content, in Markdown" data-markdown-input placeholder="# A heading Write here in Markdown - paste or drop a picture to add it."><?= isset($document_markdown) && $document_markdown !== null ? escapeHtml($document_markdown) : '' ?></textarea>
|
||||
<div class="itflow-markdown-preview itflow-document-body border border-top-0 rounded-bottom" data-markdown-preview hidden></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($document_markdown_ready) { ?>
|
||||
<script>
|
||||
// js/document_markdown.js - on a page of its own this runs before that file has loaded, and it takes the form up then
|
||||
(window.itflowDocumentForms = window.itflowDocumentForms || []).push(document.currentScript.previousElementSibling);
|
||||
if (window.itflowDocumentFormat) {
|
||||
window.itflowDocumentFormat.start();
|
||||
}
|
||||
</script>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($document_form_mode === 'edit') { ?>
|
||||
<div class="form-text"><i class="fas fa-history me-1"></i>Saving keeps what it says now in the document's history, so it can be put back.</div>
|
||||
|
||||
Reference in New Issue
Block a user