1Writer カーソル行のノートを開く
2024/09/13
code:js
// カーソル行のテキストを取得
const selectedLineRange = editor.getSelectedLineRange();
const selectedLineText = editor.getTextInRange(selectedLineRange0, selectedLineRange1); // 正規表現でダブルブラケット内のテキストを抽出
const matches = selectedLineText.match(/\[\[([^\\]+)\]\]/); if (matches && matches1) { const fileName = matches1; // ファイル名が取得できたら、そのファイルを開く
const folderPath = editor.getFolderPath();
const filePath = folderPath + "/" + fileName + ".md"; // 拡張子は適宜変更
// ファイルを開く
editor.openFile(filePath, "edit", (success) => {
if (success) {
ui.hudSuccess(ファイル「${fileName}」を開きました);
} else {
ui.hudError(ファイル「${fileName}」が見つかりません);
}
});
} else {
ui.hudError("ダブルブラケット内のテキストが見つかりません");
}