M shard.lock => shard.lock +1 -1
@@ 2,7 2,7 @@ version: 2.0
shards:
map_parallel:
git: https://git.sr.ht/~michalr/map_parallel
- version: 0.0.1+git.commit.b8db351b7066ed039d7a1a906fa814595dedf46c
+ version: 0.0.1+git.commit.a7c0be201c6695fa24b5e4f5fdffa3c707a54eb1
markd:
git: https://github.com/icyleaf/markd.git
M spec/gmi_renderer_spec.cr => spec/gmi_renderer_spec.cr +11 -1
@@ 3,7 3,8 @@ require "spec"
require "../src/gmi_renderer.cr"
def render_to_gmi(input : String)
- GmiRenderer.new.render(Markd::Parser.parse(input))
+ rendered, warnings = GmiRenderer.new.render(Markd::Parser.parse(input))
+ return rendered
end
describe "GmiRenderer" do
@@ 232,5 233,14 @@ there"
actual.should eq(expected)
end
+
+ it "a" do
+ input = "hello <a href=\"http://fl9.eu/\">oh hi<a/> there"
+ expected = "hello <a href=\"http://fl9.eu/\">oh hi<a/> there"
+
+ actual = render_to_gmi(input)
+
+ actual.should eq(expected)
+ end
end
end
M src/gmi_renderer.cr => src/gmi_renderer.cr +13 -1
@@ 14,6 14,7 @@ class GmiRenderer < Markd::Renderer
@last_output = "\n"
@is_newline = false
@is_blockquote = false
+ @warnings = Array(String).new
end
def heading(node, entering)
@@ 65,6 66,17 @@ class GmiRenderer < Markd::Renderer
when .includes?("<br")
@output_io << "\n"
@is_newline = true
+ when .includes?("<a"), .includes?("</a")
+ @output_io << node.text
+ @warnings << "#{node.source_pos[0][0]}:#{node.source_pos[0][1]}: Inline <a> encountered. Ignoring."
+ when .includes?("<img"), .includes?("</img")
+ @output_io << node.text
+ @warnings << "#{node.source_pos[0][0]}:#{node.source_pos[0][1]}: Inline <img> encountered. Ignoring."
+ when "<strong>", "</strong>"
+ self.strong(node, entering)
+ when "<code>", "</code>"
+ @output_io << "```\n"
+ @is_newline = true
else
raise "Not implemented support of inline html for #{node.text}"
end
@@ 179,6 191,6 @@ class GmiRenderer < Markd::Renderer
end
end
@output_io << insert_links()
- @output_io.to_s.strip
+ {@output_io.to_s.strip, @warnings}
end
end
M src/main.cr => src/main.cr +9 -8
@@ 1,17 1,18 @@
require "markd"
require "./gmi_renderer"
+require "./extract_jekyll_front_matter"
require "map_parallel"
Dir.new(".").entries
- .select! { |x| /\.md$/ =~ x }
+ .select! { |x| /\.(md|markdown)$/ =~ x }
.map_parallel do |fname|
- {fname, GmiRenderer.new.render(
- Markd::Parser.parse(
- File.read(fname)
- )
- )}
+ entry = File.read(fname)
+ extract = extract_jekyll_front_matter(entry)
+ gmi_document, warnings = GmiRenderer.new.render(Markd::Parser.parse(extract[:doc]))
+ warnings.each { |w| puts "#{fname}:#{w}" }
+ {fname, extract[:front_matter], gmi_document}
end
- .each do |fname, rendered|
- puts "======= #{fname} =======\n"
+ .each do |fname, front_matter, rendered|
+ puts "======= #{fname} : #{front_matter["title"]?} =======\n"
puts "#{rendered}\n"
end