More marked use
This commit is contained in:
+83
-84
@@ -85,6 +85,7 @@ function loadIssuesFromFiles(fileRefs, issueType, elementId, applyIssueSearchFil
|
|||||||
allIssues.push({
|
allIssues.push({
|
||||||
id: issue.id || '',
|
id: issue.id || '',
|
||||||
summary: issue.summary || '',
|
summary: issue.summary || '',
|
||||||
|
caveat: issue.caveat || '',
|
||||||
sourceVersion
|
sourceVersion
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -142,90 +143,82 @@ function fetchIssueFile(productKey, fileName, issueType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseMarkdownIssues(markdownText) {
|
function parseMarkdownIssues(markdownText) {
|
||||||
const lines = String(stripMarkdownFrontmatter(markdownText) || '').split(/\r?\n/);
|
const input = String(stripMarkdownFrontmatter(markdownText) || '');
|
||||||
const issues = [];
|
if (!input.trim()) {
|
||||||
let currentIssue = null;
|
return [];
|
||||||
let inCaveatBlock = false;
|
|
||||||
let caveatLines = [];
|
|
||||||
|
|
||||||
lines.forEach(line => {
|
|
||||||
const issueHeaderMatch = line.match(/^##\s+(.+)$/);
|
|
||||||
if (issueHeaderMatch) {
|
|
||||||
finalizeMarkdownIssue(currentIssue, issues);
|
|
||||||
currentIssue = {
|
|
||||||
id: issueHeaderMatch[1].trim(),
|
|
||||||
descriptionLines: [],
|
|
||||||
caveat: ''
|
|
||||||
};
|
|
||||||
inCaveatBlock = false;
|
|
||||||
caveatLines = [];
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentIssue) {
|
try {
|
||||||
return;
|
const tokens = marked.lexer(input, {
|
||||||
}
|
gfm: true
|
||||||
|
|
||||||
if (/^```caveat\s*$/i.test(line.trim())) {
|
|
||||||
inCaveatBlock = true;
|
|
||||||
caveatLines = [];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inCaveatBlock) {
|
|
||||||
if (/^```\s*$/.test(line.trim())) {
|
|
||||||
currentIssue.caveat = caveatLines.join(' ').replace(/\s+/g, ' ').trim();
|
|
||||||
inCaveatBlock = false;
|
|
||||||
caveatLines = [];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const caveatLine = line.trim();
|
|
||||||
if (caveatLine) {
|
|
||||||
caveatLines.push(caveatLine);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const trimmed = line.trim();
|
|
||||||
if (!trimmed || /^---\s*$/.test(trimmed)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (/^(type|product|version|date):\s*/i.test(trimmed)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentIssue.descriptionLines.push(line.trimEnd());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
finalizeMarkdownIssue(currentIssue, issues);
|
const issues = [];
|
||||||
return issues;
|
let currentIssueId = '';
|
||||||
}
|
let currentIssueBodyParts = [];
|
||||||
|
let currentIssueCaveatBlocks = [];
|
||||||
|
|
||||||
function finalizeMarkdownIssue(issue, issues) {
|
const finalizeIssue = () => {
|
||||||
if (!issue || !issue.id) {
|
if (!currentIssueId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const description = Array.isArray(issue.descriptionLines)
|
const summaryBody = currentIssueBodyParts
|
||||||
? issue.descriptionLines
|
.join('')
|
||||||
.join('\n')
|
|
||||||
.replace(/\n{3,}/g, '\n\n')
|
.replace(/\n{3,}/g, '\n\n')
|
||||||
.trim()
|
.trim();
|
||||||
: '';
|
|
||||||
|
|
||||||
let summary = description;
|
const summary = summaryBody;
|
||||||
if (issue.caveat) {
|
const caveat = currentIssueCaveatBlocks.join('\n\n').trim();
|
||||||
summary = summary
|
|
||||||
? `[Caveat: ${issue.caveat}] ${summary}`
|
|
||||||
: `[Caveat: ${issue.caveat}]`;
|
|
||||||
}
|
|
||||||
|
|
||||||
issues.push({
|
issues.push({
|
||||||
id: issue.id,
|
id: currentIssueId,
|
||||||
summary
|
summary,
|
||||||
|
caveat
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
tokens.forEach(token => {
|
||||||
|
if (token.type === 'heading' && token.depth === 2) {
|
||||||
|
finalizeIssue();
|
||||||
|
currentIssueId = String(token.text || '').trim();
|
||||||
|
currentIssueBodyParts = [];
|
||||||
|
currentIssueCaveatBlocks = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!currentIssueId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token.type === 'code' && String(token.lang || '').trim().toLowerCase() === 'caveat') {
|
||||||
|
const caveatText = String(token.text || '').trim();
|
||||||
|
if (caveatText) {
|
||||||
|
currentIssueCaveatBlocks.push(caveatText);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token.type === 'space' || token.type === 'hr') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof token.raw === 'string' && token.raw) {
|
||||||
|
currentIssueBodyParts.push(token.raw);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof token.text === 'string' && token.text.trim()) {
|
||||||
|
currentIssueBodyParts.push(`${token.text.trim()}\n\n`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
finalizeIssue();
|
||||||
|
return issues;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Marked token parser failed.', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeIssuesFromPayload(data) {
|
function normalizeIssuesFromPayload(data) {
|
||||||
@@ -239,7 +232,8 @@ function normalizeIssuesFromPayload(data) {
|
|||||||
if (item.id && (item.description || item.summary)) {
|
if (item.id && (item.description || item.summary)) {
|
||||||
return {
|
return {
|
||||||
id: String(item.id).trim(),
|
id: String(item.id).trim(),
|
||||||
summary: String(item.summary || item.description).trim()
|
summary: String(item.summary || item.description).trim(),
|
||||||
|
caveat: String(item.caveat || '').trim()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +249,8 @@ function normalizeIssuesFromPayload(data) {
|
|||||||
if (issue && typeof issue === 'object' && issue.id && issue.description) {
|
if (issue && typeof issue === 'object' && issue.id && issue.description) {
|
||||||
return {
|
return {
|
||||||
id: String(issue.id).trim(),
|
id: String(issue.id).trim(),
|
||||||
summary: String(issue.description).trim()
|
summary: String(issue.description).trim(),
|
||||||
|
caveat: String(issue.caveat || '').trim()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return parseIssueLine(JSON.stringify(issue));
|
return parseIssueLine(JSON.stringify(issue));
|
||||||
@@ -394,16 +389,20 @@ function dedupeIssues(issues, versionKey) {
|
|||||||
issues.forEach(issue => {
|
issues.forEach(issue => {
|
||||||
const id = (issue.id || '').trim();
|
const id = (issue.id || '').trim();
|
||||||
const summary = (issue.summary || '').trim();
|
const summary = (issue.summary || '').trim();
|
||||||
|
const caveat = (issue.caveat || '').trim();
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
|
||||||
if (!map.has(id)) {
|
if (!map.has(id)) {
|
||||||
map.set(id, { id, summary, [versionKey]: [] });
|
map.set(id, { id, summary, caveat, [versionKey]: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const entry = map.get(id);
|
const entry = map.get(id);
|
||||||
if (!entry.summary && summary) {
|
if (!entry.summary && summary) {
|
||||||
entry.summary = summary;
|
entry.summary = summary;
|
||||||
}
|
}
|
||||||
|
if (!entry.caveat && caveat) {
|
||||||
|
entry.caveat = caveat;
|
||||||
|
}
|
||||||
|
|
||||||
const version = (issue.sourceVersion || '').trim();
|
const version = (issue.sourceVersion || '').trim();
|
||||||
if (version && !entry[versionKey].includes(version)) {
|
if (version && !entry[versionKey].includes(version)) {
|
||||||
@@ -441,7 +440,7 @@ function getSourceVersionFromFileName(fileName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderSummaryCell(cell, issue) {
|
function renderSummaryCell(cell, issue) {
|
||||||
cell.innerHTML = markdownSummaryToHtml(issue.summary);
|
cell.innerHTML = markdownSummaryToHtml(issue.summary, issue.caveat);
|
||||||
|
|
||||||
const refs = getSocialRefsForIssue(issue.id);
|
const refs = getSocialRefsForIssue(issue.id);
|
||||||
if (!refs.length) {
|
if (!refs.length) {
|
||||||
@@ -545,22 +544,22 @@ function sourceLabelFromKey(sourceKey) {
|
|||||||
.join(' ');
|
.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function markdownSummaryToHtml(summaryText) {
|
function markdownSummaryToHtml(summaryText, caveatText) {
|
||||||
const input = String(summaryText || '').trim();
|
const input = String(summaryText || '').trim();
|
||||||
if (!input) {
|
const caveat = String(caveatText || '').trim();
|
||||||
|
|
||||||
|
if (!input && !caveat) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const caveatMatch = input.match(/^\[Caveat:\s*([^\]]+)\]\s*/i);
|
|
||||||
const caveatText = caveatMatch ? caveatMatch[1].trim() : '';
|
|
||||||
const body = caveatMatch ? input.slice(caveatMatch[0].length) : input;
|
|
||||||
|
|
||||||
const htmlParts = [];
|
const htmlParts = [];
|
||||||
if (caveatText) {
|
if (caveat) {
|
||||||
htmlParts.push(`<div><em>Caveat: ${escapeHtml(caveatText)}</em></div>`);
|
htmlParts.push(`<div><em>Caveat: ${escapeHtml(caveat)}</em></div>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
htmlParts.push(renderMarkdownBodyToHtml(body));
|
if (input) {
|
||||||
|
htmlParts.push(renderMarkdownBodyToHtml(input));
|
||||||
|
}
|
||||||
return htmlParts.join('');
|
return htmlParts.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user