Gatsby: [gatsby-transformer-remark] [Migration from 0.x to 1.0] Add CSS class to markdown elements

Created on 4 Oct 2017  路  9Comments  路  Source: gatsbyjs/gatsby

I'm working on migrating my site from 0.x to 1.0. On many of my markdown pages, I've annotated the text with css classes using the syntax supported by the markdown-it-attrs plugin.

I see that gatsby has switched over to using remark for markdown parsing, and I've started reemplementing some of the features I lost as plugins. As far as I can tell, however, there is no existing remark plugin for adding CSS classes. Is there a plan for implementing this feature?

documentation question or discussion

Most helpful comment

If I find some time, I may pick this up soon.

FWIW, for the time being, I've gone back through and replaced the styled markdown tags with HTML spans.

All 9 comments

Someone else mentioning needed this. Not sure if they added a plugin. Try searching npm? If it doesn't exist, it'd be great to have it!

If I find some time, I may pick this up soon.

FWIW, for the time being, I've gone back through and replaced the styled markdown tags with HTML spans.

I'd love a way to handle this feature in a remark plugin or somehow at the configuration level

It'd be great to have a Gatsby remark plugin that wraps this https://github.com/sethvincent/remark-bracketed-spans

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

@KyleAMathews I'm trying to implement gatsby-remark-bracketed-spans. Is it sufficient to have a code like that?

const remarkBracketedSpans = require('remark-bracketed-spans')
module.exports = () => ({})
module.exports.setParserPlugins = () => [remarkBracketedSpans]

Or maybe I can remove default export?

Have you checked out other remark plugins?

I've thought about gatsby-remark-katex as example. There are some processing with nodes for getting done with katex.
https://github.com/gatsbyjs/gatsby/blob/95a898c2a8f9cc9e52dd6b83dee94084918a9ba8/packages/gatsby-remark-katex/src/index.js#L21
But below we add a markdown plugin remark-math, which would be used within gatsby-tranformer-remark.
https://github.com/gatsbyjs/gatsby/blob/95a898c2a8f9cc9e52dd6b83dee94084918a9ba8/packages/gatsby-transformer-remark/src/extend-node-type.js#L86-L93
I thought its sufficient, isn't?
But plugin with only setParserPlugins exports looks strange 馃槃

@KyleAMathews I've made a PR #8044 with adding remark-bracketed-spans parser plugin

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theduke picture theduke  路  3Comments

benstr picture benstr  路  3Comments

magicly picture magicly  路  3Comments

totsteps picture totsteps  路  3Comments

timbrandin picture timbrandin  路  3Comments