"abc"
.upcase # =>
.chars # =>
.join("/") # =>
Last active
September 14, 2022 01:16
-
-
Save JoshCheek/d0e07b600d5a90e15cb5384a61791487 to your computer and use it in GitHub Desktop.
Evaluating and updating annotations in ruby code in markdown files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redcarpet' # gem | |
require 'open3' # stdlib | |
class SibRenderer < Redcarpet::Render::Safe | |
def block_code(code, language) | |
if language == "ruby" | |
code, _status = Open3.capture2("seeing_is_believing", "--xmpfilter-style", stdin_data: code) | |
end | |
super code, language # prob what you really want, see somefile.correctly_escaped.html | |
%(<pre><code class="#{language}">\n#{code}</code></pre>) # better for this example, see somefile.from_example.html | |
end | |
end | |
markdown = Redcarpet::Markdown.new(SibRenderer.new, fenced_code_blocks: true) | |
puts markdown.render File.read ARGV.first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Here is some ruby:</h1> | |
<pre><code>"abc" | |
.upcase # => "ABC" | |
.chars # => ["A", "B", "C"] | |
.join("/") # => "A/B/C" | |
</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Here is some ruby:</h1> | |
<pre><code class="ruby"> | |
"abc" | |
.upcase # => "ABC" | |
.chars # => ["A", "B", "C"] | |
.join("/") # => "A/B/C" | |
</code></pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment