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

Unsupport format table with Chinese character #70

Open
xdc0209 opened this issue Sep 21, 2017 · 0 comments
Open

Unsupport format table with Chinese character #70

xdc0209 opened this issue Sep 21, 2017 · 0 comments

Comments

@xdc0209
Copy link

xdc0209 commented Sep 21, 2017

I set atom Font "新宋体"

My md is as below:

操作类型 操作 使用场景 参数与返回值
查询 HEAD 应用层心跳 通过URI Path片断或者查询参数传递参数,响应消息无Body

Format with tidy-markdown 2017-09-21_181020

Format with markdown-writer 2017-09-21_181135

I temporarily modify .atom\packages\tidy-markdown\node_modules\tidy-markdown\lib\tables.coffee to avoid the problem

longestStringInArray = (array) ->
  longest = 0
  for str in array
    ######### I modify here #########
    len = str.replace(/[^\u0000-\u00ff]/g,"aa").length;
    if len > longest then longest = len
  return longest
formatRow = (row, alignments, columnWidths) ->
  # apply padding around each cell for alignment and column width
  for i in [0...row.length]
    row[i] = (
      switch alignments[i]
        when 'right'
          pad(columnWidths[i], row[i])
        when 'center'
          # rounding causes a bias to the left because we can't have half a char
          whitespace = columnWidths[i] - row[i].length
          leftPadded = pad(Math.floor(whitespace / 2) + row[i].length, row[i])
          pad(leftPadded, Math.ceil(whitespace / 2) + leftPadded.length)
        else
          ######### I modify here #########
          # left is the default alignment when formatting
          pad(row[i], columnWidths[i] - (row[i].replace(/[^\u0000-\u00ff]/g,"aa").length - row[i].length))
    )

  # trimRight is to remove any trailing whitespace added by the padding
  joinColumns(row).trimRight()

I write coffeescript and javascript for the first time, the code is a bit ugly, hope you can fix it in the new realse.

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

1 participant