Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
user docs: Create separate "Code blocks" user documentation page.
Alya Abbott279f7b1c8d98
diff --git a/docs/production/install.md b/docs/production/install.mdindex f81dd8c0324..6e9e72e4d82 100644--- a/docs/production/install.md+++ b/docs/production/install.md@@ -176,4 +176,4 @@ block][code-block]).[chat-zulip-org]: ../contributing/chat-zulip-org.md[production-help]: https://chat.zulip.org/#narrow/stream/31-production-help-[code-block]: https://zulip.com/help/format-your-message-using-markdown#code+[code-block]: https://zulip.com/help/code-blocksdiff --git a/docs/production/upgrade-or-modify.md b/docs/production/upgrade-or-modify.mdindex d847ab62243..4dfdd888cc1 100644--- a/docs/production/upgrade-or-modify.md+++ b/docs/production/upgrade-or-modify.md@@ -188,7 +188,7 @@ help](https://chat.zulip.org/#narrow/stream/31-production-help) in theserver](../contributing/chat-zulip-org.md) for best-effort help.Please include the relevant error output from the above logs in a[Markdown code-block](https://zulip.com/help/format-your-message-using-markdown#code)+block](https://zulip.com/help/code-blocks)in any reports.### Rolling back to a prior versiondiff --git a/static/templates/settings/playground_settings_admin.hbs b/static/templates/settings/playground_settings_admin.hbsindex 0bc3491be2e..823296d89c0 100644--- a/static/templates/settings/playground_settings_admin.hbs+++ b/static/templates/settings/playground_settings_admin.hbs@@ -7,7 +7,7 @@code. Zulip code blocks that are <z-link-markdown-help>tagged with a programming language</z-link-markdown-help> will havea button visible on hover that allows you to open the code block in the code playground site.{{#*inline "z-link-repl"}}<a href="https://replit.com/" target="_blank" rel="noopener noreferrer">{{> @partial-block}}</a>{{/inline}}- {{#*inline "z-link-markdown-help"}}<a href="/help/format-your-message-using-markdown#code" target="_blank" rel="noopener noreferrer">{{> @partial-block}}</a>{{/inline}}+ {{#*inline "z-link-markdown-help"}}<a href="/help/code-blocks" target="_blank" rel="noopener noreferrer">{{> @partial-block}}</a>{{/inline}}{{/tr}}</p><p>@@ -27,7 +27,7 @@<div class="new-playground-form wrapper"><div class="settings-section-title">{{t "Add a new code playground" }}- {{> ../help_link_widget link="/help/add-a-custom-playground" }}+ {{> ../help_link_widget link="/help/code-blocks#code-playgrounds" }}</div><div class="alert" id="admin-playground-status"></div><div class="control-group">diff --git a/templates/zerver/features.html b/templates/zerver/features.htmlindex 40c28b8efda..f91f469803e 100644--- a/templates/zerver/features.html+++ b/templates/zerver/features.html@@ -70,7 +70,7 @@With a single click, one can easily copy code blockcontents to the clipboard or transfer the contentsto- an <a href="/help/add-a-custom-playground">external+ an <a href="/help/code-blocks#code-playgrounds">externalcode playground</a> that can run the code.</p></div>diff --git a/templates/zerver/for/open-source.md b/templates/zerver/for/open-source.mdindex cfc75622136..f895191f2f9 100644--- a/templates/zerver/for/open-source.md+++ b/templates/zerver/for/open-source.md@@ -128,17 +128,17 @@ Import your existing organization from [Slack](/help/import-from-slack),### Collaborate on code and formulas-[Markdown code blocks](/help/format-your-message-using-markdown#code)+[Markdown code blocks](/help/code-blocks)with syntax highlighting make it easy to discuss code, paste an errormessage, or explain a complicated point. Native LaTeX support providesthe same benefits when talking about math.You can also instantly copy a code block to your clipboard or transfer-it to an [external code playground](/help/add-a-custom-playground) to+it to an [external code playground](/help/code-blocks#code-playgrounds) tointeractively run and debug the code.If your community primarily uses a single programming language,-consider setting a default language for syntax highlighting.+consider setting a [default code block language](/help/code-blocks#default-code-block-language).### Permalink to conversations.diff --git a/templates/zerver/help/add-a-custom-playground.md b/templates/zerver/help/add-a-custom-playground.mddeleted file mode 100644index eb60e72ed77..00000000000--- a/templates/zerver/help/add-a-custom-playground.md+++ /dev/null@@ -1,72 +0,0 @@-# Add a custom playground--{!admin-only.md!}--Code playgrounds allow users to open the contents of a [code-block][code-block] in an external playground of your choice by-clicking a widget that appears when hovering over the code block.--Code playgrounds can be configured for any programming language (the-language of a code block is determined by the logic for syntax-highlighting). You can also use a custom language name to implement-simple integrations. For example, a playground for the language-`send_tweet` could be used with a "playground" that sends the content-of the code block as a Tweet.--[code-block]: /help/format-your-message-using-markdown#code--### Add a custom playground--{start_tabs}--{settings_tab|playground-settings}--1. Under **Add a new playground**, enter a **Name**, **Language** and-**URL prefix**.--1. Click **Add playground**.--{end_tabs}--## Walkthrough with an example--Consider the following example.--* Name: `Rust playground`-* Language: `Rust`-* URL prefix: `https://play.rust-lang.org/?edition=2018&code=`--When composing a message `rust` can be mentioned as the syntax highlighting-language in the code blocks.--~~~-``` rust-fn main() {- // A hello world Rust program for demo purposes- println!("Hello World!");-}-```-~~~--The user would then get a on-hover option to open the above code in the playground-they had previously configured.--## Technical details--* You can configure multiple playgrounds for a given language; if you do that,- the user will get to choose which playground to open the code in.-* The `Language` field is the human-readable Pygments language name for that- programming language. The syntax highlighting language in a code block- is internally mapped to these human-readable Pygments names.- E.g: `py3` and `py` are mapped to `Python`. We are working on implementing a- typeahead for looking up the Pygments name. Until then, one can use- [this Pygments method](https://pygments-doc.readthedocs.io/en/latest/lexers/lexers.html#pygments.lexers.get_lexer_by_name).-* The links for opening code playgrounds are always constructed by- concatenating the provided URL prefix with the URL-encoded contents- of the code block.-* Code playground sites do not always clearly document their URL- format; often you can just get the prefix from your browser's URL bar.--If you have any trouble setting in setting up a code playground, please [contact-us](/help/contact-support) with details on what you're trying to do, and we'll be-happy to help you out.diff --git a/templates/zerver/help/code-blocks.md b/templates/zerver/help/code-blocks.mdnew file mode 100644index 00000000000..354d806f148--- /dev/null+++ b/templates/zerver/help/code-blocks.md@@ -0,0 +1,139 @@+# Code blocks++Zulip supports the standard [Markdown syntax][markdown] for code+blocks:++~~~+Inline: `let x = 5`++Code block:+```+def f(x):+ return x+1+```++Syntax highlighting:+```python+def fib(n):+ # TODO: base case+ return fib(n-1) + fib(n-2)+```+~~~++Sending the above message in Zulip will render like this:++++You can also use `~~~` to start codeblocks, or just indent the code 4 or more+spaces.++A widget in the upper-right corner of code blocks allows you to easily+copy the code to your clipboard.++## Language tagging++Tagging a code block with a language enables syntax highlighting and+(if configured) [code playgrounds](#code-playgrounds). Zulip supports syntax highlighting+for hundreds of languages.++A code block can be tagged by typing the language name after the fence+(` ``` `) that begins a code block, as shown here. Typeahead will+help you enter the name for the language. The **Short names** values+from the [Pygments lexer documentation][pygments-lexers] are the+complete set of values that support syntax highlighting.++~~~+``` python+print("Hello world!")+```+~~~++### Default code block language++Organization administrators can also configure a default language for code+blocks, which will be used whenever the code block has no tag.++{!admin-only.md!}++{start_tabs}++{settings_tab|organization-settings}++1. Under **Other settings**, edit **Default language for code blocks**.++{end_tabs}+++When a default language is configured, one can use ````text` to display code+blocks without any syntax highlighting (E.g. to paste an error message).++## Code playgrounds++Code playgrounds are interactive in-browser development environments, such as+[replit](https://replit.com), that are designed to make it convenient to edit+and debug code. Code playgrounds can be configured for any programming language.+Zulip code blocks that are tagged with the language will have a button visible+on hover that allows you to open the code block in the code playground site.++### Add a custom code playground++{!admin-only.md!}++{start_tabs}++{settings_tab|playground-settings}++1. Under **Add a new code playground**, enter a **Name**, **Language** and **URL+prefix**.++1. Click **Add code playground**.++{end_tabs}++For example, to configure code playgrounds for languages like Python or+JavaScript, you could specify the Language and URL Prefix fields as:++* `Python` and `https://replit.com/languages/python3/?code=`+* `JavaScript` and `https://replit.com/languages/javascript/?code=`++When a code block is labeled as Python or JavaScript (either explicitly or by+organization default), users would get a on-hover option to open the code block+in the speficied code playground.++### Technical details++* You can configure multiple playgrounds for a given language; if you do that,+the user will get to choose which playground to open the code in.++* The `Language` field is the human-readable Pygments language name for that+programming language. The language tag for a code block is internally mapped+to these human-readable Pygments names. E.g: `py3` and `py` are mapped to+`Python`. We are working on implementing a typeahead for looking up the+Pygments name. Until then, one can use [this Pygments method][get_lexer_by_name].++* The links for opening code playgrounds are always constructed by concatenating+the provided URL prefix with the URL-encoded contents of the code block.++* Code playground sites do not always clearly document their URL format; often+you can just get the prefix from your browser's URL bar.++* You can also use a custom language name to implement simple integrations.+For example, a code block tagged with the "language" `send_tweet` could be+used with a "playground" that sends the content of the code block as a Tweet.++If you have any trouble setting in setting up a code playground, please [contact+us](/help/contact-support) with details on what you're trying to do, and we'll+be happy to help you out.++## Related articles++[Math blocks][math-block], [spoiler blocks][spoiler-block], and [quote+blocks][quote-block] use similar fenced block syntax.++[pygments-lexers]: https://pygments.org/docs/lexers/+[get_lexer_by_name]: https://pygments-doc.readthedocs.io/en/latest/lexers/lexers.html#pygments.lexers.get_lexer_by_name++[markdown]: /help/format-your-message-using-markdown+[math-block]: /help/format-your-message-using-markdown#latex+[quote-block]: /help/format-your-message-using-markdown#quotes+[spoiler-block]: /help/format-your-message-using-markdown#spoilersdiff --git a/templates/zerver/help/format-your-message-using-markdown.md b/templates/zerver/help/format-your-message-using-markdown.mdindex 23e0306539e..9cc8db89aac 100644--- a/templates/zerver/help/format-your-message-using-markdown.md+++ b/templates/zerver/help/format-your-message-using-markdown.md@@ -109,18 +109,9 @@ def fib(n):You can also use `~~~` to start codeblocks, or just indent the code 4 or more spaces.-Zulip supports syntax highlighting for hundreds of languages, and a-typeahead will pop up when you start typing after the ` ``` `. If you can't-find your language, search for it [here](https://pygments.org/docs/lexers/)-and try the **short names** listed for the lexers for your language.--Organization administrators can also configure a default syntax-highlighting language. In this configuration, one can use ````text`-to display content without any syntax highlighting.--Hovering over a Zulip code block reveals buttons to copy the code or-open it in one of the organization's configured [custom code-playgrounds](/help/add-a-custom-playground).+See the main [code blocks article](/help/code-blocks) for details on+[syntax highlighting](/help/code-blocks#language-tagging), [code+playgrounds](/help/code-blocks#code-playgrounds), and other features.## LaTeX~~~diff --git a/templates/zerver/help/include/sidebar_index.md b/templates/zerver/help/include/sidebar_index.mdindex b59b36b6b87..d09427df164 100644--- a/templates/zerver/help/include/sidebar_index.md+++ b/templates/zerver/help/include/sidebar_index.md@@ -37,6 +37,7 @@* [Mention a user or group](/help/mention-a-user-or-group)* [Edit or delete a message](/help/edit-or-delete-a-message)* [Message a stream by email](/help/message-a-stream-by-email)+* [Code blocks](/help/code-blocks)* [Add GIFs in your message](/help/animated-gifs-from-giphy)* [Create a poll](/help/create-a-poll)@@ -140,7 +141,6 @@* [Add custom emoji](/help/add-custom-emoji)* [Configure authentication methods](/help/configure-authentication-methods)* [Add a custom linkifier](/help/add-a-custom-linkifier)-* [Add a custom playground](/help/add-a-custom-playground)* [Message retention policy](/help/message-retention-policy)* [SAML authentication](/help/saml-authentication)diff --git a/zerver/lib/markdown/help_settings_links.py b/zerver/lib/markdown/help_settings_links.pyindex 2c0f748c8db..96bce11fce0 100644--- a/zerver/lib/markdown/help_settings_links.py+++ b/zerver/lib/markdown/help_settings_links.py@@ -64,7 +64,7 @@ link_mapping = {],"playground-settings": ["Manage organization",- "Playgrounds",+ "Code playgrounds","/#organization/playground-settings",],"profile-field-settings": [diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 3c1a5fbc769..80774792a8d 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -2629,7 +2629,7 @@ paths:additionalProperties: falsedescription: |Event sent to all users in a Zulip organization when the- set of configured [code playgrounds](/help/add-a-custom-playground)+ set of configured [code playgrounds](/help/code-blocks#code-playgrounds)for the organization has changed.**Changes**: New in Zulip 4.0 (feature level 49).@@ -6986,7 +6986,7 @@ paths:operationId: add_realm_playgroundtags: ["server_and_organizations"]description: |- Configure [code playgrounds](/help/add-a-custom-playground) for the organization.+ Configure [code playgrounds](/help/code-blocks#code-playgrounds) for the organization.`POST {{ api_url }}/v1/realm/playgrounds`@@ -7042,7 +7042,7 @@ paths:operationId: remove_realm_playgroundtags: ["server_and_organizations"]description: |- Remove a [code playground](/help/add-a-custom-playground) previously+ Remove a [code playground](/help/code-blocks#code-playgrounds) previouslyconfigured for an organization.`DELETE {{ api_url }}/v1/realm/playgrounds/{playground_id}`@@ -7450,7 +7450,7 @@ paths:Present if `realm_playgrounds` is present in `fetch_event_types`.An array of dictionaries where each dictionary describes a- [code playground](/help/add-a-custom-playground) configured for this Zulip organization.+ [code playground](/help/code-blocks#code-playgrounds) configured for this Zulip organization.**Changes**: New in Zulip 4.0 (feature level 49).realm_user_groups: