Code Block¶
code_block is a block element node that represents source code across one or more lines.
Usage and Children¶
- Its
childrenarecode_lineblock elements. Each code line contains text nodes representing one line of code, rather than paragraph or inline link elements. - Pasted content is converted into code-line text.
code_block -> code_line -> text leaf
Data Structure¶
Required Properties¶
language(required, string): language identifier, such asjavascript, rather than the display labelJavascript. Common values includeplaintext,bash,css,c,cpp,csharp,go,html,javascript,java,json,php,python,ruby,sql,swift,typescript,xml, andyaml.
Optional Properties¶
style(optional, object): code display settings.style.white_space(optional, string):nowrapdisables visual line wrapping;normalenables it. Visual wrapping does not create additionalcode_linenodes. When the style object is absent, the editor usesnowrap.
Editor-Created Defaults¶
languagemay be an empty string orplaintextwhen no programming language is set. The historical valuetextalso represents plain text.style.white_spaceisnowrapfor a newly-created block.
language is the native .sdoc field.
Example¶
{
"id": "code-block-id",
"type": "code_block",
"language": "javascript",
"style": {
"white_space": "nowrap"
},
"children": [
{
"id": "code-line-one-id",
"type": "code_line",
"children": [
{
"id": "code-text-one-id",
"text": "const value = 1;"
}
]
},
{
"id": "code-line-two-id",
"type": "code_line",
"children": [
{
"id": "code-text-two-id",
"text": "console.log(value);"
}
]
}
]
}