Comments (7)
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.
@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.
Yes, that’s possible, but you need to configure how to sanitize remark react!
from remark-slug.
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.
attributes: { code: ["className"] },
Cool, but that example only allows className
s on code
elements!
If you want to allow id
s on all elements, you need to add a statement, e.g., like this:
- attributes: { code: ["className"] },
+ attributes: { code: ["className"], "*": ["id"] },
from remark-slug.
from remark-slug.
Good to know. I just found how to improve the situation.
hast-util-sanitize/lib/github.json
have aclobberPrefix
set touser-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)
- Mismatch between GH Emoji and Slug HOT 1
- does not add anchors to headings using GitHub’s algorithm HOT 4
- When creating slugs (within gatsby-plugin-mdx), accents make the anchors fail HOT 7
- remark-slug doesn't take current URL into consideration HOT 2
- Allow slugger to be passed in HOT 2
- link in header leads to unexpected parsing HOT 1
- Types definitions HOT 5
- Emoji leads to weird slug HOT 4
- Enable unique slugs across multiple files HOT 8
- Add `-` before headings whose ID starts with number to avoid URL issue HOT 1
- Compatible with `remark-autolink-headings` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remark-slug.