Skip to content

Commit

Permalink
Fix extended blockcode stripping whitespace following blank line. [#78
Browse files Browse the repository at this point in the history
…state:resolved]
  • Loading branch information
jgarber committed Oct 31, 2008
1 parent fff9ea5 commit ac7d616
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
1 change: 0 additions & 1 deletion ext/redcloth_scan/redcloth_inline.c.rl
Expand Up @@ -87,7 +87,6 @@ VALUE
red_blockcode(VALUE self, VALUE regs, VALUE block)
{
VALUE btype = rb_hash_aref(regs, ID2SYM(rb_intern("type")));
block = rb_funcall(block, rb_intern("strip"), 0);
if (RSTRING_LEN(block) > 0)
{
rb_hash_aset(regs, ID2SYM(rb_intern("text")), block);
Expand Down
1 change: 0 additions & 1 deletion ext/redcloth_scan/redcloth_scan.c.rl
Expand Up @@ -69,7 +69,6 @@ VALUE
redcloth_transform2(self, str)
VALUE self, str;
{
rb_str_cat2(str, "\n");
StringValue(str);
rb_funcall(self, rb_intern("before_transform"), 1, str);
return redcloth_transform(self, RSTRING_PTR(str), RSTRING_PTR(str) + RSTRING_LEN(str) + 1, Qnil);
Expand Down
2 changes: 0 additions & 2 deletions ext/redcloth_scan/redcloth_scan.java.rl
Expand Up @@ -137,7 +137,6 @@ public class RedclothScanService implements BasicLibraryService {
public IRubyObject red_blockcode(IRubyObject self, IRubyObject regs, IRubyObject block) {
Ruby runtime = self.getRuntime();
IRubyObject btype = ((RubyHash)regs).aref(runtime.newSymbol("type"));
block = block.callMethod(runtime.getCurrentContext(), "strip");
if(((RubyString)block).getByteList().realSize > 0) {
((RubyHash)regs).aset(runtime.newSymbol("text"), block);
block = self.callMethod(runtime.getCurrentContext(), btype.asJavaString(), regs);
Expand Down Expand Up @@ -392,7 +391,6 @@ public class RedclothScanService implements BasicLibraryService {

public static IRubyObject transform2(IRubyObject self, IRubyObject str) {
RubyString ss = str.convertToString();
ss.cat((byte)'\n');
self.callMethod(self.getRuntime().getCurrentContext(), "before_transform", ss);
return transform(self, ss.getByteList().bytes(), ss.getByteList().begin, ss.getByteList().realSize, self.getRuntime().getNil());
}
Expand Down
2 changes: 1 addition & 1 deletion ext/redcloth_scan/redcloth_scan.rl
Expand Up @@ -50,7 +50,7 @@
block_end_tag = "</" BlockTagName space* ">" ;
html_start = indent >B %{STORE_B("indent_before_start");} block_start_tag >B %{STORE_B("start_tag");} indent >B %{STORE_B("indent_after_start");} ;
html_end = indent >B %{STORE_B("indent_before_end");} block_end_tag >B %{STORE_B("end_tag");} (indent LF?) >B %{STORE_B("indent_after_end");} ;
standalone_html = indent (block_start_tag | block_empty_tag | block_end_tag) indent LF+;
standalone_html = indent (block_start_tag | block_empty_tag | block_end_tag) indent (LF+ | EOF);
html_end_terminating_block = ( LF indent block_end_tag ) >A @{ p = reg - 1; } ;

# tables
Expand Down
30 changes: 28 additions & 2 deletions test/code.yml
Expand Up @@ -42,8 +42,7 @@ html: "<p>Math fact: 3 &lt; 5 &amp; 5 &gt; 3 but &pound;6 &#62; $6. Oh, and 2 &d
latex: "Math fact: 3 \\textless{} 5 \\& 5 \\textgreater{} 3 but \\pounds{}6 \\textgreater{} \\$6. Oh, and 2 \\textdiv{} 4 is \\sfrac{1}{2}.\n\n"
---
name: escaping of existing entities in blockcode
in: "bc. Math fact: 3 &lt; 5 &amp; 5 &gt; 3 but &pound;5 &#62; $5.
"
in: "bc. Math fact: 3 &lt; 5 &amp; 5 &gt; 3 but &pound;5 &#62; $5."
html: "<pre><code>Math fact: 3 &amp;lt; 5 &amp;amp; 5 &amp;gt; 3 but &amp;pound;5 &amp;#62; $5.</code></pre>"
latex: "\\begin{verbatim}\nMath fact: 3 &lt; 5 &amp; 5 &gt; 3 but &pound;5 &#62; $5.\\end{verbatim}\n"
---
Expand Down Expand Up @@ -146,6 +145,33 @@ html: |-
</pre>
<p>And then go back with a normal paragraph.</p>
---
name: extended block code preserves leading whitespace after blank line
in: |-
bc.. class Foo
def bar
'bar'
end
def baz
'baz'
end
end
p. That's it!
html: |-
<pre><code>class Foo
def bar
'bar'
end</code>
<code> def baz
'baz'
end
end</code>
</pre>
<p>That&#8217;s it!</p>
---
name: block code containing code avoids nesting code tags
in: |-
bc. A one-liner: @ruby -ne '($h||={}).fetch($_){puts $h[$_]=$_}'@
Expand Down

0 comments on commit ac7d616

Please sign in to comment.