Implements Code shape which renders the highlighted code at specified point.
Kind: global class
Extends: Shape
Since: 1.0.0
- Code ⇐
Shape- new Code(cursor, [options])
- .getCode() ⇒
String - .setCode([code]) ⇒
Shape - .getWidth() ⇒
Number - .getHeight() ⇒
Number - .render() ⇒
Text - .toObject() ⇒
Object
Create Code shape.
| Param | Type | Description |
|---|---|---|
| cursor | Cursor |
Cursor instance |
| [options] | Object |
Options object |
| [options.code] | String |
Code fragment that you want to show |
Example
Code.create(cursor, {
code: 'console.log('Your code here');'
});Get current code from shape.
Kind: instance method of Code
Set new code to this shape.
Kind: instance method of Code
| Param | Type | Default |
|---|---|---|
| [code] | String |
'' |
Returns actual width of the shape. Since code shape hasn't specified width, we need to override default. It looks for the longest line in your shape and returns its length.
Kind: instance method of Code
Returns actual height of the shape. Since code shape hasn't specified height, we need to override default. It returns count of lines in our shape.
Kind: instance method of Code
Render the shape based on options.
Kind: instance method of Code
Overrides default toObject() method because we have new fields here.
Kind: instance method of Code