2015-10-03 23:47:01 +00:00
|
|
|
caption: codeblock
|
|
|
|
created: 20151103160200000
|
2016-08-18 08:07:06 +00:00
|
|
|
modified: 20160817175325205
|
2015-10-03 23:47:01 +00:00
|
|
|
tags: Widgets
|
|
|
|
title: CodeBlockWidget
|
|
|
|
type: text/vnd.tiddlywiki
|
|
|
|
|
|
|
|
! Introduction
|
|
|
|
|
|
|
|
The ''codeblock'' widget renders text in `<pre>` and `<code>` blocks, causing it to be
|
|
|
|
displayed monospace. A language may optionally be specified using the
|
|
|
|
''language'' attribute, however syntax highlighting will only be used if the
|
|
|
|
[[Highlight Plugin]] is installed.
|
|
|
|
|
|
|
|
! Content and Attributes
|
|
|
|
|
|
|
|
The content of the `<$codeblock>` widget is ignored.
|
|
|
|
|
2016-08-18 08:07:06 +00:00
|
|
|
|!Attribute |!Description |
|
|
|
|
|code |Contents of the block to render as code |
|
|
|
|
|language |Programming language for syntax highlighting |
|
|
|
|
|
|
|
|
The `language` attribute accepts either:
|
|
|
|
|
|
|
|
* a Highlight.js language code (see https://highlightjs.org/static/demo/ for a list)
|
|
|
|
* a MIME type (eg, `text/html` or `image/svg+xml`)
|
2015-10-03 23:47:01 +00:00
|
|
|
|
|
|
|
! Examples
|
|
|
|
|
|
|
|
Here is an example embedding the contents of a tiddler as a code block.
|
|
|
|
|
2015-10-04 20:05:46 +00:00
|
|
|
<$macrocall $name='wikitext-example-without-html'
|
|
|
|
src='<$codeblock code={{$:/editions/tw5.com/macro-examples/say-hi}} />' />
|
2015-10-03 23:47:01 +00:00
|
|
|
|
|
|
|
A codeblock may also specify a language.
|
|
|
|
|
2015-10-04 20:05:46 +00:00
|
|
|
<$macrocall $name='wikitext-example-without-html'
|
|
|
|
src='<$codeblock code="SELECT * FROM users WHERE deleted = false" language="sql" />' />
|
2015-10-03 23:47:01 +00:00
|
|
|
|