From 274f73d117ae109f32d12578bd033e2a67b26204 Mon Sep 17 00:00:00 2001 From: Suyash Vardhan Mathur Date: Wed, 2 Jun 2021 22:06:25 +0530 Subject: [PATCH] apidocs: Automatically add javascript example tabs. The javascript tab in .md templates can be generated along with the line that adds js example. Further, as a part of the effort of moving towards a single template, the markdown extension for javascrit examples is modified to return empty string if javascript example doesn't exist for that endpoint. This would make it possible to cover more endpoints with a single template. The js example tabs are now automatically generated during generation of javascript code, and so need to be removed. Also, the markdown function to render js examples can be added in all templates, since it is parses and returns an empty string if the examples don't exist, and allows us to move towards a common template. The pages have been verified to be correct by using diff between old and new pages' raw HTML. --- templates/zerver/api/add-code-playground.md | 2 ++ templates/zerver/api/add-linkifier.md | 2 ++ templates/zerver/api/add-reaction.md | 2 ++ templates/zerver/api/archive-stream.md | 2 ++ templates/zerver/api/check-messages-match-narrow.md | 2 ++ templates/zerver/api/create-custom-profile-field.md | 2 ++ templates/zerver/api/create-user-group.md | 2 ++ templates/zerver/api/create-user.md | 4 ---- templates/zerver/api/deactivate-own-user.md | 2 ++ templates/zerver/api/deactivate-user.md | 2 ++ templates/zerver/api/delete-message.md | 2 ++ templates/zerver/api/delete-queue.md | 4 ---- templates/zerver/api/get-attachments.md | 2 ++ templates/zerver/api/get-custom-emoji.md | 4 ---- templates/zerver/api/get-custom-profile-fields.md | 2 ++ templates/zerver/api/get-events.md | 4 ---- templates/zerver/api/get-linkifiers.md | 2 ++ templates/zerver/api/get-message-history.md | 2 ++ templates/zerver/api/get-messages.md | 4 ---- templates/zerver/api/get-own-user.md | 4 ---- templates/zerver/api/get-raw-message.md | 2 ++ templates/zerver/api/get-server-settings.md | 2 ++ templates/zerver/api/get-stream-id.md | 4 ---- templates/zerver/api/get-stream-topics.md | 4 ---- templates/zerver/api/get-streams.md | 4 ---- templates/zerver/api/get-subscription-status.md | 2 ++ templates/zerver/api/get-subscriptions.md | 4 ---- templates/zerver/api/get-user-by-email.md | 2 ++ templates/zerver/api/get-user-groups.md | 2 ++ templates/zerver/api/get-user-presence.md | 2 ++ templates/zerver/api/get-user.md | 2 ++ templates/zerver/api/get-users.md | 4 ---- templates/zerver/api/mark-all-as-read.md | 6 ++++++ templates/zerver/api/mute-topic.md | 2 ++ templates/zerver/api/mute-user.md | 2 ++ templates/zerver/api/reactivate-user.md | 2 ++ templates/zerver/api/register-queue.md | 4 ---- templates/zerver/api/remove-code-playground.md | 2 ++ templates/zerver/api/remove-linkifier.md | 2 ++ templates/zerver/api/remove-reaction.md | 2 ++ templates/zerver/api/remove-user-group.md | 2 ++ templates/zerver/api/render-message.md | 4 ---- templates/zerver/api/reorder-custom-profile-fields.md | 2 ++ templates/zerver/api/send-message.md | 4 ---- templates/zerver/api/set-typing-status.md | 4 ---- templates/zerver/api/subscribe.md | 4 ---- templates/zerver/api/unmute-user.md | 2 ++ templates/zerver/api/unsubscribe.md | 4 ---- templates/zerver/api/update-display-settings.md | 2 ++ templates/zerver/api/update-linkifier.md | 2 ++ templates/zerver/api/update-message-flags.md | 4 ---- templates/zerver/api/update-message.md | 4 ---- templates/zerver/api/update-notification-settings.md | 2 ++ templates/zerver/api/update-stream.md | 2 ++ templates/zerver/api/update-subscription-settings.md | 2 ++ templates/zerver/api/update-user-group-members.md | 2 ++ templates/zerver/api/update-user-group.md | 2 ++ templates/zerver/api/update-user.md | 2 ++ templates/zerver/api/upload-custom-emoji.md | 2 ++ templates/zerver/api/upload-file.md | 2 ++ zerver/openapi/markdown_extension.py | 9 +++++++-- zerver/templatetags/app_filters.py | 6 ++++-- 62 files changed, 97 insertions(+), 80 deletions(-) diff --git a/templates/zerver/api/add-code-playground.md b/templates/zerver/api/add-code-playground.md index 15da521eb0..3fadf83410 100644 --- a/templates/zerver/api/add-code-playground.md +++ b/templates/zerver/api/add-code-playground.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/realm/playgrounds:post|example} +{generate_code_example(javascript)|/realm/playgrounds:post|example} + {tab|curl} {generate_code_example(curl)|/realm/playgrounds:post|example} diff --git a/templates/zerver/api/add-linkifier.md b/templates/zerver/api/add-linkifier.md index ca35a3c91d..2ce5243129 100644 --- a/templates/zerver/api/add-linkifier.md +++ b/templates/zerver/api/add-linkifier.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/realm/filters:post|example} +{generate_code_example(javascript)|/realm/filters:post|example} + {tab|curl} {generate_code_example(curl)|/realm/filters:post|example} diff --git a/templates/zerver/api/add-reaction.md b/templates/zerver/api/add-reaction.md index 235609a490..466c0c9133 100644 --- a/templates/zerver/api/add-reaction.md +++ b/templates/zerver/api/add-reaction.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/messages/{message_id}/reactions:post|example} +{generate_code_example(javascript)|/messages/{message_id}/reactions:post|example} + {tab|curl} {generate_code_example(curl, exclude=["emoji_code","reaction_type"])|/messages/{message_id}/reactions:post|example} diff --git a/templates/zerver/api/archive-stream.md b/templates/zerver/api/archive-stream.md index a0942f02e4..9a523de7ee 100644 --- a/templates/zerver/api/archive-stream.md +++ b/templates/zerver/api/archive-stream.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/streams/{stream_id}:delete|example} +{generate_code_example(javascript)|/streams/{stream_id}:delete|example} + {tab|curl} {generate_code_example(curl)|/streams/{stream_id}:delete|example} diff --git a/templates/zerver/api/check-messages-match-narrow.md b/templates/zerver/api/check-messages-match-narrow.md index 1b30236c00..ab836aab86 100644 --- a/templates/zerver/api/check-messages-match-narrow.md +++ b/templates/zerver/api/check-messages-match-narrow.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/messages/matches_narrow:get|example} +{generate_code_example(javascript)|/messages/matches_narrow:get|example} + {tab|curl} {generate_code_example(curl)|/messages/matches_narrow:get|example} diff --git a/templates/zerver/api/create-custom-profile-field.md b/templates/zerver/api/create-custom-profile-field.md index 3dcec9cf49..07d9d59276 100644 --- a/templates/zerver/api/create-custom-profile-field.md +++ b/templates/zerver/api/create-custom-profile-field.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/realm/profile_fields:post|example(admin_config=True)} +{generate_code_example(javascript)|/realm/profile_fields:post|example} + {tab|curl} {generate_code_example(curl)|/realm/profile_fields:post|example} diff --git a/templates/zerver/api/create-user-group.md b/templates/zerver/api/create-user-group.md index 8024e7d035..0a8f399157 100644 --- a/templates/zerver/api/create-user-group.md +++ b/templates/zerver/api/create-user-group.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/user_groups/create:post|example} +{generate_code_example(javascript)|/user_groups/create:post|example} + {tab|curl} {generate_code_example(curl)|/user_groups/create:post|example} diff --git a/templates/zerver/api/create-user.md b/templates/zerver/api/create-user.md index f3c08e7e0d..8b234adc6f 100644 --- a/templates/zerver/api/create-user.md +++ b/templates/zerver/api/create-user.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/users:post|example(admin_config=True)} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/users:post|example(admin_config=True)} {tab|curl} diff --git a/templates/zerver/api/deactivate-own-user.md b/templates/zerver/api/deactivate-own-user.md index 5bec4b1cb8..5e1b006c69 100644 --- a/templates/zerver/api/deactivate-own-user.md +++ b/templates/zerver/api/deactivate-own-user.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/me:delete|example} +{generate_code_example(javascript)|/users/me:delete|example} + {tab|curl} {generate_code_example(curl)|/users/me:delete|example} diff --git a/templates/zerver/api/deactivate-user.md b/templates/zerver/api/deactivate-user.md index 8f3acf18d5..97715ee4ce 100644 --- a/templates/zerver/api/deactivate-user.md +++ b/templates/zerver/api/deactivate-user.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/{user_id}:delete|example} +{generate_code_example(javascript)|/users/{user_id}:delete|example} + {tab|curl} {generate_code_example(curl)|/users/{user_id}:delete|example} diff --git a/templates/zerver/api/delete-message.md b/templates/zerver/api/delete-message.md index 657ed79b20..3c5817e5d5 100644 --- a/templates/zerver/api/delete-message.md +++ b/templates/zerver/api/delete-message.md @@ -11,6 +11,8 @@ {generate_code_example(python)|/messages/{message_id}:delete|example(admin_config=True)} +{generate_code_example(javascript)|/messages/{message_id}:delete|example} + {tab|curl} {generate_code_example(curl)|/messages/{message_id}:delete|example} diff --git a/templates/zerver/api/delete-queue.md b/templates/zerver/api/delete-queue.md index 5531f86c43..68e84afb9f 100644 --- a/templates/zerver/api/delete-queue.md +++ b/templates/zerver/api/delete-queue.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/events:delete|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/events:delete|example} {tab|curl} diff --git a/templates/zerver/api/get-attachments.md b/templates/zerver/api/get-attachments.md index b565ec3bbd..57258de83e 100644 --- a/templates/zerver/api/get-attachments.md +++ b/templates/zerver/api/get-attachments.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/attachments:get|example} +{generate_code_example(javascript)|/attachments:get|example} + {tab|curl} {generate_code_example(curl)|/attachments:get|example} diff --git a/templates/zerver/api/get-custom-emoji.md b/templates/zerver/api/get-custom-emoji.md index 7e539eb9d7..f7ab7106d1 100644 --- a/templates/zerver/api/get-custom-emoji.md +++ b/templates/zerver/api/get-custom-emoji.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/realm/emoji:get|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/realm/emoji:get|example} {tab|curl} diff --git a/templates/zerver/api/get-custom-profile-fields.md b/templates/zerver/api/get-custom-profile-fields.md index cf7377c4e7..c3833c2132 100644 --- a/templates/zerver/api/get-custom-profile-fields.md +++ b/templates/zerver/api/get-custom-profile-fields.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/realm/profile_fields:get|example} +{generate_code_example(javascript)|/realm/profile_fields:get|example} + {tab|curl} {generate_code_example(curl)|/realm/profile_fields:get|example} diff --git a/templates/zerver/api/get-events.md b/templates/zerver/api/get-events.md index a5d8d4ded9..3a765239d3 100644 --- a/templates/zerver/api/get-events.md +++ b/templates/zerver/api/get-events.md @@ -28,10 +28,6 @@ print(client.get_events( `call_on_each_message` and `call_on_each_event` will automatically register a queue for you. -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/events:get|example} {tab|curl} diff --git a/templates/zerver/api/get-linkifiers.md b/templates/zerver/api/get-linkifiers.md index 31acc9a53f..2283376ca6 100644 --- a/templates/zerver/api/get-linkifiers.md +++ b/templates/zerver/api/get-linkifiers.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/realm/linkifiers:get|example} +{generate_code_example(javascript)|/realm/linkifiers:get|example} + {tab|curl} {generate_code_example(curl)|/realm/linkifiers:get|example} diff --git a/templates/zerver/api/get-message-history.md b/templates/zerver/api/get-message-history.md index 658f63ef2d..3e763c9eef 100644 --- a/templates/zerver/api/get-message-history.md +++ b/templates/zerver/api/get-message-history.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/messages/{message_id}/history:get|example} +{generate_code_example(javascript)|/messages/{message_id}/history:get|example} + {tab|curl} {generate_code_example(curl)|/messages/{message_id}/history:get|example} diff --git a/templates/zerver/api/get-messages.md b/templates/zerver/api/get-messages.md index a2bc12fcc6..c887d032b5 100644 --- a/templates/zerver/api/get-messages.md +++ b/templates/zerver/api/get-messages.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/messages:get|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/messages:get|example} {tab|curl} diff --git a/templates/zerver/api/get-own-user.md b/templates/zerver/api/get-own-user.md index 4c097a68a8..3a7ae3ab79 100644 --- a/templates/zerver/api/get-own-user.md +++ b/templates/zerver/api/get-own-user.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/users/me:get|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/users/me:get|example} {tab|curl} diff --git a/templates/zerver/api/get-raw-message.md b/templates/zerver/api/get-raw-message.md index 493e8f2931..088d78b56e 100644 --- a/templates/zerver/api/get-raw-message.md +++ b/templates/zerver/api/get-raw-message.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/messages/{message_id}:get|example} +{generate_code_example(javascript)|/messages/{message_id}:get|example} + {tab|curl} {generate_code_example(curl)|/messages/{message_id}:get|example} diff --git a/templates/zerver/api/get-server-settings.md b/templates/zerver/api/get-server-settings.md index b909ac9e92..608543b272 100644 --- a/templates/zerver/api/get-server-settings.md +++ b/templates/zerver/api/get-server-settings.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/server_settings:get|example} +{generate_code_example(javascript)|/server_settings:get|example} + {tab|curl} {generate_code_example(curl)|/server_settings:get|example} diff --git a/templates/zerver/api/get-stream-id.md b/templates/zerver/api/get-stream-id.md index d83f19121e..dc659f96f5 100644 --- a/templates/zerver/api/get-stream-id.md +++ b/templates/zerver/api/get-stream-id.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/get_stream_id:get|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/get_stream_id:get|example} {tab|curl} diff --git a/templates/zerver/api/get-stream-topics.md b/templates/zerver/api/get-stream-topics.md index 7a796f74f0..df299adcbe 100644 --- a/templates/zerver/api/get-stream-topics.md +++ b/templates/zerver/api/get-stream-topics.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/users/me/{stream_id}/topics:get|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/users/me/{stream_id}/topics:get|example} {tab|curl} diff --git a/templates/zerver/api/get-streams.md b/templates/zerver/api/get-streams.md index ad3e85b84c..bead278431 100644 --- a/templates/zerver/api/get-streams.md +++ b/templates/zerver/api/get-streams.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/streams:get|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/streams:get|example} {tab|curl} diff --git a/templates/zerver/api/get-subscription-status.md b/templates/zerver/api/get-subscription-status.md index ff417aa5d5..03421b504d 100644 --- a/templates/zerver/api/get-subscription-status.md +++ b/templates/zerver/api/get-subscription-status.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/{user_id}/subscriptions/{stream_id}:get|example} +{generate_code_example(javascript)|/users/{user_id}/subscriptions/{stream_id}:get|example} + {tab|curl} {generate_code_example(curl)|/users/{user_id}/subscriptions/{stream_id}:get|example} diff --git a/templates/zerver/api/get-subscriptions.md b/templates/zerver/api/get-subscriptions.md index 903328e8cd..72e68c92d2 100644 --- a/templates/zerver/api/get-subscriptions.md +++ b/templates/zerver/api/get-subscriptions.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/users/me/subscriptions:get|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/users/me/subscriptions:get|example} {tab|curl} diff --git a/templates/zerver/api/get-user-by-email.md b/templates/zerver/api/get-user-by-email.md index 9e983bfd1f..5c288e931b 100644 --- a/templates/zerver/api/get-user-by-email.md +++ b/templates/zerver/api/get-user-by-email.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/{email}:get|example} +{generate_code_example(javascript)|/users/{email}:get|example} + {tab|curl} {generate_code_example(curl, include=[""])|/users/{email}:get|example} diff --git a/templates/zerver/api/get-user-groups.md b/templates/zerver/api/get-user-groups.md index cd02093669..03de66c1ee 100644 --- a/templates/zerver/api/get-user-groups.md +++ b/templates/zerver/api/get-user-groups.md @@ -11,6 +11,8 @@ {generate_code_example(python)|/user_groups:get|example} +{generate_code_example(javascript)|/user_groups:get|example} + {tab|curl} {generate_code_example(curl)|/user_groups:get|example} diff --git a/templates/zerver/api/get-user-presence.md b/templates/zerver/api/get-user-presence.md index 09f8c4e4bd..5be2f9fd91 100644 --- a/templates/zerver/api/get-user-presence.md +++ b/templates/zerver/api/get-user-presence.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/{user_id_or_email}/presence:get|example} +{generate_code_example(javascript)|/users/{user_id_or_email}/presence:get|example} + {tab|curl} {generate_code_example(curl)|/users/{user_id_or_email}/presence:get|example} diff --git a/templates/zerver/api/get-user.md b/templates/zerver/api/get-user.md index f1e2852b78..da7f6db7c9 100644 --- a/templates/zerver/api/get-user.md +++ b/templates/zerver/api/get-user.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/{user_id}:get|example} +{generate_code_example(javascript)|/users/{user_id}:get|example} + {tab|curl} {generate_code_example(curl, include=[""])|/users/{user_id}:get|example} diff --git a/templates/zerver/api/get-users.md b/templates/zerver/api/get-users.md index c48a8f39ac..0a6875099b 100644 --- a/templates/zerver/api/get-users.md +++ b/templates/zerver/api/get-users.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/users:get|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/users:get|example} {tab|curl} diff --git a/templates/zerver/api/mark-all-as-read.md b/templates/zerver/api/mark-all-as-read.md index 74b7601139..d0eebb859e 100644 --- a/templates/zerver/api/mark-all-as-read.md +++ b/templates/zerver/api/mark-all-as-read.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/mark_all_as_read:post|example} +{generate_code_example(javascript)|/mark_all_as_read:post|example} + {tab|curl} {generate_code_example(curl)|/mark_all_as_read:post|example} @@ -40,6 +42,8 @@ {generate_code_example(python)|/mark_stream_as_read:post|example} +{generate_code_example(javascript)|/mark_all_as_read:post|example} + {tab|curl} {generate_code_example(curl)|/mark_stream_as_read:post|example} @@ -72,6 +76,8 @@ {generate_code_example(python)|/mark_topic_as_read:post|example} +{generate_code_example(javascript)|/mark_all_as_read:post|example} + {tab|curl} {generate_code_example(curl)|/mark_topic_as_read:post|example} diff --git a/templates/zerver/api/mute-topic.md b/templates/zerver/api/mute-topic.md index 728fe5ea30..d0d41dea93 100644 --- a/templates/zerver/api/mute-topic.md +++ b/templates/zerver/api/mute-topic.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/me/subscriptions/muted_topics:patch|example} +{generate_code_example(javascript)|/users/me/subscriptions/muted_topics:patch|example} + {tab|curl} {generate_code_example(curl, exclude=["stream_id"])|/users/me/subscriptions/muted_topics:patch|example} diff --git a/templates/zerver/api/mute-user.md b/templates/zerver/api/mute-user.md index bf00576455..11fd129d50 100644 --- a/templates/zerver/api/mute-user.md +++ b/templates/zerver/api/mute-user.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/me/muted_users/{muted_user_id}:post|example} +{generate_code_example(javascript)|/users/me/muted_users/{muted_user_id}:post|example} + {tab|curl} {generate_code_example(curl)|/users/me/muted_users/{muted_user_id}:post|example} diff --git a/templates/zerver/api/reactivate-user.md b/templates/zerver/api/reactivate-user.md index b03e718bd8..81f556d444 100644 --- a/templates/zerver/api/reactivate-user.md +++ b/templates/zerver/api/reactivate-user.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/{user_id}/reactivate:post|example} +{generate_code_example(javascript)|/users/{user_id}/reactivate:post|example} + {tab|curl} {generate_code_example(curl)|/users/{user_id}/reactivate:post|example} diff --git a/templates/zerver/api/register-queue.md b/templates/zerver/api/register-queue.md index fda84829d8..3388cae7bd 100644 --- a/templates/zerver/api/register-queue.md +++ b/templates/zerver/api/register-queue.md @@ -52,10 +52,6 @@ potentially messy races, etc. {generate_code_example(python)|/register:post|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/register:post|example} {tab|curl} diff --git a/templates/zerver/api/remove-code-playground.md b/templates/zerver/api/remove-code-playground.md index 23b4114a6e..009ddad4cb 100644 --- a/templates/zerver/api/remove-code-playground.md +++ b/templates/zerver/api/remove-code-playground.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/realm/playgrounds/{playground_id}:delete|example} +{generate_code_example(javascript)|/realm/playgrounds/{playground_id}:delete|example} + {tab|curl} {generate_code_example(curl)|/realm/playgrounds/{playground_id}:delete|example} diff --git a/templates/zerver/api/remove-linkifier.md b/templates/zerver/api/remove-linkifier.md index 776a1b9123..b3c8bed03b 100644 --- a/templates/zerver/api/remove-linkifier.md +++ b/templates/zerver/api/remove-linkifier.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/realm/filters/{filter_id}:delete|example} +{generate_code_example(javascript)|/realm/filters/{filter_id}:delete|example} + {tab|curl} {generate_code_example(curl)|/realm/filters/{filter_id}:delete|example} diff --git a/templates/zerver/api/remove-reaction.md b/templates/zerver/api/remove-reaction.md index 754e6e0751..4790782b4d 100644 --- a/templates/zerver/api/remove-reaction.md +++ b/templates/zerver/api/remove-reaction.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/messages/{message_id}/reactions:delete|example} +{generate_code_example(javascript)|/messages/{message_id}/reactions:delete|example} + {tab|curl} {generate_code_example(curl, exclude=["emoji_code", "reaction_type"])|/messages/{message_id}/reactions:delete|example} diff --git a/templates/zerver/api/remove-user-group.md b/templates/zerver/api/remove-user-group.md index b73b32a12d..88382eb4e5 100644 --- a/templates/zerver/api/remove-user-group.md +++ b/templates/zerver/api/remove-user-group.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/user_groups/{user_group_id}:delete|example} +{generate_code_example(javascript)|/user_groups/{user_group_id}:delete|example} + {tab|curl} {generate_code_example(curl)|/user_groups/{user_group_id}:delete|example} diff --git a/templates/zerver/api/render-message.md b/templates/zerver/api/render-message.md index a3f75275a0..3439c52c49 100644 --- a/templates/zerver/api/render-message.md +++ b/templates/zerver/api/render-message.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/messages/render:post|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/messages/render:post|example} {tab|curl} diff --git a/templates/zerver/api/reorder-custom-profile-fields.md b/templates/zerver/api/reorder-custom-profile-fields.md index 8144bd803a..850d5e51be 100644 --- a/templates/zerver/api/reorder-custom-profile-fields.md +++ b/templates/zerver/api/reorder-custom-profile-fields.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/realm/profile_fields:patch|example(admin_config=True)} +{generate_code_example(javascript)|/realm/profile_fields:patch|example} + {tab|curl} {generate_code_example(curl)|/realm/profile_fields:patch|example} diff --git a/templates/zerver/api/send-message.md b/templates/zerver/api/send-message.md index 3b5f6f04a9..35918ffc1d 100644 --- a/templates/zerver/api/send-message.md +++ b/templates/zerver/api/send-message.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/messages:post|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/messages:post|example} {tab|curl} diff --git a/templates/zerver/api/set-typing-status.md b/templates/zerver/api/set-typing-status.md index 417b58217e..17114b5ebc 100644 --- a/templates/zerver/api/set-typing-status.md +++ b/templates/zerver/api/set-typing-status.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/typing:post|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/typing:post|example} {tab|curl} diff --git a/templates/zerver/api/subscribe.md b/templates/zerver/api/subscribe.md index aa0e4b9fcc..a3f3d3f9ea 100644 --- a/templates/zerver/api/subscribe.md +++ b/templates/zerver/api/subscribe.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/users/me/subscriptions:post|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/users/me/subscriptions:post|example} {tab|curl} diff --git a/templates/zerver/api/unmute-user.md b/templates/zerver/api/unmute-user.md index 0a3c259cc2..4d8240ca72 100644 --- a/templates/zerver/api/unmute-user.md +++ b/templates/zerver/api/unmute-user.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/me/muted_users/{muted_user_id}:delete|example} +{generate_code_example(javascript)|/users/me/muted_users/{muted_user_id}:delete|example} + {tab|curl} {generate_code_example(curl)|/users/me/muted_users/{muted_user_id}:delete|example} diff --git a/templates/zerver/api/unsubscribe.md b/templates/zerver/api/unsubscribe.md index 71b81c3c4c..1b0c9fcd11 100644 --- a/templates/zerver/api/unsubscribe.md +++ b/templates/zerver/api/unsubscribe.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/users/me/subscriptions:delete|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/users/me/subscriptions:delete|example} {tab|curl} diff --git a/templates/zerver/api/update-display-settings.md b/templates/zerver/api/update-display-settings.md index e4a10cee1d..33c929963e 100644 --- a/templates/zerver/api/update-display-settings.md +++ b/templates/zerver/api/update-display-settings.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/settings/display:patch|example} +{generate_code_example(javascript)|/settings/display:patch|example} + {tab|curl} {generate_code_example(curl, include=["left_side_userlist", "emojiset"])|/settings/display:patch|example} diff --git a/templates/zerver/api/update-linkifier.md b/templates/zerver/api/update-linkifier.md index 8ea727faf8..8607955ef8 100644 --- a/templates/zerver/api/update-linkifier.md +++ b/templates/zerver/api/update-linkifier.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/realm/filters/{filter_id}:patch|example} +{generate_code_example(javascript)|/realm/filters/{filter_id}:patch|example} + {tab|curl} {generate_code_example(curl)|/realm/filters/{filter_id}:patch|example} diff --git a/templates/zerver/api/update-message-flags.md b/templates/zerver/api/update-message-flags.md index a99e0d5616..cfef53b9b4 100644 --- a/templates/zerver/api/update-message-flags.md +++ b/templates/zerver/api/update-message-flags.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/messages/flags:post|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/messages/flags:post|example} {tab|curl} diff --git a/templates/zerver/api/update-message.md b/templates/zerver/api/update-message.md index 5d2f5fb652..c91c1e904d 100644 --- a/templates/zerver/api/update-message.md +++ b/templates/zerver/api/update-message.md @@ -9,10 +9,6 @@ {generate_code_example(python)|/messages/{message_id}:patch|example} -{tab|js} - -More examples and documentation can be found [here](https://github.com/zulip/zulip-js). - {generate_code_example(javascript)|/messages/{message_id}:patch|example} {tab|curl} diff --git a/templates/zerver/api/update-notification-settings.md b/templates/zerver/api/update-notification-settings.md index 84d1d396fc..45bbc3b42b 100644 --- a/templates/zerver/api/update-notification-settings.md +++ b/templates/zerver/api/update-notification-settings.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/settings/notifications:patch|example} +{generate_code_example(javascript)|/settings/notifications:patch|example} + {tab|curl} {generate_code_example(curl, include=["enable_offline_push_notifications", "enable_online_push_notifications"])|/settings/notifications:patch|example} diff --git a/templates/zerver/api/update-stream.md b/templates/zerver/api/update-stream.md index fc6e235447..53ea64f677 100644 --- a/templates/zerver/api/update-stream.md +++ b/templates/zerver/api/update-stream.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/streams/{stream_id}:patch|example} +{generate_code_example(javascript)|/streams/{stream_id}:patch|example} + {tab|curl} {generate_code_example(curl, include=["new_name", "description", "is_private"])|/streams/{stream_id}:patch|example} diff --git a/templates/zerver/api/update-subscription-settings.md b/templates/zerver/api/update-subscription-settings.md index 8f4589e658..5801829dcb 100644 --- a/templates/zerver/api/update-subscription-settings.md +++ b/templates/zerver/api/update-subscription-settings.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/me/subscriptions/properties:post|example} +{generate_code_example(javascript)|/users/me/subscriptions/properties:post|example} + {tab|curl} {generate_code_example(curl)|/users/me/subscriptions/properties:post|example} diff --git a/templates/zerver/api/update-user-group-members.md b/templates/zerver/api/update-user-group-members.md index c77bf5f29b..93a5803189 100644 --- a/templates/zerver/api/update-user-group-members.md +++ b/templates/zerver/api/update-user-group-members.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/user_groups/{user_group_id}/members:post|example} +{generate_code_example(javascript)|/user_groups/{user_group_id}/members:post|example} + {tab|curl} {generate_code_example(curl, exclude=["delete"])|/user_groups/{user_group_id}/members:post|example} diff --git a/templates/zerver/api/update-user-group.md b/templates/zerver/api/update-user-group.md index 6916d99666..1bf80d8037 100644 --- a/templates/zerver/api/update-user-group.md +++ b/templates/zerver/api/update-user-group.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/user_groups/{user_group_id}:patch|example} +{generate_code_example(javascript)|/user_groups/{user_group_id}:patch|example} + {tab|curl} {generate_code_example(curl)|/user_groups/{user_group_id}:patch|example} diff --git a/templates/zerver/api/update-user.md b/templates/zerver/api/update-user.md index 972d13e8e7..ff68dff571 100644 --- a/templates/zerver/api/update-user.md +++ b/templates/zerver/api/update-user.md @@ -9,6 +9,8 @@ {generate_code_example(python)|/users/{user_id}:patch|example} +{generate_code_example(javascript)|/users/{user_id}:patch|example} + {tab|curl} {generate_code_example(curl)|/users/{user_id}:patch|example} diff --git a/templates/zerver/api/upload-custom-emoji.md b/templates/zerver/api/upload-custom-emoji.md index 1dcc1458f6..e7bf76c601 100644 --- a/templates/zerver/api/upload-custom-emoji.md +++ b/templates/zerver/api/upload-custom-emoji.md @@ -10,6 +10,8 @@ {generate_code_example(python)|/realm/emoji/{emoji_name}:post|example} +{generate_code_example(javascript)|/realm/emoji/{emoji_name}:post|example} + {tab|curl} {generate_code_example(curl)|/realm/emoji/{emoji_name}:post|example} diff --git a/templates/zerver/api/upload-file.md b/templates/zerver/api/upload-file.md index ea6ff977cd..b8babcac13 100644 --- a/templates/zerver/api/upload-file.md +++ b/templates/zerver/api/upload-file.md @@ -10,6 +10,8 @@ {generate_code_example(python)|/user_uploads:post|example} +{generate_code_example(javascript)|/user_uploads:post|example} + {tab|curl} {generate_code_example(curl)|/user_uploads:post|example} diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py index 9897c94eba..4e82e22e76 100644 --- a/zerver/openapi/markdown_extension.py +++ b/zerver/openapi/markdown_extension.py @@ -154,7 +154,8 @@ def render_javascript_code_example( pattern = fr'^add_example\(\s*"[^"]*",\s*{re.escape(json.dumps(function))},\s*\d+,\s*async \(client, console\) => \{{\n(.*?)^(?:\}}| *\}},\n)\);$' with open("zerver/openapi/javascript_examples.js") as f: m = re.search(pattern, f.read(), re.M | re.S) - assert m is not None + if m is None: + return [] function_source_lines = dedent(m.group(1)).splitlines() snippets = extract_code_example(function_source_lines, [], JS_EXAMPLE_REGEX) @@ -164,7 +165,11 @@ def render_javascript_code_example( else: config = JS_CLIENT_CONFIG.splitlines() - code_example = [] + code_example = [ + "{tab|js}\n", + "More examples and documentation can be found [here](https://github.com/zulip/zulip-js).", + ] + code_example.append("```js") code_example.extend(config) code_example.append("(async () => {") diff --git a/zerver/templatetags/app_filters.py b/zerver/templatetags/app_filters.py index 728437cfe3..736c09c059 100644 --- a/zerver/templatetags/app_filters.py +++ b/zerver/templatetags/app_filters.py @@ -128,7 +128,6 @@ def render_markdown_path( md_macro_extension = zerver.lib.markdown.include.makeExtension( base_path="templates/zerver/help/include/" ) - extensions = md_extensions if "api_url" in context: # We need to generate the API code examples extension each # time so the `api_url` config parameter can be set dynamically. @@ -136,11 +135,14 @@ def render_markdown_path( # TODO: Convert this to something more efficient involving # passing the API URL as a direct parameter. extensions = [ - *extensions, zerver.openapi.markdown_extension.makeExtension( api_url=context["api_url"], ), + *md_extensions, ] + else: + extensions = md_extensions + if not any(doc in markdown_file_path for doc in docs_without_macros): extensions = [md_macro_extension, *extensions]