Skip to content

Instantly share code, notes, and snippets.

@NathanFlurry NathanFlurry/
Last active Feb 18, 2018

What would you like to do?
Inkdrop Import Markdown Files


This script will import Markdown files from a folder. It will only import files ending in .md, so it skips folders and images. This will use the file name as the note name. If there is a H1 on the first line, it will remove that line and trim the file in order to remove redundancy.

How to use

  1. Select the notebook you want to import into in the sidebar.
  2. Under Inkdrop, select Developer > Toggle Developer Tools.
  3. Paste this script.
  4. Replace path/to/folder/with/markdown/files/ with a path to the folder with the markdown files in it. Make sure to include the trailing "/".
  5. Ignore the error and please forgive my laziness. If you get a grey screen, just click a few times and the ghost windows will disappear.

Todo (that probably won't ever be completed)

  • Transferring Bear-style tags
  • Image import
  • Use file chooser
async function importMd(path) {
const editorActions = inkdrop.flux.getActions("editor");
const editorStore = inkdrop.flux.getStore("editor");
const files = readFiles(path);
for (let file of files) {
await editorActions.create();
const state = editorStore.getState();
const lines = file.content.trim().split("\n");
const newDocument = Object.assign(Object.assign({}, state.document), {
body: lines[0][0] == "#" ? lines.slice(1).join("\n").trim() : file.contents
await editorActions.update({ document: newDocument, changed: true });
await{ document: newDocument });
function readFiles(dirname) {
const fs = require("fs");
const filenames = fs.readdirSync(dirname);
return filenames.filter(n => n.slice(-3) == ".md").map(name => {
const content = fs.readFileSync(dirname + name, "utf-8");
return { name: name.slice(0,-3), content: content };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.