@@ -3,6 +3,16 @@ import type { Parent } from "unist";
33import { custom_vfile } from "./types" ;
44import visit from "unist-util-visit" ;
55
6+ /**
7+ * The svelte docs have a special two-column display for code examples. This
8+ * allows arbitrary content to appear alongside a highlighted code example.
9+ *
10+ * This formatting starts at `***` (a `hr`) and ends with the next fenced code block. All
11+ * of this content is wrappeed in `<div class="side-by-side" />`. then there
12+ * are two nested divs `<div class="copy" />` which contains the arbirtary
13+ * content *up to* the code block and `<div class="code" />` which contains
14+ * the code block itself.
15+ */
616export function split_view ( ) : Transformer {
717 return function ( tree , vFile : custom_vfile ) {
818 if ( vFile . data . docs_type !== "docs" ) return ;
@@ -23,16 +33,20 @@ export function split_view(): Transformer {
2333 children : [ ] ,
2434 } ;
2535
36+ // starting from the current node, we iterate the children of the parent
37+ // when we find the next code block (which is a `raw` node at this point)
38+ // we stop, as we have all of the content
2639 for ( let index = i + 1 ; index < parent . children . length ; index ++ ) {
2740 const _node = parent . children [ index ] ;
2841
2942 if ( ! _node ) break ;
3043
44+ // data.code_block is set as meta data when highlight code blocks in another transform
3145 if ( _node . data && _node . data . code_block ) {
3246 const parts = parent . children . splice ( i + 1 , index - i ) ;
33- parts . pop ( ) ;
47+
3448 left . children = parts ;
35- right . children . push ( _node ) ;
49+ right . children . push ( parts . pop ( ) ) ;
3650 break ;
3751 }
3852 }
0 commit comments