muerwre.github.io/content/Frontend/Vue/Make Nuxt handle Obsidian highlights.md
2022-11-03 10:38:11 +06:00

471 B

By default Nuxt Content Plugin not handling ==highlight== links. To fix that we will create Nitro plugin:

// ~/server/plugins/highlight.ts
export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook("content:file:beforeParse", (file) => {
    if (file._id.endsWith(".md")) {
      file.body = file.body.replace(
        /==([^=]+)==/gs,
        `<span class="highlight">$1</span>`
      );
    }
  });
});