lib/maruku/ext/div.rb in maruku-0.5.9 vs lib/maruku/ext/div.rb in maruku-0.6.0
- old
+ new
@@ -1,9 +1,22 @@
-OpenDiv = /^[ ]{0,3}\+\-\-+\s*([^\s-]*)\s*\-*\s*$/
-CloseDiv = /^[ ]{0,3}\=\-\-+\s*([^\s-]*)\s*\-*\s*$/
+#+-----------------------------------{.warning}------
+#| this is the last warning!
+#|
+#| please, go away!
+#|
+#| +------------------------------------- {.menace} --
+#| | or else terrible things will happen
+#| +--------------------------------------------------
+#+---------------------------------------------------
+
+OpenDiv = /^[ ]{0,3}\+\-\-+\s*(\{([^{}]*|".*"|'.*')*\})?\s*\-*\s*$/
+CloseDiv = /^[ ]{0,3}\=\-\-+\s*(\{([^{}]*|".*"|'.*')*\})?\s*\-*\s*$/
+# note these are not enough for parsing the above example:
+#OpenDiv = /^[ ]{0,3}\+\-\-+\s*(.*)$/
+#CloseDiv = /^[ ]{0,3}\=\-\-+\s*(.*)$/
StartPipe = /^[ ]{0,3}\|(.*)$/ # $1 is rest of line
DecorativeClosing = OpenDiv
MaRuKu::In::Markdown::register_block_extension(
:regexp => OpenDiv,
@@ -65,11 +78,11 @@
end
al_string = ial_at_beginning || ial_at_end
al = nil
- if al_string =~ /^\{(.*)\}$/
+ if al_string =~ /^\{(.*)\}\s*$/
inside = $1
cs = MaRuKu::In::Markdown::SpanLevelParser::CharSource
al = al_string &&
doc.read_attribute_list(cs.new(inside), its_context=nil, break_on=[nil])
end
@@ -82,12 +95,32 @@
})
module MaRuKu; class MDElement
- def md_div(children, a=nil)
- self.md_el(:div, children, meta={}, a)
+ def md_div(children, al=nil)
+ type = label = num = nil
+ doc.refid2ref ||= {}
+ if al
+ al.each do |k, v|
+ case k
+ when :class
+ type = $1 if v =~ /^num_(\w*)/
+ when :id
+ label = v
+ end
+ end
+ end
+ if type
+ doc.refid2ref[type] ||= {}
+ num = doc.refid2ref[type].length + 1 || 1
+ end
+ e = self.md_el(:div, children, meta={:label => label, :type => type, :num => num}, al)
+ if type && label
+ doc.refid2ref[type].update({label => e})
+ end
+ e
end
end end
@@ -95,6 +128,6 @@
def to_html_div
add_ws wrap_as_element('div')
end
-end end end
\ No newline at end of file
+end end end