GithubHelp home page GithubHelp logo

svelte-markdoc's Introduction

svelte-markdoc

A Markdoc preprocessor for Svelte. Supports SvelteKit.

Setup

Create a SvelteKit project:

mkdir my-markdoc-project
cd my-markdoc-project

pnpm init svelte@next 

Install the svelte-markdoc package:

pnpm install -D svelte-markdoc

Create a markdoc.config.js in the root folder to hold your markdoc config:

export default {
  variables: {
    title: 'My awesome site'
  }
}

Then, configure the preprocessor in svelte.config.js:

import preprocessMarkdoc from 'svelte-markdoc'
import markdocConfig from './markdoc.config.js'

const config = {
  extensions: ['.svelte', '.markdoc'],
  preprocess: {
    markup: preprocessMarkdoc(markdocConfig)
  },
  kit: {
    // ...
  }
}

export default config

Now you can create pages with the .markdoc extension in src/routes:

---
title: Hello from Markdoc
---

# {% $markdoc.frontmatter.title %}

This is *super* cool.

FAQ

How is this different than MDX?

MDX is great! It's very flexible, this is a more contrained editing system where docs are treated as data, whereas with mdx, it's more like code. More info here: https://markdoc.io/docs/faq#why-not-mdx

License

MIT

svelte-markdoc's People

Contributors

bayre avatar joshnuss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

svelte-markdoc's Issues

500 error : Unexpected token

Hi, I just tried this package and I found an error like this
Screen Shot 2022-05-12 at 20 13 38

If there is a curly bracket in the .markdoc file it will cause an error. If I change the curly bracket with the bracket it's working fine.
Screen Shot 2022-05-12 at 20 18 13

+page.markdoc is not found - SvelteKit

I think svelte-markdoc doesn't work with the latest SvelteKit. Check the setup and error below:

// package.json:

{
  "name": "markdoc-demo",
  "version": "0.0.1",
  "scripts": {
     "dev": "vite dev",
     "build": "svelte-kit sync && svelte-package",
     "lint": "prettier --check .",
     "format": "prettier --write ."
   },
  "devDependencies": {
     "@sveltejs/adapter-auto": "next",
     "@sveltejs/kit": "next",
     "@sveltejs/package": "next",
     "autoprefixer": "^10.4.7",
     "postcss": "^8.4.14",
     "postcss-load-config": "^4.0.1",
     "prettier": "^2.6.2",
     "prettier-plugin-svelte": "^2.7.0",
     "svelte": "^3.44.0",
     "svelte-preprocess": "^4.10.7",
     "typescript": "^4.8.2",
     "vite": "^3.1.0",
     "svelte-markdoc": "^0.0.1",
   },
  "type": "module",
  "dependencies": {
   }
}
// markdoc.config.js

export default {
  variables: {
     title: 'My awesome site'
   }
};
// svelte.config.js

import adapter from '@sveltejs/adapter-auto';
import preprocessMarkdoc from 'svelte-markdoc';
import markdocConfig from './markdoc.config.js';

const config = {
  extensions: ['.svelte', '.markdoc'],
    kit: {
      adapter: adapter()
    },
      preprocess: {
         markup: preprocessMarkdoc(markdocConfig)
      }
};

export default config;

Routing is:

src
 └ routes
    └ +layout.svelte
    └ +page.svelte
    └ +page.markdoc

The error I get:

Not found: /+page.markdoc
Error: Not found: /+page.markdoc

Wondering what could be causing this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.