Skip to content

Latest commit

 

History

History
174 lines (138 loc) · 3.2 KB

code.adoc

File metadata and controls

174 lines (138 loc) · 3.2 KB

Showing Code

background

Code blocks

You can use ---- and .... to limit code blocks

[source]
----
pi = 3
----

Syntax highlight

We can use highlight.js library to make our code shine.

Choose in the main slide deck all the languages you want to use
:source-highlighter: highlightjs
:highlightjs-languages: asciidoc,python,yaml,Dockerfile,dockerfile,Bash
And specify the language in the block
[source, python]
----
pi = 3
----

Syntax highlight Result

pi = 3.1415
name = "m"

Do not duplicate code

Get your code directly from files!
[source,python]
----
include::../code_examples/flask_app.py[]
----
Or just some lines
[source,python]
----
include::../code_examples/flask_app.py[lines=1]
include::../code_examples/flask_app.py[lines=6..10]
----

!

link:../code_examples/flask_app.py[role=include]
link:../code_examples/flask_app.py[role=include]
link:../code_examples/flask_app.py[role=include]

Line numbers

Use source%linenums to show line numbers. [1]

[source%linenums,python]
----
include::../code_examples/flask_app.py[]
----

Line numbers

link:../code_examples/flask_app.py[role=include]

Highlight lines of code

Use highlight= to draw the atention to the lines you are explaining.

, acts as and, .. is to indicate a line range and | indicates different steps.

[source,python,highlight="1,6|7..10"]
----
include::../code_examples/flask_app.py[]
----
Warning
Don’t use source%linenums with this since in some cases causes conflicts

Highlight lines of code

link:../code_examples/flask_app.py[role=include]

Incrementally reveal code

Incrementally reveal code

link:../code_examples/flask_app.py[role=include]

Incrementally reveal code

link:../code_examples/flask_app.py[role=include]

link:../code_examples/flask_app.py[role=include]

Incrementally reveal code

link:../code_examples/flask_app.py[role=include]

How to do it?

Use a combination of [%auto-animate] and data-id=xyz in different slides

[%auto-animate]
=== Incrementally reveal code
[source,python,highlight="1,3",data-id=flask-app]
----
include::../code_examples/flask_app.py[lines=1,6]
----

[%auto-animate]
=== Incrementally reveal code
[source,python,highlight="4..7",data-id=flask-app]
----
include::../code_examples/flask_app.py[lines=1]

include::../code_examples/flask_app.py[lines=6..10]
----

[%auto-animate]
=== Incrementally reveal code
[source,python,highlight="2..4",data-id=flask-app]
----
include::../code_examples/flask_app.py[]
----

1. |test|