misc: Use html.escape instead of cgi.escape

cgi has been removed from the standard library after PEP594
https://peps.python.org/pep-0594/

Change-Id: I684b305421ec684e45b02785e70580efa8f1beef
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/17900
Reviewed-by: Dirk Pranke <dpranke@google.com>
Commit-Queue: Dirk Pranke <dpranke@google.com>
Reviewed-by: Takuto Ikuta <tikuta@google.com>
diff --git a/misc/help_as_html.py b/misc/help_as_html.py
index 6a3fafb..e449094 100755
--- a/misc/help_as_html.py
+++ b/misc/help_as_html.py
@@ -11,7 +11,7 @@
 # - Convert "|blahblah|" to <code>.
 # - Spit out other similar formats like wiki, markdown, whatever.
 
-import cgi
+import html
 import subprocess
 import sys
 
@@ -34,14 +34,14 @@
       output_line = ['<li>']
       if not is_option:
         commands.append(command)
-        output_line.append('<a href="#' + cgi.escape(command) + '">')
-      output_line.append(cgi.escape(command))
+        output_line.append('<a href="#' + html.escape(command) + '">')
+      output_line.append(html.escape(command))
       if not is_option:
         output_line.append('</a>')
-      output_line.extend([sep + cgi.escape(rest) + '</li>'])
+      output_line.extend([sep + html.escape(rest) + '</li>'])
       output.append(''.join(output_line))
     else:
-      output.append('<h2>' + cgi.escape(line) + '</h2>')
+      output.append('<h2>' + html.escape(line) + '</h2>')
   return commands, output
 
 
@@ -53,8 +53,8 @@
     if first_line:
       name, sep, rest = line.partition(':')
       name = name.strip()
-      output.append('<h3><a name="' + cgi.escape(command) + '">' +
-                    cgi.escape(name + sep + rest) + '</a></h3>')
+      output.append('<h3><a name="' + html.escape(command) + '">' +
+                    html.escape(name + sep + rest) + '</a></h3>')
       first_line = False
     else:
       if line.startswith('Example'):
@@ -68,9 +68,9 @@
         output.append('<p>')
       elif not line.startswith('  ') and line.endswith(':'):
         # Subsection.
-        output.append('<h4>' + cgi.escape(line[:-1]) + '</h4>')
+        output.append('<h4>' + html.escape(line[:-1]) + '</h4>')
       else:
-        output.append(cgi.escape(line))
+        output.append(html.escape(line))
   if got_example:
     output.append('</pre>')
   return output