From 0e6908730165b9e030438bcedac6d54674ead5b0 Mon Sep 17 00:00:00 2001
From: Katsuya Hidaka <hidakatsuya@gmail.com>
Date: Mon, 23 Sep 2024 01:42:27 +0900
Subject: [PATCH 8/8] Modified to simpler implementation and improved code
 comments

---
 app/assets/javascripts/quote_reply.js | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/app/assets/javascripts/quote_reply.js b/app/assets/javascripts/quote_reply.js
index 95cf2c433..7649f5125 100644
--- a/app/assets/javascripts/quote_reply.js
+++ b/app/assets/javascripts/quote_reply.js
@@ -77,7 +77,6 @@ class QuoteTextFormatter {
     // Remove all unnecessary anchor elements
     fragment.querySelectorAll('a.wiki-anchor').forEach(e => e.remove());
 
-    // Adjust line breaks when output as text
     const html = this.adjustLineBreaks(fragment.innerHTML);
 
     const result = document.createElement('div');
@@ -171,7 +170,8 @@ class QuoteCommonMarkFormatter {
       }
     });
 
-    // Table elements are not formatted, and the within the table is output as is.
+    // Table does not maintain its original format,
+    // and the text within the table is displayed as it is
     //
     // | A | B | C |
     // |---|---|---|
@@ -180,9 +180,7 @@ class QuoteCommonMarkFormatter {
     // A B C
     // 1 2 3
     turndownService.addRule('table', {
-      filter: (node, options) => {
-        return node.nodeName === 'TD' || node.nodeName === 'TH';
-      },
+      filter: ['td', 'th'],
       replacement: (content, node) => {
         const separator = node.parentElement.lastElementChild === node ? '' : ' ';
         return content + separator;
@@ -207,7 +205,7 @@ class QuoteCommonMarkFormatter {
     // <h1>Title1<a href="#Title" class="wiki-anchor">¶</a></h1> => <h1>Title1</h1>
     htmlFragment.querySelectorAll('a.wiki-anchor').forEach(e => e.remove());
 
-    // Convert code highlight blocks to CommonMark code blocks.
+    // Convert code highlight blocks to CommonMark format code blocks.
     // <code class="ruby" data-language="ruby"> => <code class="language-ruby" data-language="ruby">
     htmlFragment.querySelectorAll('code[data-language]').forEach(e => {
       e.classList.replace(e.dataset['language'], 'language-' + e.dataset['language'])
-- 
2.45.2

