Giter Club home page Giter Club logo

Comments (7)

benjamincanac avatar benjamincanac commented on August 15, 2024 1

@juliomrqz Thanks for your explanation.

Will work on it soon then!

from content.

Atinux avatar Atinux commented on August 15, 2024 1

Thank you for your comments and feedback @juliomrqz ☺️

Beautiful website BTW!

from content.

benjamincanac avatar benjamincanac commented on August 15, 2024

Hey @juliomrqz,

We're considering this option indeed.

Juste to make sure, do you have any example of something you can do with a rehype plugin but not with remark?

Thanks!

from content.

juliomrqz avatar juliomrqz commented on August 15, 2024

In my blog, I use math equations in TeX format (an example article here https://marquez.co/blog/probabilities-and-uncertainty). The easy way to support this, it's using an official remark plugin remark-math, but it's required to use one of these official rehype plugins to work properly: rehype-katex or rehype-mathjax.

I managed to make them work with the latest version of @nuxt/content but I had to apply this hack for rehype-katex:

// nuxt.config.js
import rehypeKatex from 'rehype-katex'
import visit from 'unist-util-visit'

export default {
  //....
  hooks: {
    'content:file:beforeInsert': (document) => {
      if (document.extension === '.md') {
        const transformMath = rehypeKatex()

        visit(document.body, 'element', (element) => {
          element.properties = element.props
        })

        transformMath(document.body)

        visit(document.body, 'element', (element) => {
          element.props = element.properties
          element.tag = element.tagName || element.tag

          delete element.properties
          delete element.tagName
        })
      }
    },
  },
  //...
}

Fortunately, for this case, it was not a complicated hack.

Other rehype plugins can improve the developer's experience, for example:

  • If you want to add TailwindCSS classes for some HTML tags, you can easily use rehype-add-classes
  • For advanced HTML minifications, rehype-minify seems to be a good choice.

from content.

juliomrqz avatar juliomrqz commented on August 15, 2024

@benjamincanac. Another example is to easily support responsive tables if it's being used a bootstrap-lie approach https://getbootstrap.com/docs/4.5/content/tables/#responsive-tables

// nuxt.config.js
export default {
  content: {
    rehypePlugins: ["rehype-wrap", "rehype-add-classes"],
    rehypeWrap: {
      selector: "table",
      wrapper: "div.table-responsive",
    },
    rehypeAddClasses: {
      table: "table table-hover",
    },
  },
};

Maybe this example can be included in the Docs for advanced usage.

from content.

GussieTech avatar GussieTech commented on August 15, 2024

In nuxt/content v1.14.0, rehype-add-classes worked well with the following writing style.

// nuxt.config.js
export default {
  content: {
    markdown: {
      rehypePlugins: [
        ['rehype-add-classes', { table: 'table' }]
      ]
    }
  },
}

#45 (comment)

from content.

adrianrudnik avatar adrianrudnik commented on August 15, 2024

Just as a side node for others looking on how to use the rehype-wrapplugin with nuxt: It does only wrap the first occurrence. so the table example will only wrap the first table in a content document.

from content.

Related Issues (20)

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.