File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed
Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,9 @@ pub fn post_process_html<T: PageLike>(
124124 let class = el. get_attribute( "class" ) ;
125125 let class = class. as_deref( ) . unwrap_or_default( ) ;
126126 let is_hidden = class. split_ascii_whitespace( ) . any( |c| c == "hidden" ) ;
127+ let is_interactive_example = class
128+ . split_ascii_whitespace( )
129+ . any( |c| c. starts_with( "interactive-example" ) ) ;
127130 let name = class
128131 . split_ascii_whitespace( )
129132 . skip_while( |s| * s != "brush:" )
@@ -134,7 +137,7 @@ pub fn post_process_html<T: PageLike>(
134137 el. prepend( "<code>" , ContentType :: Html ) ;
135138 el. append( "</code>" , ContentType :: Html ) ;
136139 }
137- if is_hidden {
140+ if is_hidden || is_interactive_example {
138141 el. before( r#"<div class="code-example">"# , ContentType :: Html ) ;
139142 el. after( "</div>" , ContentType :: Html ) ;
140143 } else if !name. is_empty( ) && name != "plain" {
Original file line number Diff line number Diff line change 1+ use html_escape:: encode_double_quoted_attribute;
2+ use rari_templ_func:: rari_f;
3+ use rari_utils:: concat_strs;
4+
5+ use crate :: error:: DocError ;
6+ use crate :: helpers:: l10n:: l10n_json_data;
7+ use crate :: templ:: api:: RariApi ;
8+
9+ /// Adds an <interactive-example> element to the content
10+ ///
11+ /// Parameters:
12+ /// $0 - Name of interactive example
13+ /// $1 - Optional custom height class to set on interactive-example element
14+ ///
15+ /// Example call {{InteractiveExample("JavaScript Demo: Array.from()", "taller")}}
16+ #[ rari_f]
17+ pub fn interactive_example ( name : String , height : Option < String > ) -> Result < String , DocError > {
18+ let title = l10n_json_data ( "Template" , "interactive_example_cta" , env. locale ) ?;
19+ let id = RariApi :: anchorize ( title) ;
20+
21+ let height = height
22+ . map ( |height| {
23+ concat_strs ! (
24+ r#" height="# ,
25+ & encode_double_quoted_attribute( & height) . as_ref( ) ,
26+ r#"""#
27+ )
28+ } )
29+ . unwrap_or_default ( ) ;
30+ Ok ( concat_strs ! (
31+ r#"<h2 id=""# ,
32+ & id,
33+ r#"">"# ,
34+ title,
35+ "</h2>\n " ,
36+ r#"<interactive-example name=""# ,
37+ encode_double_quoted_attribute( & name) . as_ref( ) ,
38+ r#"""# ,
39+ & height,
40+ r#"></interactive-example>"#
41+ ) )
42+ }
Original file line number Diff line number Diff line change @@ -2,5 +2,6 @@ pub mod embed_gh_live_sample;
22pub mod embed_interactive_example;
33pub mod embed_live_sample;
44pub mod embed_youtube;
5+ pub mod interactive_example;
56pub mod jsfiddle_embed;
67pub mod live_sample_link;
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ pub fn invoke(
103103 "embedinteractiveexample" => {
104104 embeds:: embed_interactive_example:: embed_interactive_example_any
105105 }
106+ "interactiveexample" => embeds:: interactive_example:: interactive_example_any,
106107 "embedghlivesample" => embeds:: embed_gh_live_sample:: embed_gh_live_sample_any,
107108 "embedlivesample" => embeds:: embed_live_sample:: embed_live_sample_any,
108109 "embedyoutube" => embeds:: embed_youtube:: embed_youtube_any,
You can’t perform that action at this time.
0 commit comments