Skip to main content

Codewars' Markdown Extensions

Codewars adds a few Markdown extensions for writing kata descriptions.

Sequential Code Blocks

Used to display code blocks only in the language selected by the user.

Details

  • Each code block must have an info string set to a valid language ID. To find the language ID, visit its documentation from the languages page.
  • The order of the code blocks/languages doesn't matter.
  • To avoid rendering errors/problems:
    • Always put an empty line before and after the complete group of code blocks
    • Never put empty lines between individual code blocks of the same sequential group.

Example

```javascript
const add = (a, b) => a + b;
```

```typescript
const add = (a: number, b: number) => a + b;
```

```ruby
def add(a, b)
  a + b
end
```
```javascript
const add = (a, b) => a + b;
```

```typescript
const add = (a: number, b: number) => a + b;
```

```ruby
def add(a, b)
  a + b
end
```

If the active language of the user is TypeScript, the above Markdown is rendered to the following:

const add = (a: number, b: number) => a + b;
const add = (a: number, b: number) => a + b;

Conditional Rendering

Conditional rendering blocks renders the content when the language selected by the user matches the condition specified in the info string.

Basic syntax

```if:java
For java, use `Preloaded.check(input)`.
```
```if:java
For java, use `Preloaded.check(input)`.
```

If the selected language is java, this block is showing up in the description, rendered to:

For java, use Preloaded.check(input).

Details

  • The language name in the info string has to match a valid language ID. To find the language ID, visit its documentation from the languages page.
  • To obtain proper rendering, language-specific blocks need an empty line before and after them, just like code blocks.
  • You can use Markdown inside conditional blocks, but be careful when inserting code blocks.
  • You can use different kinds of conditions or assigned them to groups of languages using the following syntaxes:
    • if:language
    • if:language,language2
    • if-not:language
    • if-not:language1,language2

Examples

if:languages

```if:javascript,typescript
Shown _if_ the active language is JavaScript **or** TypeScript.
```

```if:ruby
Shown _if_ the active language is Ruby.
```
```if:javascript,typescript
Shown _if_ the active language is JavaScript **or** TypeScript.
```

```if:ruby
Shown _if_ the active language is Ruby.
```

If the active language is Ruby, the above renders:

Shown if the active language is Ruby.

if-not:languages

```if-not:javascript,typescript
Hidden _if_ the active language is JavaScript **or** TypeScript.
```

```if-not:ruby
Hidden _if_ the active language is Ruby.
```
```if-not:javascript,typescript
Hidden _if_ the active language is JavaScript **or** TypeScript.
```

```if-not:ruby
Hidden _if_ the active language is Ruby.
```

If the active language is Ruby, the above renders:

Hidden if the active language is JavaScript or TypeScript.

Using Code Blocks Inside Conditional Blocks

To use code blocks within these conditional blocks, use tildes (~) to declare the conditional block or increase the number of backticks used.

~~~if:javascript
Used tilde to open conditional block.
```javascript
// Regular code block
```
~~~
~~~if:javascript
Used tilde to open conditional block.
```javascript
// Regular code block
```
~~~
````if:javascript
Used 4 backticks
```javascript
// Regular code block
```
````
````if:javascript
Used 4 backticks
```javascript
// Regular code block
```
````

Math Typesetting

Math typesetting is supported with the following two syntaxes:

See the support table on KaTeX to find all of the supported syntaxes.

Commonly used Symbols/Functions

Symbol/FunctionRepresents
x_nindice
x^nexponant
\ltlower than
\leqlower or equal
\lgtgreater than
\geqgreater or equal
\sumsigma (sum)
\prodpi (big)
\pipi (small)
\toarrow
\limlimit
\inftyinfinite
{ ... }to group instructions

Example

Suppose `$ x_n \leq l \leq y_n $` and `$ \lim_{n\to\infty} (x_n - y_n) = 0 $`,
prove that `$ \lim_{n\to\infty} x_n = \lim_{n\to\infty} y_n = l $`.

```math
x_n \leq l \leq y_n
```

```math
\lim_{n\to\infty} (x_n - y_n) = 0
```

```math
\lim_{n\to\infty} x_n = \lim_{n\to\infty} y_n = l
```
Suppose `$ x_n \leq l \leq y_n $` and `$ \lim_{n\to\infty} (x_n - y_n) = 0 $`,
prove that `$ \lim_{n\to\infty} x_n = \lim_{n\to\infty} y_n = l $`.

```math
x_n \leq l \leq y_n
```

```math
\lim_{n\to\infty} (x_n - y_n) = 0
```

```math
\lim_{n\to\infty} x_n = \lim_{n\to\infty} y_n = l
```

Renders:

Math Typeset Example Math Typeset Example