Azure DevOps 如何处理描述字段中的 HTML 结构更改?

问题描述 投票:0回答:1

我注意到 Azure DevOps 中关于元素描述字段的特殊行为。我通过带有 REST API 的程序自动添加一些在具有各种 ID 和类的 div 容器中构建的内容。但是,如果我手动将内容添加到 Azure DevOps 中的“描述”字段,整个 HTML 结构就会发生变化。 div 的 ID 和类将被删除,并且样式标签中包含的样式信息将作为属性添加到各个元素。

自动输入:

<div id="automaticInput">
<div class="category">Category 1: </div><br>
   <table>
     <tr>
        <td class="text">Some information about the item. </td>
        <td class="comment"> </td>
     </tr>
   </table><br>
</div>
<style>
   /*Some style*/
</style>

当我在 Azure 中手动添加一些文本时:

<div>
<div>Category 1: </div><br>
  <table style="border-collapse:collapse;width:100%;table-layout:fixed;">
    <tbody>
        <tr>
            <td style="vertical-align:top;text-align:left;width:80%;padding:10px;">Some 
                     information about the item.
                <br>Some new changes </td>
            <td
                style="vertical-align:top;text-align:left;padding:10px;border:1px solid 
                 rgb(221, 221, 221);background-color:beige;width:20%;">
            </td>
        </tr>
    </tbody>
  </table><br>
</div>

我很好奇 Azure DevOps 在进行这些更改时遵循的规则或标准。有没有办法防止这种情况发生,或者我应该遵循哪些准则来确保“描述”字段中的 HTML 结构保持一致?

html azure azure-devops azure-devops-rest-api azure-devops-server-2019
1个回答
0
投票

根据您的描述,我通过 API 使用一些简单的格式添加了工作项的注释,如下面的 PowerShell 脚本中所示。然后我收到了新评论并注意到

id=automaticInput
style
确实保留在回复中;自定义样式仍然没有反映在 Web UI 中。

$addCommentURL = "https://dev.azure.com/$organization/$project/_apis/wit/workItems/259/comments/?api-version=$apiVersion"
$headers = @{
    'Authorization' = 'Bearer ' + "$token"
    'Content-Type' = 'application/json'
}
$htmlContent = @"
<div id="automaticInput">
   <style>
      .category {
         font-weight: bold;
         color: yellow;
      }
      .text {
         font-size: 14px;
         color: #333;
      }
      .comment {
         color: yellow;
      }
   </style>
   <div class="category">Category 1: </div><br>
   <table>
      <tr>
         <td class="text">Some information about the item.</td>
         <td class="comment">XXXXXX</td>
      </tr>
   </table><br>
</div>
"@

# Create the comment payload
$commentPayload = @{
    text = $htmlContent
} | ConvertTo-Json

$commentPayload

$addComment = Invoke-RestMethod -Method Post -Uri $addCommentURL -Headers $headers -Body $commentPayload
$newCommentId = $addComment.id

# Comments - Get Comments GET https://dev.azure.com/{organization}/{project}/_apis/wit/workItems/{workItemId}/comments?api-version=7.2-preview.4
$getCommentURL = "https://dev.azure.com/$organization/$project/_apis/wit/workItems/259/comments/$($newCommentId)?api-version=$apiVersion"

$newComment = Invoke-RestMethod -Method Get -Uri $getCommentURL -Headers $headers

$newComment | ConvertTo-Json -Depth 100 | Out-File "E:\Alvin\Desktop\newComment.json"

在 Web UI 中编辑此注释时,我们可以检查浏览器开发工具(F12)发送的请求没有传达有效负载中的

id=automaticInput
style
部分。

Azure DevOps 工作项注释字段似乎不支持 Web UI 的此类 html 样式。

© www.soinside.com 2019 - 2024. All rights reserved.