Create new
Bindings
Transitions
Animations
Easing
Component composition
Context API
Special elements
Module context
Debugging
Miscellaneous
App.svelte
runes
This component is not in runes mode.
To enable runes mode, either start using runes in your code, or add the following to the top of your component:
<svelte:options runes />
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
⌄
<script>
// Import markdown conversion library
import { marked } from 'marked'
// Declare a variable to store the markdown data
let markdown = ""
</script>
<h1>Markdown Editor</h1>
<!-- Declare a textarea where the user can enter markdown, and bind it to the variable `markdown` -->
<textarea bind:value={markdown} placeholder="Enter markdown here"/>
<!-- Convert the markdown to HTML and display it -->
<div class="preview">{@html marked(markdown)}</div>
<!-- Make it look (slightly) nicer ;) -->
<style>
textarea, .preview {
box-sizing: border-box;
display: block;
width: 100%;
}
textarea {
font-family: monospace, Roboto;
height: 25%;
border: none;
margin: 0;
padding: 1rem;
}
.preview {
height: 75%;
padding: 2rem;
border-top: solid 2px #888;
bundling https://unpkg.com/marked@15.0.7/lib/marked.esm.js
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
›
⌄
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';
// Import markdown conversion library
import { marked } from 'marked';
var root = $.template(`<h1 class="svelte-7t82hi">Markdown Editor</h1> <textarea placeholder="Enter markdown here" class="svelte-7t82hi"></textarea> <div class="preview svelte-7t82hi"><!></div>`, 1);
export default function App($$anchor, $$props) {
$.push($$props, false);
// Declare a variable to store the markdown data
let markdown = $.mutable_state("");
$.init();
var fragment = root();
var textarea = $.sibling($.first_child(fragment), 2);
$.remove_textarea_child(textarea);
var div = $.sibling(textarea, 2);
var node = $.child(div);
$.html(node, () => marked($.get(markdown)), false, false);
$.reset(div);
$.bind_value(textarea, () => $.get(markdown), ($$value) => $.set(markdown, $$value));
$.append($$anchor, fragment);
$.pop();
}
result = svelte.compile(source, {
generate: ,
});99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
›
textarea.svelte-7t82hi, .preview.svelte-7t82hi {
box-sizing: border-box;
display: block;
width: 100%;
}
textarea.svelte-7t82hi {
font-family: monospace, Roboto;
height: 25%;
border: none;
margin: 0;
padding: 1rem;
}
.preview.svelte-7t82hi {
height: 75%;
padding: 2rem;
border-top: solid 2px #888;
}
h1.svelte-7t82hi {
background: #e1e1e1;
margin: 0px;
padding: 0.8rem;
font-size: 1.2rem;
}
body {
padding: 0;
}
Root {
css: StyleSheet {...}
- type: "StyleSheet"
- start: 511
- end: 927
- attributes: []
children: [...] (5)
Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 520
- end: 538
children: [...] (2)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 520
- end: 528
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "textarea"
- start: 520
- end: 528
}
]- start: 520
- end: 528
}
]
} ComplexSelector {...}
- type: "ComplexSelector"
- start: 530
- end: 538
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
ClassSelector {...}
- type: "ClassSelector"
- name: "preview"
- start: 530
- end: 538
}
]- start: 530
- end: 538
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 539
- end: 602
children: [...] (3)
Declaration {...}
- type: "Declaration"
- start: 543
- end: 565
- property: "box-sizing"
- value: "border-box"
} Declaration {...}
- type: "Declaration"
- start: 569
- end: 583
- property: "display"
- value: "block"
} Declaration {...}
- type: "Declaration"
- start: 587
- end: 598
- property: "width"
- value: "100%"
}
]
}- start: 520
- end: 602
} Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 606
- end: 614
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 606
- end: 614
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "textarea"
- start: 606
- end: 614
}
]- start: 606
- end: 614
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 615
- end: 714
children: [...] (5)
Declaration {...}
- type: "Declaration"
- start: 619
- end: 649
- property: "font-family"
- value: "monospace, Roboto"
} Declaration {...}
- type: "Declaration"
- start: 653
- end: 664
- property: "height"
- value: "25%"
} Declaration {...}
- type: "Declaration"
- start: 668
- end: 680
- property: "border"
- value: "none"
} Declaration {...}
- type: "Declaration"
- start: 684
- end: 693
- property: "margin"
- value: "0"
} Declaration {...}
- type: "Declaration"
- start: 697
- end: 710
- property: "padding"
- value: "1rem"
}
]
}- start: 606
- end: 714
} Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 718
- end: 726
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 718
- end: 726
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
ClassSelector {...}
- type: "ClassSelector"
- name: "preview"
- start: 718
- end: 726
}
]- start: 718
- end: 726
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 727
- end: 793
children: [...] (3)
Declaration {...}
- type: "Declaration"
- start: 731
- end: 742
- property: "height"
- value: "75%"
} Declaration {...}
- type: "Declaration"
- start: 746
- end: 759
- property: "padding"
- value: "2rem"
} Declaration {...}
- type: "Declaration"
- start: 763
- end: 789
- property: "border-top"
- value: "solid 2px #888"
}
]
}- start: 718
- end: 793
} Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 797
- end: 799
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 797
- end: 799
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "h1"
- start: 797
- end: 799
}
]- start: 797
- end: 799
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 800
- end: 882
children: [...] (4)
Declaration {...}
- type: "Declaration"
- start: 804
- end: 823
- property: "background"
- value: "#e1e1e1"
} Declaration {...}
- type: "Declaration"
- start: 827
- end: 838
- property: "margin"
- value: "0px"
} Declaration {...}
- type: "Declaration"
- start: 842
- end: 857
- property: "padding"
- value: "0.8rem"
} Declaration {...}
- type: "Declaration"
- start: 861
- end: 878
- property: "font-size"
- value: "1.2rem"
}
]
}- start: 797
- end: 882
} Rule {...}
- type: "Rule"
prelude: SelectorList {...}
- type: "SelectorList"
- start: 886
- end: 899
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 886
- end: 899
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
PseudoClassSelector {...}
- type: "PseudoClassSelector"
- name: "global"
args: SelectorList {...}
- type: "SelectorList"
- start: 894
- end: 898
children: [...] (1)
ComplexSelector {...}
- type: "ComplexSelector"
- start: 894
- end: 898
children: [...] (1)
RelativeSelector {...}
- type: "RelativeSelector"
- combinator: null
selectors: [...] (1)
TypeSelector {...}
- type: "TypeSelector"
- name: "body"
- start: 894
- end: 898
}
]- start: 894
- end: 898
}
]
}
]
}- start: 886
- end: 899
}
]- start: 886
- end: 899
}
]
}
]
}block: Block {...}
- type: "Block"
- start: 900
- end: 918
children: [...] (1)
Declaration {...}
- type: "Declaration"
- start: 904
- end: 914
- property: "padding"
- value: "0"
}
]
}- start: 886
- end: 918
}
]content: {...}
- start: 518
- end: 919
- styles: "\n\ttextarea, .preview {\n\t\tbox-sizing: border-box;\n\t\tdisplay: block;\n\t\twidth: 100%;\n\t}\n\t\n\ttextarea {\n\t\tfont-family: monospace, Roboto;\n\t\theight: 25%;\n\t\tborder: none;\n\t\tmargin: 0;\n\t\tpadding: 1rem;\n\t}\n\t\n\t.preview {\n\t\theight: 75%;\n\t\tpadding: 2rem;\n\t\tborder-top: solid 2px #888;\n\t}\n\t\n\th1 {\n\t\tbackground: #e1e1e1;\n\t\tmargin: 0px;\n\t\tpadding: 0.8rem;\n\t\tfont-size: 1.2rem;\n\t}\n\t\n\t:global(body) {\n\t\tpadding: 0;\n\t}\n"
comment: Comment {...}
- type: "Comment"
- start: 469
- end: 510
- data: " Make it look (slightly) nicer ;) "
}
}
}- js: []
- start: 166
- end: 510
- type: "Root"
fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (13)
Text {...}
- type: "Text"
- start: 164
- end: 166
- raw: "\n\n"
- data: "\n\n"
} RegularElement {...}
- type: "RegularElement"
- start: 166
- end: 190
- name: "h1"
attributes: [...] (1)
Attribute {...}
- type: "Attribute"
- start: -1
- end: -1
- name: "class"
value: [...] (1)
Text {...}
- type: "Text"
- data: ""
- raw: ""
- start: -1
- end: -1
}
]
}
]fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (1)
Text {...}
- type: "Text"
- start: 170
- end: 185
- raw: "Markdown Editor"
- data: "Markdown Editor"
}
]
}
} Text {...}
- type: "Text"
- start: 190
- end: 192
- raw: " "
- data: " "
} Comment {...}
- type: "Comment"
- start: 192
- end: 293
- data: " Declare a textarea where the user can enter markdown, and bind it to the variable `markdown` "
} Text {...}
- type: "Text"
- start: 293
- end: 294
- raw: ""
- data: ""
} RegularElement {...}
- type: "RegularElement"
- start: 294
- end: 361
- name: "textarea"
attributes: [...] (3)
BindDirective {...}
- start: 304
- end: 325
- type: "BindDirective"
- name: "value"
expression: Identifier {...}
- type: "Identifier"
- start: 316
- end: 324
loc: {...}
start: {...}
- line: 12
- column: 22
}end: {...}
- line: 12
- column: 30
}
}- name: "markdown"
}- modifiers: []
} Attribute {...}
- type: "Attribute"
- start: 326
- end: 359
- name: "placeholder"
value: [...] (1)
Text {...}
- start: 339
- end: 358
- type: "Text"
- raw: "Enter markdown here"
- data: "Enter markdown here"
}
]
} Attribute {...}
- type: "Attribute"
- start: -1
- end: -1
- name: "class"
value: [...] (1)
Text {...}
- type: "Text"
- data: ""
- raw: ""
- start: -1
- end: -1
}
]
}
]fragment: Fragment {...}
- type: "Fragment"
- nodes: []
}
} Text {...}
- type: "Text"
- start: 361
- end: 363
- raw: " "
- data: " "
} Comment {...}
- type: "Comment"
- start: 363
- end: 415
- data: " Convert the markdown to HTML and display it "
} Text {...}
- type: "Text"
- start: 415
- end: 416
- raw: ""
- data: ""
} RegularElement {...}
- type: "RegularElement"
- start: 416
- end: 467
- name: "div"
attributes: [...] (1)
Attribute {...}
- type: "Attribute"
- start: 421
- end: 436
- name: "class"
value: [...] (1)
Text {...}
- start: 428
- end: 435
- type: "Text"
- raw: "preview"
- data: "preview"
}
]
}
]fragment: Fragment {...}
- type: "Fragment"
nodes: [...] (1)
HtmlTag {...}
- type: "HtmlTag"
- start: 437
- end: 461
expression: CallExpression {...}
- type: "CallExpression"
- start: 444
- end: 460
loc: {...}
start: {...}
- line: 15
- column: 28
}end: {...}
- line: 15
- column: 44
}
}callee: Identifier {...}
- type: "Identifier"
- start: 444
- end: 450
loc: {...}
start: {...}
- line: 15
- column: 28
}end: {...}
- line: 15
- column: 34
}
}- name: "marked"
}arguments: [...] (1)
Identifier {...}
- type: "Identifier"
- start: 451
- end: 459
loc: {...}
start: {...}
- line: 15
- column: 35
}end: {...}
- line: 15
- column: 43
}
}- name: "markdown"
}
]- optional: false
}
}
]
}
} Text {...}
- type: "Text"
- start: 467
- end: 469
- raw: "\n\n"
- data: "\n\n"
} Comment {...}
- type: "Comment"
- start: 469
- end: 510
- data: " Make it look (slightly) nicer ;) "
} Text {...}
- type: "Text"
- start: 510
- end: 511
- raw: "\n"
- data: "\n"
}
]
}- options: null
instance: Script {...}
- type: "Script"
- start: 0
- end: 164
- context: "default"
content: Program {...}
- type: "Program"
- start: 8
- end: 155
loc: {...}
start: {...}
- line: 1
- column: 0
}end: {...}
- line: 7
- column: 0
}
}body: [...] (2)
ImportDeclaration {...}
- type: "ImportDeclaration"
- start: 50
- end: 81
loc: {...}
start: {...}
- line: 3
- column: 2
}end: {...}
- line: 3
- column: 33
}
}specifiers: [...] (1)
ImportSpecifier {...}
- type: "ImportSpecifier"
- start: 59
- end: 65
loc: {...}
start: {...}
- line: 3
- column: 11
}end: {...}
- line: 3
- column: 17
}
}imported: Identifier {...}
- type: "Identifier"
- start: 59
- end: 65
loc: {...}
start: {...}
- line: 3
- column: 11
}end: {...}
- line: 3
- column: 17
}
}- name: "marked"
}local: Identifier {...}
- type: "Identifier"
- start: 59
- end: 65
loc: {...}
start: {...}
- line: 3
- column: 11
}end: {...}
- line: 3
- column: 17
}
}- name: "marked"
}
}
]source: Literal {...}
- type: "Literal"
- start: 73
- end: 81
loc: {...}
start: {...}
- line: 3
- column: 25
}end: {...}
- line: 3
- column: 33
}
}- value: "marked"
- raw: "'marked'"
}
} VariableDeclaration {...}
- type: "VariableDeclaration"
- start: 137
- end: 154
loc: {...}
start: {...}
- line: 6
- column: 2
}end: {...}
- line: 6
- column: 19
}
}declarations: [...] (1)
VariableDeclarator {...}
- type: "VariableDeclarator"
- start: 141
- end: 154
loc: {...}
start: {...}
- line: 6
- column: 6
}end: {...}
- line: 6
- column: 19
}
}id: Identifier {...}
- type: "Identifier"
- start: 141
- end: 149
loc: {...}
start: {...}
- line: 6
- column: 6
}end: {...}
- line: 6
- column: 14
}
}- name: "markdown"
}init: Literal {...}
- type: "Literal"
- start: 152
- end: 154
loc: {...}
start: {...}
- line: 6
- column: 17
}end: {...}
- line: 6
- column: 19
}
}- value: ""
- raw: "\"\""
}
}
]- kind: "let"
leadingComments: [...] (1)
Line {...}
- type: "Line"
- value: " Declare a variable to store the markdown data"
- start: 86
- end: 134
}
]
}
]- sourceType: "module"
}- attributes: []
}
}
The AST is not public API and may change at any point in time