Skip to content
Giorgio Garofalo edited this page Oct 10, 2024 · 9 revisions

A block of code can be created by either a 4-spaces or 1-tab indentation or a delimitation of 3 backticks or tildes, as the standard Markdown specification allows.

However, Quarkdown also provides a more powerful .code block function, so what's the difference?

.code vs. standard code block

Content processing

  • Standard code blocks don't allow any processing of their content, which is rendered as-is;
  • .code's body parameter accepts any Quarkdown string, making it possible to evaluate functions before displaying their output as code.
    This can be extremely useful when using .code in combination with .read to load a code snippet from file:
    .code
      .read {Point.java}
    

Language specification

  • Standard fenced code blocks define their language right after the starter delimiter (e.g. ```markdown);
  • .code elements define their language through the optional lang argument (e.g. .code {markdown} or .code lang:{markdown})

Line numbers

  • Standard code blocks always show line numbers by default;
  • .code allows toggling line numbers via the optional linenumbers Boolean argument, which defaults to true.

Focused lines

.code allows focusing a Range of lines (beginning from 1):

.code {java} focus:{8..10}
   public final class Wrapper<T> {
       private final T value;

       public Wrapper(T value) {
          this.value = value;
       }

       public final T getValue() {
           return this.value;
       }
   }
Focused code
Clone this wiki locally