Skip to content

Commit

Permalink
Fix regressions inherited from Maruku trunk
Browse files Browse the repository at this point in the history
The last commit was a real mess.
  • Loading branch information
distler committed Apr 15, 2013
1 parent 97e3854 commit d5c13bb
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 66 deletions.
4 changes: 3 additions & 1 deletion lib/maruku/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def read_attribute_list(src, con=nil, break_on_chars=nil)
break if break_on_chars.include? src.cur_char

case src.cur_char
when ':'
src.ignore_char
when nil
break # we're done here.
when '=' # error
Expand Down Expand Up @@ -69,7 +71,7 @@ def read_attribute_list(src, con=nil, break_on_chars=nil)
next
end

if src.cur_char != '='
if src.cur_char != '=' && key.length > 0
al << [:ref, key]
next
end
Expand Down
6 changes: 4 additions & 2 deletions lib/maruku/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ def md_html(raw_html, al=nil)
e = md_el(:raw_html, [], :raw_html => raw_html)
e.extend HTMLElement
begin
d = Nokogiri::HTML::Document.new
# Some might prefer an HTML::Document here. Alas, we need to preserve case
# on element names, so that's not suitable.
d = Nokogiri::XML::Document.new

# Make sure the SVG namespace is known
root = Nokogiri::XML::Element.new('html', d)
root.add_namespace('svg', "http://www.w3.org/2000/svg" )

# Set this as an attribute so it doesn't get included
# in metadata comparisons
e.parsed_html = Nokogiri::HTML::DocumentFragment.new(d, raw_html, d)
e.parsed_html = Nokogiri::XML::DocumentFragment.new(d, raw_html, d)
rescue => ex
maruku_recover "Nokogiri cannot parse this block of HTML/XML:\n" +
raw_html.gsub(/^/, '|').rstrip + "\n" + ex.inspect
Expand Down
22 changes: 12 additions & 10 deletions lib/maruku/input/parse_block.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'set'

module MaRuKu; module In; module Markdown; module BlockLevelParser

include Helpers
Expand Down Expand Up @@ -236,7 +238,8 @@ def read_xml_instruction(src, output)
end
end

HTML_INLINE_ELEMS = %w(a abbr acronym b big bdo br button cite code del dfn em i img input ins kbd label option q rb rbc rp rt rtc ruby samp select small span strong sub sup textarea tt var)
HTML_INLINE_ELEMS = Set.new %w[a abbr acronym b big bdo br button canvas cite code del dfn em i img input ins
kbd label option q rb rbc rp rt rtc ruby samp select small span strong sub sup textarea tt var]
def read_raw_html(src)
extra_line = nil
h = HTMLHelper.new
Expand Down Expand Up @@ -306,9 +309,9 @@ def read_list_item(src)

indentation, ial = spaces_before_first_char(first)
al = read_attribute_list(CharSource.new(ial, src)) if ial

ial_offset = ial ? ial.length + 3 : 0
lines, want_my_paragraph =
read_indented_content(src, indentation, :ial, item_type)
read_indented_content(src, indentation, [], item_type, ial_offset)

# add first line
# Strip first '*', '-', '+' from first line
Expand All @@ -318,9 +321,7 @@ def read_list_item(src)
src2 = LineSource.new(lines, src, parent_offset)
children = parse_blocks(src2)

with_par = want_my_paragraph

md_li(children, with_par, al)
md_li(children, want_my_paragraph, al)
end

def read_abbreviation(src)
Expand Down Expand Up @@ -374,16 +375,17 @@ def read_footnote_text(src)

# This is the only ugly function in the code base.
# It is used to read list items, descriptions, footnote text
def read_indented_content(src, indentation, break_list, item_type)
def read_indented_content(src, indentation, break_list, item_type, ial_offset=0)
lines = []
# collect all indented lines
saw_empty = false
saw_anything_after = false
break_list = Array(break_list)
len = indentation - ial_offset

while src.cur_line
num_leading_spaces = src.cur_line.number_of_leading_spaces
break if num_leading_spaces < indentation && ![:text, :empty].include?(src.cur_line.md_type)
break if num_leading_spaces < len && ![:text, :empty].include?(src.cur_line.md_type)

line = strip_indent(src.cur_line, indentation)
md_type = line.md_type
Expand All @@ -396,7 +398,7 @@ def read_indented_content(src, indentation, break_list, item_type)
end

# Unquestioningly grab anything that's deeper-indented
if md_type != :code && num_leading_spaces > indentation
if md_type != :code && num_leading_spaces > len
lines << line
src.shift_line
next
Expand All @@ -405,7 +407,7 @@ def read_indented_content(src, indentation, break_list, item_type)
# after a white line
if saw_empty
# we expect things to be properly aligned
break if num_leading_spaces < indentation
break if num_leading_spaces < len
saw_anything_after = true
else
break if break_list.include?(md_type)
Expand Down
2 changes: 1 addition & 1 deletion lib/maruku/input/parse_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def substitute_markdown_inside_raw_html
block_tags = ['div']

# find span elements or elements with 'markdown' attribute
doc.css((["[markdown]"] + HTML_INLINE_ELEMS).join(",")).each do |e|
doc.css((["[markdown]"] + HTML_INLINE_ELEMS.to_a).join(",")).each do |e|
# should we parse block-level or span-level?

how = e['markdown']
Expand Down
5 changes: 4 additions & 1 deletion lib/maruku/toc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ class MDElement
# Generate an id for headers. Assumes @children is set.
def generate_id
raise "generate_id only makes sense for headers" unless node_type == :header
children_to_s.tr(' ', '_').downcase.gsub(/\W/, '').strip
#The generated id must be unique; not just because non-unique id's are invalid,
#but because the are functionally-broken (don't work as link targets).
@doc.id_counter += 1
children_to_s.tr(' ', '_').downcase.gsub(/\W/, '').strip + "_" + @doc.id_counter.to_s
end
end
end
4 changes: 2 additions & 2 deletions spec/block_docs/abbrev.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ md_el(:document,[
md_ref_def("jos", "jos", {:title=>nil})
],{},[])
*** Output of to_html ***
<h1 id="webkit_safari_31_and_the_css_fontface_declaration">WebKit (Safari 3.1) and the <abbr title="Cascading Style Sheets">CSS</abbr> @font-face declaration</h1>
<h1 id="webkit_safari_31_and_the_css_fontface_declaration_1">WebKit (Safari 3.1) and the <abbr title="Cascading Style Sheets">CSS</abbr> @font-face declaration</h1>

<p>I&#8217;m a big fan of typography in general. If you check out <a href="http://elliottcable.name">my homepage</a> or my <a href="http://elliottcable.name/contact.xhtml">contact elliottcable</a> page, and you&#8217;re using Safari/WebKit or Opera/Kestrel, you&#8217;ll notice the typefaces (fonts, as colloquialized) are <em>very</em> non-standard. (As of this writing, I&#8217;m using <a href="http://www.josbuivenga.demon.nl/museo.html" title="Jos Buivenga's Museo free typeface">Museo</a> and <a href="http://www.josbuivenga.demon.nl/diavlo.html" title="Jos Buivenga's free Diavlo typeface">Diavlo</a><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> heavily on both.)</p>

Expand Down Expand Up @@ -508,7 +508,7 @@ div#content {
<p>To give Microsoft a little credit, something I rarely do&#8230; Yes, I&#8217;m aware Microsoft submitted EOT to the <abbr title="World Wide Web Consortium">W3C</abbr> as a proposal - the problem isn&#8217;t with their attempts to make it non-proprietary, but with the basic concept of making typefaces on the web DRMed. Look what such attempts have done to the music and video industry - simply decimated it. Do we really want to see the same thing happen to our beloved medium as typography moves into the 21st century? <a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li></ol></div>
*** Output of to_latex ***
\hypertarget{webkit_safari_31_and_the_css_fontface_declaration}{}\section*{{WebKit (Safari 3.1) and the CSS @font-face declaration}}\label{webkit_safari_31_and_the_css_fontface_declaration}
\hypertarget{webkit_safari_31_and_the_css_fontface_declaration_1}{}\section*{{WebKit (Safari 3.1) and the CSS @font-face declaration}}\label{webkit_safari_31_and_the_css_fontface_declaration_1}

I'm a big fan of typography in general. If you check out \href{http://elliottcable.name}{my homepage} or my \href{http://elliottcable.name/contact.xhtml}{contact elliottcable} page, and you're using Safari/WebKit or Opera/Kestrel, you'll notice the typefaces (fonts, as colloquialized) are \emph{very} non-standard. (As of this writing, I'm using \href{http://www.josbuivenga.demon.nl/museo.html}{Museo} and \href{http://www.josbuivenga.demon.nl/diavlo.html}{Diavlo}\footnote{These are fonts by \href{jos}{Jos Buivenga}, quite the amazing person. His (free) fonts are, uniquely, released for use on the web in {\colorbox[rgb]{1.00,0.93,1.00}{\tt \char64font\char45face}} declarations - unlike the vast majority of other (even free to download) typefaces, which have ridiculously restricting licenses and terms of use statements. Props, Jos - you're a pioneer, and deserve recognition as such.} heavily on both.)

Expand Down
4 changes: 2 additions & 2 deletions spec/block_docs/attributes/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ md_el(:document,[

<h3 id="header2">Header with attributes</h3>

<h3 id="header_no_attributes">Header no attributes</h3>
<h3 id="header_no_attributes_3">Header no attributes</h3>

<p id="par1">Paragraph with a.</p>

Expand All @@ -44,7 +44,7 @@ md_el(:document,[

\hypertarget{header2}{}\subsubsection*{{Header with attributes}}\label{header2}

\hypertarget{header_no_attributes}{}\subsubsection*{{Header no attributes}}\label{header_no_attributes}
\hypertarget{header_no_attributes_3}{}\subsubsection*{{Header no attributes}}\label{header_no_attributes_3}

Paragraph with a.

Expand Down
2 changes: 1 addition & 1 deletion spec/block_docs/fenced_code_blocks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Fenced code blocks
*** Parameters: ***
{ :fenced_code_blocks => true }
{ :fenced_code_blocks => true, :html_use_syntax => false }
*** Markdown input: ***
```ruby
john = Twitter::Client.new(
Expand Down
78 changes: 78 additions & 0 deletions spec/block_docs/footnotes2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Write a comment abouth the test here.
*** Parameters: ***
require 'maruku/ext/math';{:html_math_engine => 'itex2mml'}
*** Markdown input: ***
Ruby on Rails is a web-framework[^framework]. It uses the MVC[^MVC] architecture pattern. It has its good points[^points].

[^framework]: a reusable set of libraries
[^MVC]: Model View Controller
[^points]: Here are its good points
1. Ease of use
2. Rapid development

That has nothing to do with putting equations in footnotes[^equations].

[^equations]: Like this:
$$
x = r\cos\theta
$$
*** Output of inspect ***
md_el(:document,[
md_par([
"Ruby on Rails is a web-framework",
md_foot_ref("^framework"),
". It uses the MVC",
md_foot_ref("^MVC"),
" architecture pattern. It has its good points",
md_foot_ref("^points"),
"."
]),
md_el(:footnote, md_par("a reusable set of libraries"), {:footnote_id=>"^framework"}),
md_el(:footnote, md_par("Model View Controller"), {:footnote_id=>"^MVC"}),
md_el(:footnote, [
md_par("Here are its good points"),
md_el(:ol, [md_li("Ease of use", false), md_li("Rapid development", false)])
], {:footnote_id=>"^points"}),
md_par([
"That has nothing to do with putting equations in footnotes",
md_foot_ref("^equations"),
"."
]),
md_el(:footnote, [
md_par("Like this:"),
md_el(:equation, [], {:math=>"\nx = r\\cos\\theta\n\n", :label=>nil, :num=>nil})
], {:footnote_id=>"^equations"})
],{},[])
*** Output of to_html ***
<p>Ruby on Rails is a web-framework<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>. It uses the MVC<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> architecture pattern. It has its good points<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup>.</p>

<p>That has nothing to do with putting equations in footnotes<sup id="fnref:4"><a href="#fn:4" rel="footnote">4</a></sup>.</p>
<div class="footnotes"><hr /><ol><li id="fn:1">
<p>a reusable set of libraries <a href="#fnref:1" rev="footnote">↩</a></p>
</li><li id="fn:2">
<p>Model View Controller <a href="#fnref:2" rev="footnote">↩</a></p>
</li><li id="fn:3">
<p>Here are its good points</p>

<ol>
<li>Ease of use</li>

<li>Rapid development</li>
</ol>
<a href="#fnref:3" rev="footnote">↩</a></li><li id="fn:4">
<p>Like this:</p>
<div class="maruku-equation"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block" class="maruku-mathml"><mi>x</mi><mo>=</mo><mi>r</mi><mi>cos</mi><mi>θ</mi></math><span class="maruku-eq-tex"><code style="display: none">x = r\cos\theta</code></span></div><a href="#fnref:4" rev="footnote">↩</a></li></ol></div>
*** Output of to_latex ***
Ruby on Rails is a web-framework\footnote{a reusable set of libraries} . It uses the MVC\footnote{Model View Controller} architecture pattern. It has its good points\footnote{Here are its good points

\begin{enumerate}%
\item Ease of use
\item Rapid development

\end{enumerate}} .

That has nothing to do with putting equations in footnotes\footnote{Like this:

\begin{displaymath}
x = r\cos\theta
\end{displaymath}} .
12 changes: 6 additions & 6 deletions spec/block_docs/header_after_par.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ md_el(:document,[
*** Output of to_html ***
<p>Paragraph</p>

<h3 id="header_1">header 1</h3>
<h3 id="header_1_1">header 1</h3>

<p>Paragraph</p>

<h2 id="header_2">header 2</h2>
<h2 id="header_2_2">header 2</h2>

<p>Paragraph</p>

<h1 id="header_3">header 3</h1>
<h1 id="header_3_3">header 3</h1>
*** Output of to_latex ***
Paragraph

\hypertarget{header_1}{}\subsubsection*{{header 1}}\label{header_1}
\hypertarget{header_1_1}{}\subsubsection*{{header 1}}\label{header_1_1}

Paragraph

\hypertarget{header_2}{}\subsection*{{header 2}}\label{header_2}
\hypertarget{header_2_2}{}\subsection*{{header 2}}\label{header_2_2}

Paragraph

\hypertarget{header_3}{}\section*{{header 3}}\label{header_3}
\hypertarget{header_3_3}{}\section*{{header 3}}\label{header_3_3}
*** Output of to_md ***
Paragraph

Expand Down
12 changes: 6 additions & 6 deletions spec/block_docs/headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ md_el(:document,[
md_el(:header,["A title with ", md_em(["emphasis"])],{:level=>4},[])
],{},[])
*** Output of to_html ***
<h1 id="a_title_with_emphasis">A title with <em>emphasis</em></h1>
<h1 id="a_title_with_emphasis_1">A title with <em>emphasis</em></h1>

<h2 id="a_title_with_emphasis">A title with <em>emphasis</em></h2>
<h2 id="a_title_with_emphasis_2">A title with <em>emphasis</em></h2>

<h4 id="a_title_with_emphasis">A title with <em>emphasis</em></h4>
<h4 id="a_title_with_emphasis_3">A title with <em>emphasis</em></h4>
*** Output of to_latex ***
\hypertarget{a_title_with_emphasis}{}\section*{{A title with \emph{emphasis}}}\label{a_title_with_emphasis}
\hypertarget{a_title_with_emphasis_1}{}\section*{{A title with \emph{emphasis}}}\label{a_title_with_emphasis_1}

\hypertarget{a_title_with_emphasis}{}\subsection*{{A title with \emph{emphasis}}}\label{a_title_with_emphasis}
\hypertarget{a_title_with_emphasis_2}{}\subsection*{{A title with \emph{emphasis}}}\label{a_title_with_emphasis_2}

\hypertarget{a_title_with_emphasis}{}\paragraph*{{A title with \emph{emphasis}}}\label{a_title_with_emphasis}
\hypertarget{a_title_with_emphasis_3}{}\paragraph*{{A title with \emph{emphasis}}}\label{a_title_with_emphasis_3}
*** Output of to_md ***
# A title with *emphasis* #

Expand Down
8 changes: 7 additions & 1 deletion spec/block_docs/html_inline.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ One
<span></span>123

<span></span>123

<animateColor/>123
*** Output of inspect ***
md_el(:document,[
md_par(["One ", md_html("<span></span>"), "123"]),
md_par([md_html("<span></span>"), "123"])
md_par([md_html("<span></span>"), "123"]),
md_html("<animateColor/>"),
md_par("123")
],{},[])
*** Output of to_html ***
<p>One <span></span>123</p>
<p><span></span>123</p>
<animateColor></animateColor>
<p>123</p>
2 changes: 1 addition & 1 deletion spec/block_docs/issue20.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Just an attribute list on its own in a header is probably really content. https:
*** Output of inspect ***
md_el(:document, md_el(:header, "{hi}", {:level=>1}))
*** Output of to_html ***
<h1 id="hi">{hi}</h1>
<h1 id="hi_1">{hi}</h1>
2 changes: 1 addition & 1 deletion spec/block_docs/issue29.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Generating ids for unicode headers. Other markdown implementations drop the non-
*** Output of inspect ***
md_el(:document, md_el(:header, "Übersicht", {:level=>1}))
*** Output of to_html ***
<h1 id='bersicht'>Übersicht</h1>
<h1 id='bersicht_1'>Übersicht</h1>
4 changes: 2 additions & 2 deletions spec/block_docs/issue74.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ md_el(:document, [
md_el(:header, "Recents Post", {:level=>2})
])
*** Output of to_html ***
<h2 id="cool_title">Cool Title</h2>
<h2 id="cool_title_1">Cool Title</h2>
<ul>
<li>Cool Text yada yada</li>
<li>ICool Tex 2 yada yada</li>
Expand All @@ -35,4 +35,4 @@ md_el(:document, [
<a href="" class="stumbleupon" target="_blank"></a>
<a href="" class="stumbleupon" target="_blank"></a>
</p>
<h2 id="recents_post">Recents Post</h2>
<h2 id="recents_post_2">Recents Post</h2>
9 changes: 6 additions & 3 deletions spec/block_docs/issue79.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
PENDING - Non-ASCII characters in a PRE tag. See https://github.com/bhollis/maruku/issues/79
Encoding: utf-8
Non-ASCII characters in a PRE tag. See https://github.com/bhollis/maruku/issues/79
*** Parameters: ***
{}
*** Markdown input: ***
<p>á é í ó ú</p>

<pre>
á é í ó ú
</pre>
*** Output of inspect ***
md_el(:document, md_html("<pre>\ná é í ó ú\n</pre>"))
md_el(:document, [md_html("<p>á é í ó ú</p>"), md_html("<pre>\ná é í ó ú\n</pre>")])
*** Output of to_html ***
<pre>
<p>á é í ó ú</p><pre>
á é í ó ú
</pre>
Loading

0 comments on commit d5c13bb

Please sign in to comment.