Skip to content

Commit

Permalink
Update comment content list parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonamil committed Jul 16, 2024
1 parent e6de82a commit a9b1aef
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/components/CommentItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,26 +196,28 @@ domPurifyInstance.addHook('uponSanitizeElement', (node) => {
node.outerHTML = `<blockquote>${quoteHTML}</blockquote>`;
} else if (new RegExp('^(-|\\*) ?.').test(node.innerHTML)) {
// unordered list (starts with '-' or '*')
// unordered list (starts with dash or asterisk)
let listItemHTML = node.innerHTML;
while (new RegExp('^(-|\\*| )').test(listItemHTML)) {
listItemHTML = listItemHTML.substring(1);
}
listItemHTML = listItemHTML.replace(/\n(-|\*) ?/g, '</li></ul><ul><li>');
node.outerHTML = `<ul><li>${listItemHTML}</li></ul>`;
} else if (new RegExp('^\\d\\. .').test(node.innerHTML)) {
// ordered list (starts with single digit + '.')
const digit = node.innerHTML.match(/^\d/);
if (!digit) return;
} else if (new RegExp('^(\\d|[A-Z])(\\.|\\)) .').test(node.innerHTML)) {
// ordered list (starts with digit or uppercase letter followed by period or parenthesis)
const counter = node.innerHTML.match(/^(\d|[A-Z])/);
if (!counter) return;
let listItemHTML = node.innerHTML;
while (new RegExp('^(\\d|\\.| )').test(listItemHTML)) {
while (new RegExp('^(\\d|[A-Z](\\.|\\))|\\.|\\)| )').test(listItemHTML)) {
listItemHTML = listItemHTML.substring(1);
}
node.outerHTML = `<ol><li value="${digit[0]}">${listItemHTML}</li></ol>`;
node.outerHTML = `<ol><li value="${counter[0]}">${listItemHTML}</li></ol>`;
}
});
Expand Down

1 comment on commit a9b1aef

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for hackernews-dot-cool ready!

✅ Preview
https://hackernews-dot-cool-947dr1261-jonamil-56ba8df7.vercel.app

Built with commit a9b1aef.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.