Skip to content

Instantly share code, notes, and snippets.

@reasonset
Created March 30, 2016 05:05
Show Gist options
  • Save reasonset/ef850f8e8c3971d5cb3f2bb366700e9d to your computer and use it in GitHub Desktop.
Save reasonset/ef850f8e8c3971d5cb3f2bb366700e9d to your computer and use it in GitHub Desktop.
diff --git a/rubylib/pbmarkdown.rb b/rubylib/pbmarkdown.rb
index 95b843f..97acdfc 100644
--- a/rubylib/pbmarkdown.rb
+++ b/rubylib/pbmarkdown.rb
@@ -16,7 +16,15 @@ class Kramdown::Parser::Kramdown
# Is Header?
when :header
- ::DOC.stock_header(arg[-1][:level], arg[-1][:raw_text])
+ @used_ids ||= {}
+ if @used_ids.has_key?(arg[-1][:raw_text])
+ ::DOC.stock_header(arg[-1][:level], arg[-1][:raw_text],
+ sprintf("%s-%d", arg[-1][:raw_text], (@used_ids[arg[-1][:raw_text]] + 1)
+ )
+ )
+ else
+ ::DOC.stock_header(arg[-1][:level], arg[-1][:raw_text], arg[-1][:raw_text])
+ end
end
end
@@ -25,6 +33,22 @@ class Kramdown::Parser::Kramdown
end
end
+class Kramdown::Converter::Html
+ # Override of kramdown/base.rb
+ def generate_id(str)
+ gen_id = str.dup
+ @used_ids ||= {}
+ if @used_ids.has_key?(gen_id)
+ gen_id += '-' << (@used_ids[gen_id] += 1).to_s
+ else
+ @used_ids[gen_id] = 0
+ end
+ gen_id
+ end
+
+end
+
+
## Markdown Parser
class PureBuilder::Parser::MD < PureBuilder::Parser
@@ -25,6 +33,22 @@ class Kramdown::Parser::Kramdown
end
end
+class Kramdown::Converter::Html
+ # Override of kramdown/base.rb
+ def generate_id(str)
+ gen_id = str.dup
+ @used_ids ||= {}
+ if @used_ids.has_key?(gen_id)
+ gen_id += '-' << (@used_ids[gen_id] += 1).to_s
+ else
+ @used_ids[gen_id] = 0
+ end
+ gen_id
+ end
+
+end
+
+
## Markdown Parser
class PureBuilder::Parser::MD < PureBuilder::Parser
@@ -82,4 +106,4 @@ class PureBuilder::Parser::MD < PureBuilder::Parser
end
-end
\ No newline at end of file
+end
diff --git a/rubylib/purebuilder.rb b/rubylib/purebuilder.rb
index 6354ff1..f4cc55a 100644
--- a/rubylib/purebuilder.rb
+++ b/rubylib/purebuilder.rb
@@ -172,6 +172,7 @@ class PureBuilder
case i[:extension].downcase
when "pdoc"
pser = Parser::PureDoc.new(@config[:puredoc_class].new, pbconf, @file_content, @filename)
+
pser.parse
when "md"
@@ -343,6 +344,7 @@ class PureBuilder
rescue
STDERR.puts "!!ERROR in PureDoc TUNE:" + $!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment