remarkjs / remark-react

Deprecated plugin to transform to React — please use `remark-rehype` and `rehype-react` instead
524 stars 37 forks source link

Table align not working #28

Closed craftzdog closed 7 years ago

craftzdog commented 8 years ago

React ignores align property since this property is obsolete in HTML5. align is not listed as supported attribute: https://facebook.github.io/react/docs/tags-and-attributes.html It should use CSS instead.

wooorm commented 8 years ago

Interesting, was it dropped recently or never supported?

I guess we best add classes in that case, right? align-left, align-center, align-right? Inline styles seems like a bad idea.

craftzdog commented 8 years ago

I don't know when React started to ignore it. Adding classes looks OK for me.

craftzdog commented 8 years ago

But adding classes requires CSS styling in every application.

wooorm commented 8 years ago

I’d like to get someone else’s input on this as well, but I’m OK with requiring CSS: it’s better than inline styles at least.

craftzdog commented 8 years ago

found a way to avoid this issue using remarkReactComponents:

import React, { createElement } from 'react'
import remark from 'remark'
import remarkReact from 'remark-react'

function createTableCellComponent (tagName) {
  return class TableCell extends React.Component {
    render () {
      const style = { textAlign: this.props.align }
      const props = { ...this.props, style }
      return createElement(tagName, props, this.props.children)
    }
  }
}

const options = {
  remarkReactComponents: {
    td: createTableCellComponent('td'),
    th: createTableCellComponent('th')
  }
}
const processor = remark().use(remarkReact, options)
wooorm commented 8 years ago

@tmcw Any thoughts on this?

tmcw commented 8 years ago

I lean toward inline styles here - if we required a stylesheet for remark-react's output to be viewed correctly, I doubt many would include it. And GFM supports table alignment, so it seems like a complete implementation should include it.

jmca commented 7 years ago

I am running up against this issue creating email templates using React. Unfortunately I need to use many align attributes for legacy reasons.

wooorm commented 7 years ago

Hey folks! I try’d my hand at this after GH-32, by using style instead of align, but I forgot that the sanitation mechanism strips style tags away (as it’s not very safe to have style, just like classes, render by default).

I think it would be simplest to have a component handle this instead, something like remark-react-lowlight.

@noradaiko Would you be interested in creating something like that? (or maybe someone else?)

craftzdog commented 7 years ago

Do you mean that having a separate component from remark-react for it is good idea? I don't like it because the table align support is standard in GFM.

I think it's better to have a default remarkReactComponents for the table elements. It can be added here: https://github.com/mapbox/remark-react/blob/master/index.js#L36

Thanks!

wooorm commented 7 years ago

@noradaiko I think you’re right! I just pushed to GH-32 to use remarkReactComponents, and fix this!

craftzdog commented 7 years ago

Excellent!