Giter Site home page Giter Site logo

Comments (7)

MoOx avatar MoOx commented on June 16, 2024 3

Good to know. I just found how to improve the situation.
hast-util-sanitize/lib/github.json have a clobberPrefix set to user-content-, so I added it empty in my merge like this

    .use(slug)
    .use(reactRenderer, {
      sanitize: merge(
        sanitizeGhSchema,
        {
          // remove user-content from github.json to remark-slug work as expected
          clobberPrefix: "",
          attributes: { code: ["className"] } // here I didn't had to add your trick on id.
        }
      ),
      remarkReactComponents: {
        code: RemarkLowlight(languages),
      },
    })

And now that fucking perfect! Thanks a lot for your help and reactivity!

from remark-slug.

wooorm avatar wooorm commented on June 16, 2024 2

@yusufameri I’m pretty sure Max doesn’t remember how he did that two years ago, but I’m guessing by reading the docs.

from remark-slug.

wooorm avatar wooorm commented on June 16, 2024

Yes, that’s possible, but you need to configure how to sanitize remark react!

from remark-slug.

MoOx avatar MoOx commented on June 16, 2024

Actually my code is going what I found in some docs:

import remark from "remark"
import slug from "remark-slug"
import autoLinkHeadings from "remark-autolink-headings"
import toc from "remark-toc"
import reactRenderer from "remark-react"
import RemarkLowlight from "remark-react-lowlight"
import merge from "deepmerge"
import sanitizeGhSchema from "hast-util-sanitize/lib/github.json"

import languages from "./common-languages.js"

export default (body: string) =>
  remark()
    .use(slug)
    .use(autoLinkHeadings)
    .use(toc)
    .use(reactRenderer, {
      sanitize: merge(sanitizeGhSchema, {
        attributes: { code: ["className"] },
      }),
      remarkReactComponents: {
        code: RemarkLowlight(languages),
      },
    })
    .processSync(body, {
      commonmark: true,
    })

Is this good enough?

from remark-slug.

wooorm avatar wooorm commented on June 16, 2024
        attributes: { code: ["className"] },

Cool, but that example only allows classNames on code elements!

If you want to allow ids on all elements, you need to add a statement, e.g., like this:

-       attributes: { code: ["className"] },
+       attributes: { code: ["className"], "*": ["id"] },

from remark-slug.

wooorm avatar wooorm commented on June 16, 2024

👍

from remark-slug.

yusufameri avatar yusufameri commented on June 16, 2024

Good to know. I just found how to improve the situation.
hast-util-sanitize/lib/github.json have a clobberPrefix set to user-content-, so I added it empty in my merge like this

    .use(slug)
    .use(reactRenderer, {
      sanitize: merge(
        sanitizeGhSchema,
        {
          // remove user-content from github.json to remark-slug work as expected
          clobberPrefix: "",
          attributes: { code: ["className"] } // here I didn't had to add your trick on id.
        }
      ),
      remarkReactComponents: {
        code: RemarkLowlight(languages),
      },
    })

And now that fucking perfect! Thanks a lot for your help and reactivity!

OMG! This was causing me pain these past few hours. How did you figure out that clobberPrefix existed and/or was doing such a thing? Also on a separate note, I am using typescript with react but can't seem to get any of the typing to appear. Do you know how to do this?

from remark-slug.

Related Issues (12)

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.