Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
Empty backticks
Remove remaining REXML dependence
Misc fixes from trunk
  • Loading branch information
distler committed Dec 17, 2013
1 parent 5b949af commit 9f84c6d
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 53 deletions.
11 changes: 5 additions & 6 deletions lib/maruku/input/parse_span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,19 +449,18 @@ def read_inline_code(src, con)
# We will read until this string
end_string = "`" * num_ticks

# Try to handle empty single-ticks
if num_ticks > 1 && !src.next_matches(/.*#{Regexp.escape(end_string)}/)
con.push_element(end_string) and return
end

code = read_simple(src, nil, nil, end_string)

# We didn't find a closing batch!
if !code || src.cur_char != '`'
con.push_element(end_string + (code || '')) and return
end

# We didn't find a closing batch!
if !code || src.cur_char != '`'
con.push_element(end_string + (code || ''))
return
end

# puts "Now I expects #{num_ticks} ticks: #{src.cur_chars(10).inspect}"
src.ignore_chars num_ticks

Expand Down
27 changes: 20 additions & 7 deletions lib/maruku/input/rubypants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,17 @@ class ReplaceRule < Rule
# Replace all matches in the input at once with the
# same elements from "replacement".
def apply(first, input, output)
intersperse(first.split(pattern), replacement).each do |x|
append_to_output(output, x)
split = first.split(pattern)
if split.empty?
first.scan(pattern).size.times do
clone_elems(replacement).each do |x|
append_to_output(output, x)
end
end
else
intersperse(first.split(pattern), replacement).each do |x|
append_to_output(output, x)
end
end
end

Expand All @@ -174,17 +183,21 @@ def apply(first, input, output)
# Sort of like "join" - places the elements in "elem"
# between each adjacent element in the array.
def intersperse(ary, elem)
return ary if ary.length <= 1
return clone_elems(elem) if ary.empty?
return ary if ary.length == 1
h, *t = ary
t.inject([h]) do |r, e|
entities = elem.map do |el|
r.concat clone_elems(elem)
r << e
end
end

def clone_elems(elems)
elems.map do |el|
en = el.clone
en.doc = doc
en
end
r.concat entities
r << e
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions lib/maruku/maruku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ def initialize(s = nil, meta = {})
self.attributes.merge! meta
parse_doc(s) if s
end

def to_s
warn "Maruku#to_s is deprecated and will be removed or changed in a near-future version of Maruku."
super
end
end
14 changes: 7 additions & 7 deletions lib/maruku/output/entity_table.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rexml/document'
require 'nokogiri'
require 'singleton'

module MaRuKu::Out
Expand All @@ -12,12 +12,12 @@ def initialize
@entity_table = {}

xml = File.new(File.join(File.dirname(__FILE__), '..', '..', '..', 'data', 'entities.xml'))
doc = REXML::Document.new(xml)
doc.elements.each("//char") do |c|
num = c.attributes['num'].to_i
name = c.attributes['name']
convert = c.attributes['convertTo']
package = c.attributes['package']
doc = Nokogiri::XML::Document.parse(xml)
doc.xpath("//char").each do |c|
num = c['num'].to_i
name = c['name']
convert = c['convertTo']
package = c['package']

e = Entity.new(num, name, convert, package)
@entity_table[name] = e
Expand Down
15 changes: 5 additions & 10 deletions lib/maruku/output/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,8 @@ def wrap_as_element(name, attributes_to_copy=[])

def create_html_element(name, attributes_to_copy=[])
m = xelem(name)
Array(HTML4Attributes[name]).each do |att|
if v = @attributes[att]
m[att.to_s] = v.to_s
end
@attributes.each do |att,val|
m[att.to_s] = val if HTML4Attributes[name].include?(att)
end
m
end
Expand Down Expand Up @@ -579,22 +577,19 @@ def to_html_code_using_pre(source, code_lang=nil)
source = source.gsub(/\t/,'&#187;' + '&#160;' * 3).gsub(/ /,'&#172;')
end

text = xtext(source)
code << xtext(source)

code_lang ||= self.attributes[:lang]
if code_lang
code['class'] = code_lang
pre['class'] = code_lang
pre['class'] = code['class'] = code_lang
end

code << text
pre << code
end

def to_html_inline_code
pre = create_html_element('code')
source = self.raw_code
pre << xtext(source)
pre << xtext(self.raw_code)

color = get_setting(:code_background_color)
if color != MaRuKu::Globals[:code_background_color]
Expand Down
1 change: 0 additions & 1 deletion lib/maruku/output/to_s.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class MDElement

# Strips all formatting from the string
def to_s
warn "Maruku#to_s is deprecated and will be removed or changed in a near-future version of Maruku."
children_to_s
end

Expand Down
36 changes: 18 additions & 18 deletions spec/block_docs/abbrev.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions spec/block_docs/issue40.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ JRuby Nokogiri doesn't put the CDATA in.
<script>var x = true && true;</script>
*** Output of inspect ***
md_el(:document, [
md_html("<script>\n var x = true && true;\n</script>"),
md_html("<script>var x = true && true;</script>")])
md_html("<script><![CDATA[\n var x = true && true;\n]]></script>"),
md_html("<script><![CDATA[var x = true && true;]]></script>")])
*** Output of to_html ***
<script><![CDATA[
var x = true && true;
Expand Down
5 changes: 3 additions & 2 deletions spec/span_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require File.dirname(__FILE__) + '/spec_helper'
require 'rspec'
require 'maruku'

Expand All @@ -22,7 +23,7 @@

# Code blocks
["`" , :raise, 'Unclosed single ticks'],
["``" , :raise, 'Unclosed double ticks'],
["``" , [md_entity("ldquo")], 'Empty code block'],
["`a`" , [md_code('a')], 'Simple inline code'],
["`` ` ``" , [md_code('`')], ],
["`` \\` ``" , [md_code('\\`')], ],
Expand Down Expand Up @@ -71,7 +72,7 @@
["a _ b_", :raise, 'Unclosed emphasis'],
["_b_", [md_em('b')], 'Emphasis 7'],
["_b_ _c_", [md_em('b'),' ',md_em('c')], 'Emphasis 8'],
["_b__c_", [md_em('b'),md_em('c')], 'Emphasis 9', true],
["_b__c_", [md_em('b'),md_em('c')], 'Emphasis 9', true], # PENDING
# underscores in word
["mod_ruby", ['mod_ruby'], 'Word with underscore'],
# strong
Expand Down

0 comments on commit 9f84c6d

Please sign in to comment.