#BUG: Importing markdown skips first header in file

1 messages · Page 1 of 1 (latest)

winter nimbus
#

I imported several markdown files that start something like below (this is the output of onenote-md-exporter). Somehow the "# Header" and "## header" are not visible/imported in Notesnook eventhough the rest is all there. Strangely, it does NOT happen with header level 3 ("### header").


title: Page title
updated: 2025-06-16T23:34:44
created: 2025-03-03T22:37:41

Header

lorem ipsum
...

wicked belfry
winter nimbus
#

Will do!

#

Same result

#

Ok I just tested a bit more and header level 3 does work haha. I'll update the OP

winter nimbus
#

@wicked belfry @next siren So I figured out what's causing this.

This line, inside processHTML, is causing it: https://github.com/streetwriters/notesnook-importer/blob/9fc832da67935d6b2df738674e4a09b3ebeabe10/packages/core/src/providers/html/index.ts#L96

Here the title is being extracted from the html. So far so good if you want that, but on the next line the html itself is being altered, by removing the "titleElement".

const titleElement = findOne(
  (e) => ["title", "h1", "h2"].includes(e.tagName),
  document.childNodes,
  true
);
if (titleElement) removeElement(titleElement);

What makes this a bug, is that when we are importing markdown, after we get the html from the markdown, processHTML is called first and only after that the title is being decided upon based on settings or whether frontmatter has been found.
Now if one of those two would decide the title should be taken from somewhere else than the titleElement in the html provider (i.e. from the file name or from the frontmatter), the html has already been altered and we have lost the header level 1 or 2. This is what is happening in my case.

I think the easiest solution, is to remove line 100 that alters the HTML itself. This way you are sure no information is ever lost. This also requires no changes to the rest of the app.

What do you guys think?

GitHub

Import your notes from any app into Notesnook. Contribute to streetwriters/notesnook-importer development by creating an account on GitHub.