4
4
5
5
use std:: io:: prelude:: * ;
6
6
use std:: path:: Path ;
7
- use std:: sync:: atomic:: { AtomicBool , Ordering :: Relaxed } ;
7
+
8
+ mod plugins;
8
9
9
10
/// Describes the ways in which this library can fail.
10
11
#[ derive( thiserror:: Error , Debug ) ]
@@ -211,83 +212,6 @@ pub fn load_book(summary_src: &str) -> Result<Vec<IndexEntry>, Error> {
211
212
Ok ( index_entries)
212
213
}
213
214
214
- /// Adds `<section>` around <h1> and <h2> slides.
215
- struct SlideAdapter {
216
- first : AtomicBool ,
217
- no_heading_slide : AtomicBool ,
218
- in_speaker_notes : AtomicBool ,
219
- }
220
-
221
- impl SlideAdapter {
222
- fn new ( ) -> SlideAdapter {
223
- SlideAdapter {
224
- first : AtomicBool :: new ( true ) ,
225
- no_heading_slide : AtomicBool :: new ( false ) ,
226
- in_speaker_notes : AtomicBool :: new ( false ) ,
227
- }
228
- }
229
- }
230
-
231
- impl comrak:: adapters:: HeadingAdapter for SlideAdapter {
232
- fn enter (
233
- & self ,
234
- output : & mut dyn Write ,
235
- heading : & comrak:: adapters:: HeadingMeta ,
236
- _sourcepos : Option < comrak:: nodes:: Sourcepos > ,
237
- ) -> std:: io:: Result < ( ) > {
238
- if heading. level == 3 && heading. content == "Notes" {
239
- // the start of speaker notes.
240
- writeln ! ( output, r#"<aside class="notes">"# ) ?;
241
- self . in_speaker_notes . store ( true , Relaxed ) ;
242
- } else if heading. level <= 2 {
243
- // We break slides on # and ##
244
- if !self . first . load ( Relaxed ) {
245
- // we have a previous slide open. Close it
246
-
247
- // but first close any speaker notes
248
- if self . in_speaker_notes . load ( Relaxed ) {
249
- self . in_speaker_notes . store ( false , Relaxed ) ;
250
- writeln ! ( output, "</aside>" ) ?;
251
- }
252
- // now close the slide
253
- writeln ! ( output, "</section>" ) ?;
254
- } else {
255
- self . first . store ( false , Relaxed ) ;
256
- }
257
- // open a new slide
258
- writeln ! ( output, "<section>" ) ?;
259
- }
260
-
261
- if heading. content == "NO_HEADING" {
262
- // this is a slide with no heading - comment out the fake heading
263
- self . no_heading_slide . store ( true , Relaxed ) ;
264
- writeln ! ( output, "<!-- " ) ?;
265
- } else {
266
- // write out the heading
267
- self . no_heading_slide . store ( false , Relaxed ) ;
268
- writeln ! ( output, "<h{}>" , heading. level) ?;
269
- }
270
-
271
- Ok ( ( ) )
272
- }
273
-
274
- fn exit (
275
- & self ,
276
- output : & mut dyn Write ,
277
- heading : & comrak:: adapters:: HeadingMeta ,
278
- ) -> std:: io:: Result < ( ) > {
279
- if self . no_heading_slide . load ( Relaxed ) {
280
- // stop hiding the fake heading
281
- writeln ! ( output, " -->" ) ?;
282
- self . no_heading_slide . store ( false , Relaxed ) ;
283
- } else {
284
- // close the heading
285
- writeln ! ( output, "</h{}>" , heading. level) ?;
286
- }
287
- Ok ( ( ) )
288
- }
289
- }
290
-
291
215
/// Processes a markdown file into an HTML document, using the given template.
292
216
///
293
217
/// The template should contain the string `$TITLE`, which is the title of the
@@ -312,7 +236,7 @@ pub fn generate_deck(
312
236
let md_content = std:: fs:: read_to_string ( in_path) ?;
313
237
314
238
let md_content = md_content. replace ( "---" , "## NO_HEADING" ) ;
315
- let slide_adapter = SlideAdapter :: new ( ) ;
239
+ let slide_adapter = plugins :: SlideAdapter :: new ( ) ;
316
240
let options = comrak:: Options :: default ( ) ;
317
241
let mut plugins = comrak:: Plugins :: default ( ) ;
318
242
plugins. render . heading_adapter = Some ( & slide_adapter) ;
0 commit comments