Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
detabify codeblock
Browse files Browse the repository at this point in the history
test "Tabs.text" pass
  • Loading branch information
fperrad committed Mar 28, 2009
1 parent 7568ab1 commit 5f65acc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/Compiler.pir
Expand Up @@ -54,6 +54,27 @@ Markdown::HTML::Compiler implements a compiler for MAST nodes.
.return (str)
.end

.sub 'detab' :anon
.param string str
$P0 = split '', str
$P1 = new 'ResizableStringArray'
L1:
unless $P0 goto L2
$S0 = shift $P0
if $S0 == "\t" goto L3
push $P1, $S0
goto L1
L3:
push $P1, ' '
$I0 = elements $P1
$I0 %= 4
if $I0 goto L3
goto L1
L2:
str = join '', $P1
.return (str)
.end

.sub 'obscure_text' :anon
.param string str
$S0 = ''
Expand Down Expand Up @@ -465,6 +486,10 @@ Return generated HTML for all of its children.
.sub 'html' :method :multi(_, ['Markdown'; 'Line'])
.param pmc node
$S1 = node.'text'()
$I0 = node.'detab'()
unless $I0 goto L1
$S1 = detab($S1)
L1:
$S0 = escape_xml($S1)
.local pmc code
new code, 'CodeString'
Expand Down
9 changes: 9 additions & 0 deletions src/Node.pir
Expand Up @@ -48,6 +48,15 @@ for Markdown.
.end
.namespace ['Markdown'; 'Line']
.sub 'detab' :method
.param pmc value :optional
.param int has_value :opt_flag
.tailcall self.'attr'('detab', value, has_value)
.end
.namespace ['Markdown'; 'Link']
.sub 'image' :method
Expand Down
3 changes: 2 additions & 1 deletion src/parser/actions.pm
Expand Up @@ -139,7 +139,8 @@ method BlankLine($/) {
}

method NonblankIndentedLine($/) {
make Markdown::Line.new( :text( ~$<IndentedLine><Line><RawLine>.text() ) );
make Markdown::Line.new( :text( ~$<IndentedLine><Line><RawLine>.text() ),
:detab( 1 ) );
}

method VerbatimChunk($/) {
Expand Down

0 comments on commit 5f65acc

Please sign in to comment.