Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit dbf56c6

Browse files
munozemilioShuai Wang
andauthored
Cherry pick qna fix for escaped new lines in prompt display text (#1310)
* Escape new lines in prompt display text (#1308) * support escape char in qna prompt (#1309) Co-authored-by: Shuai Wang <[email protected]>
1 parent edcf63e commit dbf56c6

File tree

6 files changed

+419
-348
lines changed

6 files changed

+419
-348
lines changed

packages/lu/src/parser/lufile/LUFileParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ promptSection
230230
;
231231

232232
filterLine
233-
: WS* DASH (WS|TEXT)* newline
233+
: WS* DASH (WS|TEXT|ESCAPE_CHARACTER)* newline
234234
;
235235

236236
errorFilterLine

packages/lu/src/parser/lufile/generated/LUFileParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/lu/src/parser/lufile/generated/LUFileParser.js

Lines changed: 356 additions & 344 deletions
Large diffs are not rendered by default.

packages/lu/src/parser/qna/qnamaker/qnaConverter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const qnaToLuContent = function(qnaJSON){
4848
if (qnaItem.context && qnaItem.context.prompts && qnaItem.context.prompts.length !== 0) {
4949
fileContent += NEWLINE + '**Prompts:**' + NEWLINE;
5050
qnaItem.context.prompts.forEach(function(prompt) {
51-
fileContent += `- [${prompt.displayText}](#${prompt.qnaId})`;
51+
fileContent += `- [${prompt.displayText.replace(/\n/g, "\\n")}](#${prompt.qnaId})`;
5252
// See if the linked prompt is context only and if so, add the decoration.
5353
let promptQnA = root.find(item => item.id == prompt.qnaId);
5454
if (promptQnA) {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const QnA = require('./../../../src/parser/qna/qnamaker/qnaConverter')
2+
var chai = require('chai').expect;
3+
4+
describe('QnAMakerConverter', function() {
5+
it('New lines are escaped properly in prompt display text', async () => {
6+
const qnajson = {
7+
"qnaDocuments": [
8+
{
9+
"id": 1,
10+
"answer": "**Setting Up Sync Folders**\n\nYou decide which folders to synchronise to your computer from your web browser via [https://lion.app.box.com](https://lion.app.box.com/)",
11+
"source": "https://some.url",
12+
"questions": [
13+
"Using Box Sync"
14+
],
15+
"metadata": [
16+
{
17+
"name": "category1",
18+
"value": "it"
19+
},
20+
{
21+
"name": "category2",
22+
"value": "collaborations"
23+
},
24+
{
25+
"name": "category3",
26+
"value": "lion box"
27+
}
28+
],
29+
"alternateQuestionClusters": [],
30+
"context": {
31+
"isContextOnly": false,
32+
"prompts": [
33+
{
34+
"displayOrder": 1,
35+
"qnaId": 782,
36+
"displayText": "What \n Should You Sync"
37+
},
38+
{
39+
"displayOrder": 2,
40+
"qnaId": 783,
41+
"displayText": "Files that Cannot Sync\n"
42+
},
43+
{
44+
"displayOrder": 3,
45+
"qnaId": 784,
46+
"displayText": "Box Sync Status"
47+
}
48+
]
49+
},
50+
"lastUpdatedTimestamp": "2021-09-17T08:28:19.46+00:00",
51+
"isDocumentText": false,
52+
"extractionConfidence": -1
53+
}
54+
]
55+
}
56+
const markdown = QnA(qnajson)
57+
chai(markdown).to.contain("Files that Cannot Sync\\n");
58+
});
59+
});

packages/lu/test/parser/qna/qnaMakerBuilder.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('QnAMakerBuilder', function() {
4141
\`\`\`
4242
4343
**Prompts:**
44-
- [hi greeting](#hi)`;
44+
- [hi greeting\\n](#hi)`;
4545

4646
let qnaContent3 =
4747
`# ? hi

0 commit comments

Comments
 (0)