Code blocks
Copy Button
The Copy To Clipboard button will appear on all code blocks:
Copy me!
Do something else
Callout (1)
Callout (2)
Callout tab (3)
Comment # Just a regular comment after some code
1 | Callout |
2 | Callout |
3 | Callout after a tab |
[source,adoc]
Copy me!
Unless you add role=nocopy
:
[source,adoc,role=nocopy]
Don't copy me!
Reference lines (Callouts)
You can add number bubbles to reference specific lines by appending <n>
to a line. It is advised to put them behind a line comment for the language the code is in.
require 'sinatra' (1)
get '/hi' do (2) (3)
"Hello World!"
end
1 | Library import |
2 | URL mapping |
3 | Response block |
line of code (1)
line of code (2)
line of code (3)
line of code (4)
1 | A callout behind a line comment for C-style languages. |
2 | A callout behind a line comment for Ruby, Python, Perl, etc. |
3 | A callout behind a line comment for Clojure. |
4 | A callout behind a line comment for XML or SGML languages like HTML. |
Highlight lines
Highlight one or more lines of code by adding e.g. //mark-line
at the end of each of them. Use the line comment syntax for the language the block contains.
[source, java]
---
var result = driver.executableQuery("MATCH (p:Person {name: $name})")
.withParameters(Map.of("name", "Alice")) //mark-line
.withConfig(QueryConfig.builder().withDatabase("neo4j").build())
.execute();
---
var result = driver.executableQuery("MATCH (p:Person {name: $name})")
.withParameters(Map.of("name", "Alice")) .withConfig(QueryConfig.builder().withDatabase("neo4j").build())
.execute();
Expand code block
Code blocks longer than 15 lines (+5 of tolerance) are collapsed, unless you add role=nocollapse
[source,js]
...
[source,js,role=nocollapse]
...
// Collapse/Expand long blocks
var codeBlockMaxHeight = 300 // px
var styleMaskImage = 'linear-gradient(to bottom, black 0px, transparent ' + (codeBlockMaxHeight+100) + 'px)'
var expandCollapseBlock = function (e) {
e.preventDefault();
var showMore = e.target
var pre = showMore.parentNode
var codeBlock = pre.querySelector('code')
if (pre.st.style.webkitMaskImage = styleMaskImage
codeBlock.style.maskImage = styleMaskImage
showMore.innerHTML = '↓' // show more
//codeBlock.scrollIntoView({behavior: 'smooth'})
}
}
if (pre.st.style.webkitMaskImage = styleMaskImage
codeBlock.style.maskImage = styleMaskImage
showMore.innerHTML = '↓' // show more
//codeBlock.scrollIntoView({behavior: 'smooth'})
}
}