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

Commit

Permalink
fix escape
Browse files Browse the repository at this point in the history
- add escape from link
- add specific escape for code
  • Loading branch information
fperrad committed Mar 22, 2009
1 parent 359b274 commit aa3989c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/Compiler.pir
Expand Up @@ -30,7 +30,16 @@ Markdown::HTML::Compiler implements a compiler for MAST nodes.
.tailcall self.'html'(past)
.end

.sub 'xml_escape' :anon
.sub 'escape_xml' :anon
.param string str
$P0 = split '&', str
str = join '&', $P0
$P0 = split '<', str
str = join '&lt;', $P0
.return (str)
.end

.sub 'escape_code' :anon
.param string str
$P0 = split '&', str
str = join '&amp;', $P0
Expand Down Expand Up @@ -243,10 +252,12 @@ Return generated HTML for all of its children.
if $S0 goto L0
$S0 = "<a href=\""
$S1 = node.'url'()
$S1 = escape_xml($S1)
$S0 .= $S1
$S1 = node.'title'()
unless $S1 goto L1
$S0 .= "\" title=\""
$S1 = escape_xml($S1)
$S0 .= $S1
L1:
$S0 .= "\">"
Expand All @@ -264,6 +275,7 @@ Return generated HTML for all of its children.
$S0 .= $S1
$S0 .= "\" title=\""
$S1 = node.'title'()
$S1 = escape_xml($S1)
$S0 .= $S1
$S0 .= "\" />"
set code, $S0
Expand All @@ -286,10 +298,12 @@ Return generated HTML for all of its children.
if $S0 goto L0
$S0 = "<a href=\""
$S1 = $P1[0]
$S1 = escape_xml($S1)
$S0 .= $S1
$S1 = $P1[1]
unless $S1 goto L1
$S0 .= "\" title=\""
$S1 = escape_xml($S1)
$S0 .= $S1
L1:
$S0 .= "\">"
Expand All @@ -306,12 +320,14 @@ Return generated HTML for all of its children.
L0:
$S0 = "<img src=\""
$S1 = $P1[0]
$S1 = escape_xml($S1)
$S0 .= $S1
$S0 .= "\" alt=\""
$S1 = self.'html_children'(node)
$S0 .= $S1
$S0 .= "\" title=\""
$S1 = $P1[1]
$S1 = escape_xml($S1)
$S0 .= $S1
$S0 .= "\" />"
set code, $S0
Expand Down Expand Up @@ -392,7 +408,7 @@ Return generated HTML for all of its children.
.sub 'html' :method :multi(_,['Markdown';'Code'])
.param pmc node
$S1 = node.'text'()
$S1 = xml_escape($S1)
$S1 = escape_code($S1)
.local pmc code
new code, 'CodeString'
$S0 = "<code>"
Expand Down Expand Up @@ -422,7 +438,7 @@ Return generated HTML for all of its children.
.sub 'html' :method :multi(_,['Markdown';'Line'])
.param pmc node
$S1 = node.'text'()
$S1 = xml_escape($S1)
$S1 = escape_xml($S1)
.local pmc code
new code, 'CodeString'
set code, $S1
Expand All @@ -436,7 +452,7 @@ Return generated HTML for all of its children.
.sub 'html' :method :multi(_,['Markdown';'Word'])
.param pmc node
$S1 = node.'text'()
$S1 = xml_escape($S1)
$S1 = escape_xml($S1)
.local pmc code
new code, 'CodeString'
set code, $S1
Expand Down

0 comments on commit aa3989c

Please sign in to comment.