@jacobknightley/fabric-format 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/notebook-formatter.js +18 -6
- package/package.json +1 -1
|
@@ -392,15 +392,27 @@ export function parseNotebook(content, fileExtension) {
|
|
|
392
392
|
function replaceCell(fileContent, cell, formattedContent, config) {
|
|
393
393
|
const lines = fileContent.split(/\r?\n/);
|
|
394
394
|
let newLines;
|
|
395
|
-
if (cell.isMagicCell) {
|
|
396
|
-
|
|
395
|
+
if (cell.isMagicCell && cell.magicCommand) {
|
|
396
|
+
// For magic cells, prepend the magic command (without trailing whitespace)
|
|
397
|
+
const magicCommandLine = config.magicPrefix + '%%' + cell.magicCommand;
|
|
398
|
+
newLines = [magicCommandLine, ...addMagicPrefix(formattedContent, config)];
|
|
399
|
+
// Find where the magic command line starts (search backwards from contentStartLine)
|
|
400
|
+
let magicLineIndex = cell.contentStartLine - 1;
|
|
401
|
+
while (magicLineIndex >= 0 && !lines[magicLineIndex].trim().startsWith(config.magicPrefix + '%%')) {
|
|
402
|
+
magicLineIndex--;
|
|
403
|
+
}
|
|
404
|
+
const before = lines.slice(0, magicLineIndex >= 0 ? magicLineIndex : cell.contentStartLine);
|
|
405
|
+
const after = lines.slice(cell.contentEndLine + 1);
|
|
406
|
+
return [...before, ...newLines, ...after].join(LINE_ENDING);
|
|
397
407
|
}
|
|
398
408
|
else {
|
|
399
|
-
newLines =
|
|
409
|
+
newLines = cell.isMagicCell
|
|
410
|
+
? addMagicPrefix(formattedContent, config)
|
|
411
|
+
: formattedContent.split(/\r?\n/);
|
|
412
|
+
const before = lines.slice(0, cell.contentStartLine);
|
|
413
|
+
const after = lines.slice(cell.contentEndLine + 1);
|
|
414
|
+
return [...before, ...newLines, ...after].join(LINE_ENDING);
|
|
400
415
|
}
|
|
401
|
-
const before = lines.slice(0, cell.contentStartLine);
|
|
402
|
-
const after = lines.slice(cell.contentEndLine + 1);
|
|
403
|
-
return [...before, ...newLines, ...after].join(LINE_ENDING);
|
|
404
416
|
}
|
|
405
417
|
/**
|
|
406
418
|
* Format all cells in a Fabric notebook.
|
package/package.json
CHANGED