API 不接受 MarkDown 表格

我们使用的是托管解决方案。

问题描述: 使用 API 发布帖子。过去 4 个月(最近一次是 2019 年 3 月 11 日星期一)一直运行完美,直到今天。我创建了几个非常简单的测试来缩小问题范围:

通过 API 发送的数据:

Col1 Col2
Col1data Col2data

结果截图:

请注意高亮显示的第一个标题与数据之间的分隔符。不知为何,它从三个连字符变成了整条线。第二个分隔符未发生变化。我认为这就是问题所在。由于第一列分隔符不再是三个连字符,系统不再将其解析为 Markdown 表格。我只是不知道是什么导致三个连字符变成了这个线条字符。

我在手动发帖时也能(部分)复现这种“连字符变为线条”的现象。如果我输入以下内容(注意第二列分隔符是三个连字符)……好吧,直到发布之前都是这样……
|Col1|Col2|
|___|—|
|Col1data|Col2data|

发布后,第二个分隔符实际上会显示为整条线。由于我是该网站的新用户,系统提示我无法发布超过两张图片(什么?),所以我无法展示确切截图,但这里有一个测试链接:https://try.discourse.org/t/test-table-cause-seeing-problem/1335

我相信导致连字符变为线条字符的原因,也是导致 API 中三个连字符发生变化的原因。但这只是我的猜测。

能否请某人帮忙解释一下?1) 为什么会发生这种情况?2) 最近是否有某些变更可能导致此问题?

Try disabling the setting enable markdown typographer

1 个赞

Thanks for the quick reply Rafael. That definitely got back the 3 dashes, but it still displays as plain text, instead of converting it to a table, like I would expect. So, quite possibly, what I thought was the issue was not :-(. Any other suggestions as to why this may not be displaying correctly as a table after posting thru the API?

image

Can you share the exact content of the post sent to the API here?

Not really - it’s a a PS script…the first line tho shows the data being passed in, and the result shown above…

 $HTMLTableAll = '|Col1|Col2|<br>|---|---|<br>|Col1data|Col2data|'

#Create Discourse JSON Body for posting new Topic
$DiscourseBodyJSON = @{}
$DiscourseBodyJSON.Add("title","Test - please ignore")
$DiscourseBodyJSON.Add("raw",$HTMLTableAll)
$DiscourseBodyJSON.Add("category",$TFOCategoryID)
$DiscourseDevNoteJSON = $DiscourseBodyJSON | ConvertTo-Json
$URI = $TWDomain + "posts.json" + $DiscourseCredsURI

Show-Log -LogType Txt -LogText $URI
Show-Log -LogType Txt -LogText $HTMLTableAll

$PostNote = @{Method     = 'POST'
             Uri         = $URI  
             ContentType = "application/json"
             Headers     = @{Authorization = "Basic " + [System.Convert]::ToBase64String($DiscourseUserEnc)}
             Body        = $DiscourseDevNoteJSON
            }

Result:

Actually, I have this working again. I think that settings change actually did fix this issue. Thanks for the help!

Only thing that jumps to me is that we use \n for line breaks in the API instead of <br>.

Anyway, since it’s working already, keep going.

4 个赞