Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
artragis committed Jun 19, 2017
1 parent 64fea94 commit 33b51e3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 48 deletions.
42 changes: 0 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions packages/rebber/__tests__/fixtures/mix-2.expected.tex
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
(for convenience, are replaced with simple single spaces in the tests)

\chapter{first 1}

\begin{Quotation}{Quotation Source}

Code inside quote

\begin{codeBlock}[code source]{python}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ <h2>Code</h2>
<p>With Legend</p>
<figure><pre><code class="language-python">print('bla')
</code></pre><figcaption>figcapt1</figcaption></figure>
<figure><pre><code class="language-python">print('bla2')
</code></pre><figcaption>figcapt1</figcaption></figure>
<p>Code: bis</p>
7 changes: 7 additions & 0 deletions packages/remark-captions/__tests__/fixtures/code.fixture.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ With Legend
print('bla')
```
Code: figcapt1


```python
print('bla2')
```
Code: figcapt1
Code: bis
9 changes: 7 additions & 2 deletions packages/remark-captions/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ function externLegendVisitor(node, index, parent) {
var legendNode = parent.children[index + 1];

if (legendNode.children[0].value.startsWith(legendBlock[node.type])) {
var legendText = legendNode.children[0].value.split('\n')[0].replace(legendBlock[node.type], '').trim();
var fullLegendLine = legendBlock[node.type] + ' ' + legendText;
legendNode.children[0].value = legendNode.children[0].value.replace(fullLegendLine, '').trim();
var figcaption = {
type: 'figcaption',
children: [{
type: 'text',
value: legendNode.children[0].value.replace(legendBlock[node.type], '').trim()
value: legendText
}],
data: {
hName: 'figcaption'
Expand All @@ -84,7 +87,9 @@ function externLegendVisitor(node, index, parent) {
node.type = figure.type;
node.children = figure.children;
node.data = figure.data;
parent.children.splice(index + 1, 1);
if (!legendNode.children[0].value) {
parent.children.splice(index + 1, 1);
}
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions packages/remark-captions/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ function externLegendVisitor (node, index, parent) {
const legendNode = parent.children[index + 1]

if (legendNode.children[0].value.startsWith(legendBlock[node.type])) {
const legendText = legendNode.children[0].value
.split('\n')[0].replace(legendBlock[node.type], '').trim()
const fullLegendLine = `${legendBlock[node.type]} ${legendText}`
legendNode.children[0].value = legendNode.children[0].value.replace(fullLegendLine, '').trim()
const figcaption = {
type: 'figcaption',
children: [{
type: 'text',
value: legendNode.children[0].value.replace(legendBlock[node.type], '').trim()
value: legendText
}],
data: {
hName: 'figcaption',
Expand All @@ -86,7 +90,9 @@ function externLegendVisitor (node, index, parent) {
node.type = figure.type
node.children = figure.children
node.data = figure.data
parent.children.splice(index + 1, 1)
if (!legendNode.children[0].value) {
parent.children.splice(index + 1, 1)
}
}
}
}
Expand Down

0 comments on commit 33b51e3

Please sign in to comment.