Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Convert hint box markdown in DocuBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Simran-B committed Jan 10, 2020
1 parent 6bd829b commit d849093
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion _plugins/DocuBlockTag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ def get_docu_block(path, blockname)
@@paths[path][blockname]
end

def convertHintBox(context, content)
site = context.registers[:site]
converter = site.find_converter_instance(::Jekyll::Converters::Markdown)

# Remove indention based on first actual line (but only spaces)
content = content.sub(/^[\r\n]+/, '')
indent = content.index(/[^ ]/) || 0
content = content.lines.map{ |line| line.slice([indent, line.index(/[^ ]/) || 0].min, line.length) }.join ''
# Parse Markdown and strip trailing whitespace (especially line breaks).
# Otherwise below <div>s will be wrapped in <p> for some reason!
content = converter.convert(content).sub(/\s+$/, '')
content
end

def render(context)
if context["page"]["dir"] =~ /\d\.\d\/?$/
dir = context["page"]["dir"] + "/"
Expand Down Expand Up @@ -299,7 +313,7 @@ def render(context)
"<div class=\"alert alert-#{$1}\" style=\"display: flex\">
<i class=\"fa fa-info-circle\" style=\"margin-right: 10px; margin-top: 4px;\"></i>
<div>
#{$2}
#{convertHintBox(context, $2)}
</div>
</div>"}
content
Expand Down

0 comments on commit d849093

Please sign in to comment.