-
🌐 async-utils.jsWeb, 3.69 kB⬇
-
🌐 auth-storage.jsWeb, 735 B⬇
-
🌐 chat-helpers.jsWeb, 8.85 kB⬇
-
🌐 chat-renderer.jsWeb, 70.00 kB⬇
-
🌐 code-overlay.jsWeb, 21.77 kB⬇
-
🌐 confirm-dialog.jsWeb, 3.17 kB⬇
-
🌐 conversation-format-utils.jsWeb, 21.51 kB⬇
-
🌐 diagram-overlay.jsWeb, 7.93 kB⬇
-
🌐 dialog.jsWeb, 2.50 kB⬇
-
🌐 dom-utils.jsWeb, 8.33 kB⬇
-
🌐 drag-reorder.jsWeb, 4.82 kB⬇
-
🌐 elements.jsWeb, 11.06 kB⬇
-
🌐 export-utils.jsWeb, 1.53 kB⬇
-
🌐 format-utils.jsWeb, 29.60 kB⬇
-
🌐 history-navigation.jsWeb, 1.95 kB⬇
-
🌐 hljs-yaml.jsWeb, 5.07 kB⬇
-
🌐 inline-format.jsWeb, 7.35 kB⬇
-
🌐 instant-answer.jsWeb, 19.82 kB⬇
-
🌐 interactive-tools.jsWeb, 38.77 kB⬇
-
🌐 mermaid-fixes.jsWeb, 4.60 kB⬇
-
🌐 mermaid-render.jsWeb, 5.10 kB⬇
-
🌐 mermaid.jsWeb, 195 B⬇
-
🌐 migrations.jsWeb, 12.11 kB⬇
-
🌐 multi-choice-dialog.jsWeb, 1.33 kB⬇
-
🌐 notification-stack.jsWeb, 2.50 kB⬇
-
🌐 options-manager.jsWeb, 45.56 kB⬇
-
🌐 overlay-utils.jsWeb, 4.14 kB⬇
-
🌐 pdf-export.jsWeb, 23.59 kB⬇
-
🌐 pinch-zoom.jsWeb, 3.21 kB⬇
-
🌐 plugin-dialog.jsWeb, 2.17 kB⬇
-
🌐 read-aloud.jsWeb, 33.84 kB⬇
-
🌐 response-pipeline.jsWeb, 55.19 kB⬇
-
🌐 scratchpad-editor.jsWeb, 8.64 kB⬇
-
🌐 scratchpad-export.jsWeb, 3.56 kB⬇
-
🌐 scrollbars.jsWeb, 3.12 kB⬇
-
🌐 selection-manager.jsWeb, 3.76 kB⬇
-
🌐 settings-utils.jsWeb, 31.08 kB⬇
-
🌐 share.jsWeb, 10.75 kB⬇
-
🌐 side-drawer.jsWeb, 9.37 kB⬇
-
🌐 speech-text.jsWeb, 6.60 kB⬇
-
🌐 swipe-navigation.jsWeb, 6.16 kB⬇
-
🌐 table-overlay.jsWeb, 8.10 kB⬇
-
🌐 theme-utils.jsWeb, 8.34 kB⬇
-
🌐 thinking-panel-base.jsWeb, 14.88 kB⬇
-
🌐 ui-sets.jsWeb, 1.00 kB⬇
-
🌐 version-overlay.jsWeb, 4.63 kB⬇
/**
* File export for scratchpads: downloads the rendered scratchpad content as
* standalone HTML, Markdown, or PDF. HTML and Markdown reuse the clipboard
* conversion pipeline (extractFormattedContent); equation items are restored
* to their raw $$..$$ TeX first, since typeset MathJax markup does not
* survive outside the app. Mermaid diagrams are rasterized once and shared
* by the PDF embed and the HTML/markdown conversion; the PDF delegates to
* the shared PDF exporter.
*/
import { extractFormattedContent, rasterize_diagrams, build_export_html } from './format-utils.js';
import { strip_tags } from './dom-utils.js';
import { export_content } from './export-utils.js';
import { exportDocumentPdf } from './pdf-export.js';
import { compute_list_markers } from '../document-model.js';
import { formatEquation } from './conversation-format-utils.js';
/**
* Builds a detached clone of the rendered scratchpad content with equation
* items restored to their raw $$..$$ TeX text.
* @param {Array<Object>} items - The revision's content items.
* @param {HTMLElement} el - The rendered .div-response-content element.
* @returns {HTMLElement} The prepared clone.
*/
function prepared_content(items, el) {
const clone = el.cloneNode(true);
clone.querySelectorAll('.div-code-expand-btn').forEach(btn => btn.remove());
const by_guid = new Map((Array.isArray(items) ? items : []).map(item => [item?.guid, item]));
clone.querySelectorAll('[data-guid]').forEach(node => {
const item = by_guid.get(node.getAttribute('data-guid'));
if (item?.type === 'equation') {
node.textContent = strip_tags(formatEquation({ ...item, caption: '' })).trim();
}
});
return clone;
}
/**
* Builds the scratchpad content as markdown.
* @param {Array<Object>} items - The revision's content items.
* @param {HTMLElement} el - The rendered .div-response-content element.
* @param {Object} images - Rasterized diagram PNGs keyed by item guid.
* @returns {Promise<string>} The markdown document.
*/
async function build_scratchpad_markdown(items, el, images) {
const { text } = await extractFormattedContent(prepared_content(items, el), images);
return text + '\n';
}
/**
* Builds the scratchpad content as a standalone HTML5 document.
* @param {Array<Object>} items - The revision's content items.
* @param {HTMLElement} el - The rendered .div-response-content element.
* @param {string} title - The scratchpad title.
* @param {boolean} mobile - Whether to emit the mobile variant.
* @param {Object} images - Rasterized diagram PNGs keyed by item guid.
* @returns {Promise<string>} The HTML5 document.
*/
async function build_scratchpad_html(items, el, title, mobile, images) {
const { html } = await extractFormattedContent(prepared_content(items, el), images);
return build_export_html(title, html, mobile);
}
/**
* Exports the scratchpad in the given format and downloads the file.
* @param {Array<Object>} items - The revision's content items.
* @param {HTMLElement} el - The rendered .div-response-content element.
* @param {string} title - The scratchpad title, used for filename and metadata.
* @param {string} format - 'html', 'html-mobile', 'markdown', or 'pdf'.
*/
export async function export_scratchpad(items, el, title, format) {
title = String(title || '').trim() || 'scratchpad';
const images = await rasterize_diagrams(el, items);
await export_content(format, title, {
pdf: () => exportDocumentPdf(items, compute_list_markers(items), title, images),
html: (mobile) => build_scratchpad_html(items, el, title, mobile, images),
markdown: () => build_scratchpad_markdown(items, el, images)
});
}
scratchpad-export.js
×
Type: Web, text/x-java
3.56 Kilobytes
Last Modified 2026-11-04 09:48:28
⬇ Download File
Type: Web, text/x-java
3.56 Kilobytes
Last Modified 2026-11-04 09:48:28
⬇ Download File