tp: add documentation of macros in standard library

This CL implements the missing support of documentation generation for
macros defined in the standard library. It also fixes a bunch of small
bugs which cropped up while I was implementing this (i.e. improved
summary generation by splitting on \n\n instead of first sentence,
escaping of | in comments where they end up in tables etc.)

Bug: 321766342
Change-Id: I4e957840a80f170253684d6ec790e426ecfd1630
diff --git a/tools/gen_stdlib_docs_json.py b/tools/gen_stdlib_docs_json.py
index f5f8e5d..513b932 100755
--- a/tools/gen_stdlib_docs_json.py
+++ b/tools/gen_stdlib_docs_json.py
@@ -82,6 +82,7 @@
         'imports': [{
             'name': table.name,
             'desc': table.desc,
+            'summary_desc': table.desc.split('\n\n')[0].replace('\n', ' '),
             'type': table.type,
             'cols': {
                 col_name: {
@@ -93,6 +94,7 @@
         'functions': [{
             'name': function.name,
             'desc': function.desc,
+            'summary_desc': function.desc.split('\n\n')[0].replace('\n', ' '),
             'args': {
                 arg_name: {
                     'type': arg.type,
@@ -105,6 +107,7 @@
         'table_functions': [{
             'name': function.name,
             'desc': function.desc,
+            'summary_desc': function.desc.split('\n\n')[0].replace('\n', ' '),
             'args': {
                 arg_name: {
                     'type': arg.type,
@@ -118,6 +121,19 @@
                 } for (col_name, col) in function.cols.items()
             },
         } for function in docs.table_functions],
+        'macros': [{
+            'name': macro.name,
+            'desc': macro.desc,
+            'summary_desc': macro.desc.split('\n\n')[0].replace('\n', ' '),
+            'return_desc': macro.return_desc,
+            'return_type': macro.return_type,
+            'args': {
+                arg_name: {
+                    'type': arg.type,
+                    'desc': arg.description,
+                } for (arg_name, arg) in macro.args.items()
+            },
+        } for macro in docs.macros],
     }
     modules[module_name].append(file_dict)