Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelNivard authored Dec 4, 2024
1 parent 1d2f1e8 commit 17e7aa8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id":"ridian","name":"Ridian","version":"0.1.1","minAppVersion":"0.15.0","description":"Execute R code blocks and display outputs and plots & render documents with Quarto within Obsidian.","author":"Michel Nivard","isDesktopOnly":true}
{"id":"ridian","name":"Ridian","version":"0.1.2","minAppVersion":"0.15.0","description":"Execute R code blocks and display outputs and plots & render documents with Quarto within Obsidian.","author":"Michel Nivard","isDesktopOnly":true}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Ridian",
"version": "0.1.1",
"version": "0.1.2",
"description": "Execute R code blocks and display outputs and plots within Obsidian.",
"main": "main.js",
"scripts": {
Expand Down
17 changes: 6 additions & 11 deletions src/CombinedPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default class CombinedPlugin extends Plugin {


private handleCompletion(items: any[]) {
console.log('handleCompletion called with items:', items);


if (items.length === 0) {
if (this.currentDropdown) {
Expand Down Expand Up @@ -313,7 +313,7 @@ private handleCursorActivity(editor: Editor) {

// Close the Completion Dropdown if it's open
if (this.currentDropdown) {
console.log('Inside function call. Closing Completion Dropdown.');
-
this.currentDropdown.close();
this.currentDropdown = null;
}
Expand All @@ -325,7 +325,7 @@ private handleCursorActivity(editor: Editor) {

// Close the Signature Help Dropdown if it's open
if (this.signatureHelpDropdown) {
console.log('Outside function call. Closing Signature Help Dropdown.');
-
this.signatureHelpDropdown.close();
this.signatureHelpDropdown = null;
}
Expand All @@ -339,7 +339,6 @@ private showSignatureHelp(editor: Editor, cursor: EditorPosition) {
const { codeWithAll, startLine } = getCurrentCodeChunk(editor, cursor.line);

if (!codeWithAll) {
console.log('No code chunk found. Closing Signature Help Dropdown.');
this.closeSignatureHelpDropdown();
return;
}
Expand All @@ -361,8 +360,6 @@ private showSignatureHelp(editor: Editor, cursor: EditorPosition) {
};

// Log the uri and position
console.log('Virtual URI:', virtualUri);
console.log('Cursor position:', position);

// Send didOpen notification for the code chunk
this.rLanguageServer.sendNotification('textDocument/didOpen', {
Expand Down Expand Up @@ -393,9 +390,9 @@ private showCompletion(editor: Editor, cursor: EditorPosition) {
const { codeWithAll, startLine } = getCurrentCodeChunk(editor, cursor.line);

if (!codeWithAll) {
console.log('No code chunk found. Closing Completion Dropdown.');

if (this.currentDropdown) {
console.log('No code chunk found. Closing existing dropdown.');

this.currentDropdown.close();
this.currentDropdown = null;
}
Expand All @@ -418,9 +415,7 @@ private showCompletion(editor: Editor, cursor: EditorPosition) {
character: cursor.ch,
};

// Log the uri and position
console.log('Virtual URI:', virtualUri);
console.log('Cursor position:', position);


// Send didOpen notification for the code chunk
this.rLanguageServer.sendNotification('textDocument/didOpen', {
Expand Down
38 changes: 24 additions & 14 deletions src/RCodeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,11 @@ options(device = function(...) jpeg(filename = tempfile(), width=800, height=600
return rProcess;
}


function escapeMarkdown(text: string): string {
return text.replace(/([\\`*_{}[\]()#+\-!>|])/g, '\\$1');
return text.replace(/([\\`*_{}[\]()#+\-!>|])/g, '\u200b$1');
}


function insertOutputWithCallout(
editor: Editor,
endLine: number,
Expand All @@ -653,12 +653,12 @@ function insertOutputWithCallout(
widgetPaths: string[],
uniqueId: string,
options: { [key: string]: string },
isError: boolean = false // Optional parameter to style errors differently
isError: boolean = false
) {
const contentLines: string[] = [];

const contentLines2: string[] = [];

if (output && output.trim() !== '') {
// Escape markdown special characters in the output
const escapedOutput = escapeMarkdown(output.trim());
const outputLines = escapedOutput.split('\n').map((line) => '> ' + line);
contentLines.push(...outputLines);
Expand All @@ -667,39 +667,48 @@ function insertOutputWithCallout(
imagePaths.forEach((imagePath) => {
const vaultImagePath = `${imagePath}`;
const imageMarkdown = `![center|480](${vaultImagePath})`;
contentLines.push(`> ${imageMarkdown}`);
contentLines2.push(`> ${imageMarkdown}`);
});

widgetPaths.forEach((widgetPath) => {
const widgetMarkdown = `<iframe src="${widgetPath}" width="100%" height="680px"></iframe>`;
contentLines.push(`> ${widgetMarkdown}`);
contentLines2.push(`> ${widgetMarkdown}`);
});

if (contentLines.length === 0) {
if (contentLines.length === 0 && contentLines2.length === 0) {
return;
}

// Use a different callout type or add a class for errors if needed
let calloutType = isError ? 'ERROR' : 'OUTPUT';
let outputContent = `> [!${calloutType}]+ {#output-${uniqueId}}\n`;
const calloutType = isError ? 'ERROR' : 'OUTPUT';
const calloutTitle = `> [!${calloutType}]+ {#output-${uniqueId}}`;

let outputContent = `${calloutTitle}\n`;
if (contentLines.length !== 0) {
outputContent += '> \`\`\`\n';
outputContent += contentLines.join('\n') + '\n';
outputContent += '> \`\`\`\n';
}
if (contentLines2.length !== 0) {
outputContent += contentLines2.join('\n') + '\n';
outputContent += '> \n';
}

let existingOutputStart = -1;
let existingOutputEnd = -1;
const totalLines = editor.lineCount();

for (let i = 0; i < totalLines; i++) {
const line = editor.getLine(i);
if (line.trim() === `> [!${calloutType}]+ {#output-${uniqueId}}`) {
if (line.trim().startsWith(`> [!${calloutType}]`) && line.includes(`{#output-${uniqueId}}`)) {
existingOutputStart = i;
existingOutputEnd = i;
while (existingOutputEnd + 1 < totalLines) {
const nextLine = editor.getLine(existingOutputEnd + 1);
if (!nextLine.startsWith('> ') && nextLine.trim() !== '') {
if (nextLine.trim() === '' || nextLine.startsWith('> ')) {
existingOutputEnd++;
} else {
break;
}
existingOutputEnd++;
}
break;
}
Expand All @@ -716,6 +725,7 @@ function insertOutputWithCallout(
}



function removeOutputCallout(editor: Editor, uniqueId: string) {
let existingOutputStart = -1;
let existingOutputEnd = -1;
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"0.1.1": "0.15.0"
"0.1.2": "0.15.0"
}

0 comments on commit 17e7aa8

Please sign in to comment.