Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not convert table in Number(MacOs app) to markdown #11

Closed
Jocs opened this issue Jun 5, 2018 · 3 comments
Closed

Can not convert table in Number(MacOs app) to markdown #11

Jocs opened this issue Jun 5, 2018 · 3 comments

Comments

@Jocs
Copy link

Jocs commented Jun 5, 2018

Hello, turndown is an excellent tool, and I was fortunate to be able to use it in Mark Text. However, I encountered some problems in the process of use. I didn't know if it was a new requirement or a bug, so I wrote this issue.

I want to copy the table in Number software to another place and turn it into markdown. The table html in Number is probably like this:

<table>
  <tbody>
    <tr>
      <td>hello</td>
      <td>world</td>
    </tr>
    <tr>
      <td>hello</td>
      <td>world</td>
    </tr>
    <tr>
      <td>hello</td>
      <td>world</td>
    </tr> 
  </tbody>
</table>

I look up the source code in this repo, and found that html above can not pass this function:

function isHeadingRow (tr) {
  var parentNode = tr.parentNode
  return (
    parentNode.nodeName === 'THEAD' ||
    (
      parentNode.firstChild === tr &&
      (parentNode.nodeName === 'TABLE' || isFirstTbody(parentNode)) &&
      every.call(tr.childNodes, function (n) { return n.nodeName === 'TH' })
    )
  )
}

Because the first row does not has TH cell. So turndown does not convert it to markdown.

Is this a bug or would you want to do this? I hope turndown can support html data copied from Number.

Thanks!

@domchristie
Copy link
Collaborator

This is not really a bug, because tables with no heading row do not convert to markdown. #10 is a possible solution to this issue, but there is some uncertainty as to whether this should be the default behaviour or if it should be a plugin.

@Jocs
Copy link
Author

Jocs commented Jun 5, 2018

I think this gfm plugin can add a strict mode option, the default value is true, when we want to convert these non-standard table, you can set the strict mode to false, so it will not change the previous behavior . What do you think?

@x8x
Copy link

x8x commented Sep 13, 2018

Had to check commits logs to find out why suddenly turndown stopped converting my tables without a header. Although this is good for compatibility with renderers, #10 saved my day and it would be very nice to have it included somehow.

@Jocs Jocs closed this as completed Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants