class NishisukeBlogSyntax::Formatter::ShellFormatter
Constants
- INPUT_REGEXP
- OUTPUT_REGEXP
- PARSE_REGEXP
- SUBSTITUTE_REGEXP
Private Instance Methods
regexp()
click to toggle source
# File lib/nishisuke_blog_syntax/formatter/shell_formatter.rb, line 15 def regexp SUBSTITUTE_REGEXP end
substitute(matched)
click to toggle source
# File lib/nishisuke_blog_syntax/formatter/shell_formatter.rb, line 19 def substitute(matched) content_str = matched.match(PARSE_REGEXP)[1] contents = content_str.split("\n") contents.shift # drop first line, this is SRC```xxxxx <- contents.map! { |l| wrapped_line(l) } wrapped_content(contents.join('<br>')) end
wrapped_content(content)
click to toggle source
# File lib/nishisuke_blog_syntax/formatter/shell_formatter.rb, line 37 def wrapped_content(content) html = <<~HTML <div class="shell mdc-elevation--z2"> <pre class="shell__container"> <span class="shell__std"> #{content} </span> </pre> </div> HTML html.gsub("\n", '') end
wrapped_line(txt)
click to toggle source
# File lib/nishisuke_blog_syntax/formatter/shell_formatter.rb, line 27 def wrapped_line(txt) if m = txt.match(INPUT_REGEXP) %Q(<kbd class="shell__input">#{h(m.post_match)}</kbd>) elsif m = txt.match(OUTPUT_REGEXP) %Q(<samp class="shell__output">#{h(m.post_match)}</samp>) else '' # this means <br><br> finaly. end end