Graph Utility - Viewer!

linkFunction Overview: "Viewer!"

This function serves to embed an interactive element into a note within Amplenote, using a unique identifier (noteUUID). This operation involves storing the identifier for later use and inserting a placeholder for a plugin-based object into the note.


linkInputs and Actions

app:

Type: Object

Role: Represents the application context, providing access to various methods and settings related to the note and its content.

Effect: Used to interact with the note, set settings, and insert content.

noteUUID:

Type: String

Role: A unique identifier for the note that the function will modify.

Effect: This value is essential for identifying which note to operate on, ensuring that the correct note is updated.

linkProcess Breakdown

Setting the UUID:

Code: await app.setSetting("Current_Note_UUID [Do not Edit!]", noteUUID);

Explanation: This line stores the noteUUID in a setting named "Current_Note_UUID [Do not Edit!]". This makes the UUID accessible for later operations, specifically when rendering embedded content.

Effect: The application will have a persistent reference to the current note's UUID, which is crucial for subsequent actions, such as embedding content.

Inserting the Plugin Object:

Code: await app.insertNoteContent({ uuid: noteUUIDz },);

Explanation: This command inserts an HTML <object> tag into the note. The object references a plugin using app.context.pluginUUID and is formatted to maintain a specific aspect ratio (data-aspect-ratio="2").

Effect: This insertion creates an interactive element within the note that will be rendered when viewed. The pluginUUID is dynamically pulled from the app's context, ensuring the correct plugin is linked.

Return Statement:

Code: return null;

Explanation: The function ends by returning null, indicating that no further action is needed after the insertion.

Effect: The function terminates, having completed its task of embedding the plugin-based object into the note.


linkFunction Overview: renderEmbed

This function is responsible for rendering the embedded content within a note, specifically focusing on processing markdown tables, cleaning them up, and eventually rendering them in a final format.


linkInputs and Actions

app:

Type: Object

Role: Represents the application context, providing access to various methods and settings related to the note and its content.

Effect: Used to fetch note content and interact with the application's settings.

...args:

Type: Array

Role: Represents additional arguments that might be passed to the function.

Effect: Currently, these arguments are not used directly in the function.

linkProcess Breakdown

Retrieving the Note UUID:

Code: const noteUUID = await app.settings["Current_Note_UUID [Do not Edit!]"];

Explanation: This line retrieves the stored noteUUID from the settings, which was previously set by the "Viewer!" function.

Effect: The retrieved UUID is used to identify and fetch the content of the note that is being processed.

Fetching Note Content:

Code: const markdown = await app.getNoteContent({ uuid: noteUUID });

Explanation: This line fetches the content of the note identified by noteUUID. The content is expected to be in markdown format.

Effect: The markdown content of the note is now available for processing.

Removing HTML Comments:

Function: removeHtmlComments(content)

Code: const removeHtmlComments = (content) => content.replace(/<!--[\s\S]*?-->/g, '').trim();

Explanation: This function removes any HTML comments from the note content.

Effect: Ensures that any hidden or commented-out content does not interfere with the processing of the tables.

Processing Markdown Tables:

Function: removeEmptyRowsAndColumns(table)

Explanation:

Row Filtering: The function filters out completely empty rows from the markdown table.

Column Filtering: It also filters out columns that do not contain any data across all rows.

Effect: This results in cleaner tables, where only rows and columns with actual data are preserved, improving readability and accuracy in the final rendered content.

Handling Multiple Tables:

Code:

Explanation: This section of the code initializes variables to track the number of tables (tableCount), whether the function is currently processing a table (inTable), and stores the tables themselves (tables and currentTable).

Effect: Allows the function to handle multiple tables within the markdown content, processing each one individually.

Final Rendering:

Code:

Explanation:

Table Assembly: Joins the cleaned tables together, ensuring they are separated by double newlines.

Final Cleanup: Removes any remaining HTML comments from the processed content.

HTML Template: Prepares the final content for rendering. Although the template is empty in this example, it represents the location where the processed markdown would be inserted into an HTML structure for display.

Effect: The function returns an HTML template ready to be rendered, containing the cleaned and processed content from the note.


linkSummary

The "Viewer!" function is designed to embed a plugin-based object into a note, setting up the note for interactive viewing. The renderEmbed function complements this by processing the note's markdown content, particularly tables, to clean and prepare them for rendering. Together, these functions facilitate the embedding and display of interactive content in notes, ensuring the content is both functional and cleanly presented. This documentation serves as a guide for understanding the inputs, processes, and outcomes of these functions, making it easier to reference and modify the code as needed.