Onyx Boox Notes and Highlight export

There is, of course, a plugin to import notes exported from Onyx Boox devices. However, it doesn’t suites me. Hence, I created this small template to format the exported notes and highlights in Markdown-friendly Way.

<%* 
function getTitleAndAuthor(l) {
  l = l.replace("Reading Notes | <<", "").split(">>");
  return {
    title: l[0],
    authors: l[1]
  }
}

function parseNote(note) {
  let lines = note.split("\n");
  lines.reverse();
  let content = {
    section: "",
    timestamp: "",
    page: "",
    highlight: "",
    note: ""
  }
  for (let i = 0; i < lines.length; i++) {
    let l = lines[i];
    if (l.includes("【Note】")) {
      content.note = l.replace('【Note】', "");
    } else if (l.includes("  |  Page No.: ")) {
      let meta = l.split("  |  Page No.: ");
      content.timestamp = meta[0]
      content.page = meta[1]
    } else if (i == lines.length - 1) {
      content.section = l;
    } else {
      content.highlight = l;
    }
  }
  return content
}

function formatNote(note) {
  let sym = note.charAt(0);
  let type = "quote"
  let title = "Quotable/Concept/General Idea";
  switch(sym) {
    case "*":
      note = note.substr(2);
      type = "important";
      title = "Striking/Intense"
      break;
    case "#":
      note = note.substr(2);
      type = "danger";
      title = "In Discord"
      break;
    case "~":
      note = note.substr(2);
      type = "question";
      title = "Though Provoking"
      break;
  }
  let output = "> [!" + type + "] " + title;
  if (note) {
    output += "\n" + note + "\n"
  }
  return output
}

let file = app.workspace.getActiveFile()
let content = await app.vault.read(file)
let lines = content.split("\n");
let titleAndAuthor = getTitleAndAuthor(lines.shift())
lines = lines.join("\n")
notes = lines.split("-------------------\n")

let output = ["# " + titleAndAuthor.title, "##### " + titleAndAuthor.authors].join("\n") + "\n\n";
let currentSection = null;
for (let i = 0;  i < notes.length; i++) {
  if (notes[i]) {
    let noteData = parseNote(notes[i])
    if (noteData.section && (currentSection != noteData.section)) {
      output += "## " + noteData.section + "\n";
      currentSection = noteData.section;
    }
    output += ["### " + noteData.timestamp + " @ Page: " + noteData.page, noteData.highlight].join("\n") + "\n";
    output += "\n" + formatNote(noteData.note) + "\n"
    output += "\n"
  }
}

app.vault.modify(file, output)
%>

In Action:
Boox Template

1 Like

Thanks for sharing this. I found it whilst looking for info on recommended ways to bring epub notes / annotations / highlights into Obsidian. As I have a Onyx Boox Nova Air, and was already familiar with the plug-in, I thought I’d try your template.

I’m finding it wipes out actual highlight text content, and page numbers, etc. See the before and after images below.

Do you have a little time to help me figure out why?

Before

After