-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from tidewise/use_prepend_to_inject
modify how plantuml injects itself in the kramdown process
- Loading branch information
Showing
2 changed files
with
34 additions
and
32 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module Kramdown | ||
module PlantUml | ||
# Plugs into Kramdown::Converter::Html to provide conversion of PlantUML markup | ||
# into beautiful SVG. | ||
module ConverterExtension | ||
def convert_codeblock(element, indent) | ||
return super(element, indent) unless plantuml? element | ||
|
||
convert_plantuml(element.value) | ||
end | ||
|
||
private | ||
|
||
def plantuml?(element) | ||
element.attr['class'] == 'language-plantuml' | ||
end | ||
|
||
def convert_plantuml(plantuml) | ||
puml_opts = PlantUml::Options.new(@options) | ||
diagram = PlantUml::PlantUmlDiagram.new(plantuml, puml_opts) | ||
diagram.svg.to_s | ||
rescue StandardError => e | ||
raise e if puml_opts.nil? || puml_opts.raise_errors? | ||
|
||
logger = PlantUml::LogWrapper.init | ||
logger.error "Error while converting diagram: #{e.inspect}" | ||
end | ||
end | ||
end | ||
end |
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