Skip to content

Commit 11c7eab

Browse files
authored
Merge pull request #87 from posthtml/milestone-1.4.3
Milestone 1.4.3
2 parents b351d16 + 13a67d1 commit 11c7eab

File tree

7 files changed

+66
-3
lines changed

7 files changed

+66
-3
lines changed

lib/index.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ module.exports = function postHTMLExpressions (options) {
152152
unescapeDelimitersReplace = new RegExp(`@${delimitersSettings[0].text[0]}`, 'g')
153153

154154
// kick off the parsing
155-
return walk.bind(null, { locals: options.locals })
155+
return function (tree) {
156+
return clearRawTag(walk({ locals: options.locals }, tree))
157+
}
156158
}
157159

158160
function walk (opts, nodes) {
@@ -170,8 +172,6 @@ function walk (opts, nodes) {
170172

171173
// don't parse ignoredTag
172174
if (node.tag === ignored) {
173-
node.tag = false
174-
175175
m.push(node)
176176

177177
return m
@@ -396,3 +396,22 @@ function walk (opts, nodes) {
396396
return m
397397
}, [])
398398
}
399+
400+
401+
function clearRawTag(tree) {
402+
403+
return tree.reduce((m, node) => {
404+
if (node.content) {
405+
node.content = clearRawTag(node.content)
406+
}
407+
408+
if (node.tag === ignored) {
409+
node.tag = false
410+
}
411+
412+
m.push(node)
413+
414+
return m
415+
}, [])
416+
417+
}

test/expect/raw_in_condition.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
{{ foo }}
3+
4+
<p class="{{ dynamicClass }}">bar</p>
5+

test/expect/raw_in_switch.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Hello from Earth, {{ username }}
2+
3+
4+
5+
Hello from Moscow, {{ username }}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<if condition="foo === 'bar'">
2+
<raw>
3+
{{ foo }}
4+
</raw>
5+
</if>
6+
<p class="@{{ dynamicClass }}">{{ foo }}</p>
7+

test/fixtures/raw_in_switch.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<switch expression="country">
2+
<case n="'russia'">
3+
<p>Hello, from Russia!</p>
4+
</case>
5+
<default>
6+
<raw>Hello from Earth, {{ username }}</raw>
7+
</default>
8+
</switch>
9+
10+
<switch expression="city">
11+
<case n="'moscow'">
12+
<raw>Hello from Moscow, {{ username }}</raw>
13+
</case>
14+
<default>
15+
<p>Hello, from Earth!</p>
16+
</default>
17+
</switch>

test/test-core.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ test('Raw output', (t) => {
7878
return process(t, 'raw', { locals: { foo: 'bar' } })
7979
})
8080

81+
test('Raw output - inside condition', (t) => {
82+
return process(t, 'raw_in_condition', { locals: { foo: 'bar' } })
83+
})
84+
8185
test('Raw output - custom tag', (t) => {
8286
return process(t, 'raw_custom', { ignoredTag: 'verbatim', locals: { foo: 'bar' } })
8387
})

test/test-switch.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ test('Switch - bad flow', (t) => {
9090
t.is(err.message, 'the "switch" tag can contain only "case" tags and one "default" tag')
9191
})
9292
})
93+
94+
test('Switch - raw tag', (t) => {
95+
return Promise.all([
96+
process(t, 'raw_in_switch', { locals: { country: 'germany', city: 'moscow' } })
97+
])
98+
})

0 commit comments

Comments
 (0)