Class: JayAddCrossReference
- Inherits:
-
HTML::Pipeline::TextFilter
- Object
- HTML::Pipeline::TextFilter
- JayAddCrossReference
- Defined in:
- lib/jay_flavored_markdown/markdown_converter.rb
Overview
Org-mode like label and ref converter
+ (1)
+ (A) item title <<title>>
...
item [[title]] is...
is converted to:
+ (1)
+ (A) item title
...
item (1-A) is...
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 721 def call @labels = {} lines = @text.split("\n") # Scan "<<name>>" and make hash {"name" => "C"} lines = MarkdownEnumerator.new(lines).filter do |header, count| header.gsub(/<<([^<>]+)>>/) do |_| store_label($1, count.full_mark) "" end end # replace "[[name]]" to "(C)" @text = lines.map do |line| line.gsub(/\[\[([^\[\]]+)\]\]/) do |match| "(#{lookup_label($1) || '???'})" end end.join("\n") end |