« lib/Rapi/Blog/Template/Dispatcher/ScaffoldFile.pm
↑ Summary
lib/Rapi/Blog/Template/Postprocessor/TextMarkdown.pm »
| 1 | package Rapi::Blog::Template::Postprocessor::MarkdownElement; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use RapidApp::Util qw(:all); | ||
| 6 | use String::Random; | ||
| 7 | |||
| 8 | # This post-processor should only be used when the content is being rendered within | ||
| 9 | # an html document which has loaded the marked.js based markdown_elements.js script | ||
| 10 | |||
| 11 | sub process { | ||
| 12 | shift if ($_[0] eq __PACKAGE__); | ||
| 13 | my ($output_ref, $context) = @_; | ||
| 14 | |||
| 15 | # instead of doing this here, we're now doing it in the AccessStore. But leaving this | ||
| 16 | # commented-out for future reference. | ||
| 17 | ## If we're being processed (i.e. included within) from another Markdown template, | ||
| 18 | ## return the output as-is, since we only want to process at the top-level | ||
| 19 | #return $$output_ref if ($context->next_template_post_processor||'' eq __PACKAGE__); | ||
| 20 | |||
| 21 | my $markedId = 'markdown-el-'. String::Random->new->randregex('[a-z0-9]{6}'); | ||
| 22 | |||
| 23 | return join("\n", | ||
| 24 | '<xmp style="display:none;" id="'.$markedId.'">', | ||
| 25 | $$output_ref, | ||
| 26 | '</xmp>', | ||
| 27 | # New: now self-contained, accessing our own copy of marked.js/markdown_elements.js | ||
| 28 | '<script src="_ra-rel-mnt_/assets/local/misc/static/js/marked-el.js"></script>', | ||
| 29 | '<script>', | ||
| 30 | ' processMarkdownElementById("'.$markedId.'")', | ||
| 31 | '</script>' | ||
| 32 | ); | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 36 | 1; |