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
----
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]
Use source%linenums
to show line numbers. [1]
[source%linenums,python]
----
include::../code_examples/flask_app.py[]
----
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
|
link:../code_examples/flask_app.py[role=include]
link:../code_examples/flask_app.py[role=include]
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[]
----