diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8ff8b7706..91f25a7ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,7 @@ Update from Maintenance > Update as usual - this release has two database change
- 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.
- 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.
### Bug Fixes
@@ -34,6 +35,7 @@ Update from Maintenance > Update as usual - this release has two database change
- Database 4.2.3: documents.document_markdown and document_versions.document_version_markdown (longtext, NULL for rich text). A Markdown document's document_content is still the HTML every page shows, rendered from it on each save, so readers are unchanged; documentMarkdownReady(), documentMarkdownSql() and documentMarkdownSet() keep the writers working before the update.
- 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].
## [26.12.2]
diff --git a/agent/document.php b/agent/document.php
index 24d81a5fe..a1eff3ce8 100644
--- a/agent/document.php
+++ b/agent/document.php
@@ -87,28 +87,63 @@ $page_title = $row['document_name'];
";
}
if ($empty) {
diff --git a/js/document_contents.js b/js/document_contents.js
index 728dbd289..a6903b44c 100644
--- a/js/document_contents.js
+++ b/js/document_contents.js
@@ -2,7 +2,11 @@
* ITFlow - a contents list for a long document or Knowledge Base article (agent/document.php,
* agent/kb_article.php): its headings, in the [data-document-contents] card beside it, each one
* a link down to it. Only when it has three headings or more - a short one doesn't need it.
- * Headings without an id get one, so a link to a section can be shared.
+ * Headings without an id get one, so a link to a section can be shared. The section being read is
+ * marked in the list as the page scrolls.
+ *
+ * A link with data-document-tab (the document page's "2 earlier versions") opens that tab of the
+ * card beside the document, and goes to it.
*/
(function () {
'use strict';
@@ -58,4 +62,51 @@
target.scrollIntoView({ block: 'start' });
}
}
+
+ // The section being read is marked in the list - the last heading above the top quarter of the window
+ const links = {};
+ list.querySelectorAll('a').forEach(function (a) {
+ links[a.getAttribute('href').slice(1)] = a;
+ });
+ let queued = false;
+ const mark = function () {
+ queued = false;
+ let current = headings[0];
+ const line = window.innerHeight * 0.25;
+ headings.forEach(function (h) {
+ if (h.getBoundingClientRect().top <= line) {
+ current = h;
+ }
+ });
+ Object.keys(links).forEach(function (id) {
+ links[id].classList.toggle('active', id === current.id);
+ });
+ };
+ const queue = function () {
+ if (!queued) {
+ queued = true;
+ window.requestAnimationFrame(mark);
+ }
+ };
+ window.addEventListener('scroll', queue, { passive: true });
+ window.addEventListener('resize', queue);
+ mark();
+})();
+
+(function () {
+ 'use strict';
+
+ document.addEventListener('click', function (e) {
+ const link = e.target.closest ? e.target.closest('a[data-document-tab]') : null;
+ if (!link) {
+ return;
+ }
+ const tab = document.querySelector('button[data-document-tab="' + link.getAttribute('data-document-tab') + '"]');
+ if (!tab || !window.bootstrap) {
+ return;
+ }
+ e.preventDefault();
+ bootstrap.Tab.getOrCreateInstance(tab).show();
+ tab.closest('.card').scrollIntoView({ behavior: 'smooth', block: 'start' });
+ });
})();