Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs]: Highlighting code snippets in .rst docs #11477

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/050-breaking-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ It is still possible to interface with contracts written for Solidity versions p
v0.5.0 (or the other way around) by defining interfaces for them.
Consider you have the following pre-0.5.0 contract already deployed:

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.4.25;
Expand All @@ -308,7 +308,7 @@ Consider you have the following pre-0.5.0 contract already deployed:

This will no longer compile with Solidity v0.5.0. However, you can define a compatible interface for it:

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
Expand All @@ -326,7 +326,7 @@ the function will work with ``staticcall``.

Given the interface defined above, you can now easily use the already deployed pre-0.5.0 contract:

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
Expand All @@ -347,7 +347,7 @@ Similarly, pre-0.5.0 libraries can be used by defining the functions of the libr
supplying the address of the pre-0.5.0 library during linking (see :ref:`commandline-compiler` for how to use the
commandline compiler for linking):

::
.. code-block:: solidity

// This will not compile after 0.6.0
// SPDX-License-Identifier: GPL-3.0
Expand All @@ -372,7 +372,7 @@ v0.5.0 with some of the changes listed in this section.

Old version:

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.4.25;
Expand Down Expand Up @@ -435,7 +435,7 @@ Old version:

New version:

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.5.0;
Expand Down
8 changes: 4 additions & 4 deletions docs/abi-spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Examples

Given the contract:

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
Expand Down Expand Up @@ -510,7 +510,7 @@ call.
As an example, let us consider the following contract whose ``transfer`` function always
reverts with a custom error of "insufficient balance":

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
Expand Down Expand Up @@ -599,7 +599,7 @@ Errors look as follows:

For example,

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
Expand Down Expand Up @@ -653,7 +653,7 @@ which is of array type and has the same structure as the top-level object except

As an example, the code

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >0.7.4 <0.9.0;
Expand Down
8 changes: 5 additions & 3 deletions docs/assembly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ load it into a ``bytes`` variable. This is not possible with "plain Solidity" an
idea is that reusable assembly libraries can enhance the Solidity language
without a compiler change.

.. code::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
Expand All @@ -65,7 +65,7 @@ without a compiler change.
Inline assembly is also beneficial in cases where the optimizer fails to produce
efficient code, for example:

.. code::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
Expand Down Expand Up @@ -217,7 +217,9 @@ starting from where this pointer points at and update it.
There is no guarantee that the memory has not been used before and thus
you cannot assume that its contents are zero bytes.
There is no built-in mechanism to release or free allocated memory.
Here is an assembly snippet you can use for allocating memory that follows the process outlined above::
Here is an assembly snippet you can use for allocating memory that follows the process outlined above

.. code-block:: yul

function allocate(length) -> pos {
pos := mload(0x40)
Expand Down
8 changes: 4 additions & 4 deletions docs/common-patterns.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract in order to become the "richest", inspired by
In the following contract, if you are no longer the richest,
you receive the funds of the person who is now the richest.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
Expand Down Expand Up @@ -63,7 +63,7 @@ you receive the funds of the person who is now the richest.

This is as opposed to the more intuitive sending pattern:

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
Expand Down Expand Up @@ -129,7 +129,7 @@ functions and this is what this section is about.
The use of **function modifiers** makes these
restrictions highly readable.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
Expand Down Expand Up @@ -292,7 +292,7 @@ function finishes.
Starting with version 0.4.0, modifier code
will run even if the function explicitly returns.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
Expand Down
16 changes: 12 additions & 4 deletions docs/contracts/abstract-contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Contracts may be marked as abstract even though all functions are implemented.

This can be done by using the ``abstract`` keyword as shown in the following example. Note that this contract needs to be
defined as abstract, because the function ``utterance()`` was defined, but no implementation was
provided (no implementation body ``{ }`` was given).::
provided (no implementation body ``{ }`` was given).

.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.9.0;
Expand All @@ -21,7 +23,9 @@ provided (no implementation body ``{ }`` was given).::
}

Such abstract contracts can not be instantiated directly. This is also true, if an abstract contract itself does implement
all defined functions. The usage of an abstract contract as a base class is shown in the following example::
all defined functions. The usage of an abstract contract as a base class is shown in the following example:

.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.9.0;
Expand All @@ -40,11 +44,15 @@ functions by overriding, it needs to be marked as abstract as well.
Note that a function without implementation is different from
a :ref:`Function Type <function_types>` even though their syntax looks very similar.

Example of function without implementation (a function declaration)::
Example of function without implementation (a function declaration):

.. code-block:: solidity

function foo(address) external returns (address);

Example of a declaration of a variable whose type is a function type::
Example of a declaration of a variable whose type is a function type:

.. code-block:: solidity

function(address) external returns (address) foo;

Expand Down
2 changes: 1 addition & 1 deletion docs/contracts/constant-state-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ can sometimes be cheaper than immutable values.
Not all types for constants and immutables are implemented at this time. The only supported types are
:ref:`strings <strings>` (only for constants) and :ref:`value types <value-types>`.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.4;
Expand Down
2 changes: 1 addition & 1 deletion docs/contracts/creating-contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If a contract wants to create another contract, the source code
(and the binary) of the created contract has to be known to the creator.
This means that cyclic creation dependencies are impossible.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;
Expand Down
4 changes: 2 additions & 2 deletions docs/contracts/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ which causes
all changes in the current call to be reverted and passes the error data back to the
caller.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
Expand Down Expand Up @@ -79,4 +79,4 @@ of the built-in type ``Panic(uint256)``.
of inner calls is propagated back through the chain of external calls
by default. This means that an inner call
can "forge" revert data that looks like it could have come from the
contract that called it.
contract that called it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there actually a difference here? If it was a newline github would show that but it does not so I wonder what's going on here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's weird I didn't catch out what's changed here. I think in this script I just highlighted Solidity.

2 changes: 1 addition & 1 deletion docs/contracts/function-modifiers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inheritable properties of contracts and may be overridden by derived contracts,
if they are marked ``virtual``. For details, please see
:ref:`Modifier Overriding <modifier-overriding>`.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >0.7.0 <0.9.0;
Expand Down
28 changes: 17 additions & 11 deletions docs/contracts/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Functions outside of a contract, also called "free functions", always have impli
:ref:`visibility<visibility-and-getters>`. Their code is included in all contracts
that call them, similar to internal library functions.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >0.7.0 <0.9.0;
Expand Down Expand Up @@ -56,7 +56,9 @@ Function parameters are declared the same way as variables, and the name of
unused parameters can be omitted.

For example, if you want your contract to accept one kind of external call
with two integers, you would use something like the following::
with two integers, you would use something like the following:

.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
Expand Down Expand Up @@ -89,7 +91,9 @@ Function return variables are declared with the same syntax after the
``returns`` keyword.

For example, suppose you want to return two results: the sum and the product of
two integers passed as function parameters, then you use something like::
two integers passed as function parameters, then you use something like:

.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
Expand All @@ -114,7 +118,9 @@ You can either explicitly assign to return variables and
then leave the function as above,
or you can provide return values
(either a single or :ref:`multiple ones<multi-return>`) directly with the ``return``
statement::
statement:

.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
Expand Down Expand Up @@ -178,7 +184,7 @@ The following statements are considered modifying the state:
#. Using low-level calls.
#. Using inline assembly that contains certain opcodes.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
Expand Down Expand Up @@ -224,7 +230,7 @@ In addition to the list of state modifying statements explained above, the follo
#. Calling any function not marked ``pure``.
#. Using inline assembly that contains certain opcodes.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
Expand Down Expand Up @@ -321,7 +327,7 @@ will consume more gas than the 2300 gas stipend:

Below you can see an example of a Sink contract that uses function ``receive``.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.9.0;
Expand Down Expand Up @@ -383,7 +389,7 @@ operations as long as there is enough gas passed on to it.
proper functions should be used instead.


::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.2 <0.9.0;
Expand Down Expand Up @@ -461,7 +467,7 @@ This process is called "overloading" and also applies to inherited functions.
The following example shows overloading of the function
``f`` in the scope of contract ``A``.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
Expand All @@ -480,7 +486,7 @@ The following example shows overloading of the function
Overloaded functions are also present in the external interface. It is an error if two
externally visible functions differ by their Solidity types but not by their external types.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
Expand Down Expand Up @@ -514,7 +520,7 @@ candidate, resolution fails.
.. note::
Return parameters are not taken into account for overload resolution.

::
.. code-block:: solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
Expand Down