"Download!"This documentation provides a comprehensive explanation of the "Download!" function in the Graph Utility Plugin. It explains how each input is processed and how the function's different parts contribute to the final output. This is intended for developers or users who need to understand, modify, or use this function in their applications.
The "Download!" function is designed to be an interactive utility within Amplenote that prompts the user to select an option for handling content from a note. The content may be processed, formatted, and then either downloaded in different formats or copied to a new note. The function uses asynchronous JavaScript to manage these tasks efficiently.
Type: Prompt with Radio Buttons
Label: "Select the format that you want to download/copy in!"
Options:
Download - Interactive Charts (Recommended)
Download all Tables - Markdown
Copy all Tables from this Note to a new Note
This section prompts the user to select one of three options. Depending on the user's choice, the function will either:
Download interactive charts,
Download all tables in Markdown format,
Copy all tables to a new note.
The selected option is captured in the result variable for further processing.
Type: UUID of the Note
Purpose: Fetches the entire content of the note in markdown format.
The content of the note specified by noteUUID is retrieved in markdown format, which will then be processed according to the user's selection.
Type: String (Note Content)
Purpose: Removes all HTML comments from the note content.
This function scans the note content for any HTML comments (i.e., content between <!-- and -->) and removes them. This ensures that the final output is clean and free from any unnecessary or hidden comments.
Type: String (Table content in markdown format)
Purpose: Removes rows and columns from the table that are entirely empty.
This function processes each table by:
Filtering out empty rows.
Identifying columns that have content across rows.
Removing columns that are empty across all rows.
This ensures that only meaningful data remains in the tables.
Type: Array of Strings (Lines from Note Content)
Purpose: Detects and processes tables within the note content.
Splitting Lines: The note content is split into individual lines.
Table Detection: The function detects where tables start and end, counting each table.
Adding Headers: If a table is detected without headers, headers are added automatically.
Processing Tables: The removeEmptyRowsAndColumns function is applied to each table to clean it up.
Final Assembly: All cleaned tables are collected together, separated by a --- marker if there are multiple tables.
Type: Array of Strings (Processed tables)
Purpose: Assembles the final cleaned content.
Joining Tables: The cleaned tables are joined together into a single string.
Removing HTML Comments: Any remaining HTML comments are removed to ensure the final content is clean.
Type: Note Metadata (Name, Tags, UUID)
Purpose: Adds metadata information to the final content.
Note Metadata: The note's name, tags, and UUID are retrieved and prepended to the cleaned content.
Final Content: This forms the final content that will be used depending on the user’s selected option.
Type: String (Final content and filename)
Purpose: Triggers a download of the final content as a text file.
Blob Creation: The final content is converted into a blob (a file-like object of raw data).
Download Trigger: A temporary link is created and clicked programmatically to trigger the download. The filename includes a timestamp and the note UUID.
Type: User Selection (result)
Purpose: Executes different actions based on the user’s choice.
Option 1: If the user selects "Download - Interactive Charts", the content is prepared as an HTML file for interactive charts.
The HTML file works as smooth as a butter, with all its functionality.
Option 2: If the user selects "Download all Tables - Markdown", the content is downloaded as a .txt file containing all tables in markdown format.
This content can be used in the above HTML file, and also as a backup file.
Option 3: If the user selects "Copy all Tables from this Note to a new Note", a new note is created with the cleaned content, and the user is navigated to the new note.
Very useful when you want to collect all the tables from a single note and copy it to a new note and start working on it, without any other further information.
This part of the document explains the transposeMarkdownTables function, a JavaScript utility designed to process and transpose the data within markdown tables. The function is useful for dynamically manipulating markdown content by reorganizing table data while preserving the original structure and adding a transposed version of the table.
transposeMarkdownTablesThe transposeMarkdownTables function processes a markdown content string that contains multiple tables separated by "---". It transposes the data in each table while maintaining the table structure and appending a header to indicate the transposed version.
content (string): The markdown content containing one or more tables. Tables are expected to be separated by ---, and each table should have a header followed by a table with columns separated by |.
Returns (string): The processed markdown content with each table transposed and restructured. The transposed table is inserted below the original one, each with its corresponding header.
Action: The content string is split into sections using --- as a delimiter. This results in an array where each element corresponds to a section of the markdown content.
Code:
Action: Each section is processed individually to extract and transpose the table data.
Details:
Step 2a: Extracting the Header
The first line of the section is treated as the header.
The transposed version of the header is created by appending " (Transposed)".
Code:
Step 2b: Extracting Table Rows
Table rows are extracted starting from the third line (ignoring the first two lines which usually contain the header and separator).
Each row is split by the | character, trimmed, and the empty columns at the edges are removed.
Code:
Check for Valid Rows:
If the table has no data rows or all rows are empty, the section is returned as is without further processing.
Code:
Step 2c: Transposing the Table
The table data is split into the first two rows (which are not transposed) and the rest of the rows.
The rest of the rows are transposed using the helper function transposeArray.
Code:
Step 2d: Formatting the Transposed Table
Two new rows are added at the start: one with empty cells and one with separators.
The transposed rows are then combined into a markdown table format.
Code:
Step 2e: Combining Header and Table
The transposed table is combined with the transposed header to form the final section content.
Code:
Action: The processed sections are rejoined using --- to form the final markdown content.
Code:
transposeArrayThe transposeArray function is a utility that transposes a 2D array, effectively swapping its rows with its columns.
array (2D array): An array of arrays, where each inner array represents a row of data.
Returns (2D array): A new array where the columns and rows of the input array are swapped.
How It Works:
Pass the markdown content to the transposeMarkdownTables function.
The function will automatically process and transpose the tables.
The final output will contain both the original and transposed versions of each table, separated by ---.
Example:
Ensure the markdown content is well-structured with proper table formatting.
The function assumes that tables are separated by --- and that each table section contains a header followed by a markdown table.
This documentation should serve as a comprehensive guide to understanding and using the transposeMarkdownTables function.
This function is a comprehensive utility that allows users to handle note content in different ways, providing flexibility in how content is downloaded or copied. It processes tables within a note, ensuring they are clean and free from empty rows and columns, and allows users to download or copy this processed content according to their needs. The documentation provided here explains each part of the function in detail, making it easy for developers to understand and modify as required.