-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start supporting code * add some parsing to code * typo * add unittest * fix fixture * rebber-figure-code * rebber-figure-code * rebber-figure-code * get value for code * rebber+caption: fixes for code * Add test * Add test * lock.json * last test
- Loading branch information
Showing
19 changed files
with
308 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
/public/bundle* | ||
npm-debug.log | ||
lerna-debug.log | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
\begin{codeBlock}{python} | ||
print('bla') | ||
\end{codeBlock} | ||
|
||
\begin{codeBlock}[][1,2]{python} | ||
print('bla') | ||
print('bla') | ||
print('bla') | ||
\end{codeBlock} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
```python | ||
print('bla') | ||
``` | ||
|
||
```python hl_lines=1,2 | ||
print('bla') | ||
print('bla') | ||
print('bla') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
\begin{codeBlock}[With Source]{python} | ||
print('bla') | ||
\end{codeBlock} | ||
|
||
\begin{codeBlock}[With Source][1,2]{python} | ||
print('bla') | ||
print('bla') | ||
print('bla') | ||
\end{codeBlock} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```python | ||
print('bla') | ||
``` | ||
Code: With Source | ||
|
||
```python hl_lines=1,2 | ||
print('bla') | ||
print('bla') | ||
print('bla') | ||
``` | ||
Code: With Source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(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} | ||
print('bla') | ||
\end{codeBlock} | ||
\end{Quotation} | ||
|
||
\begin{codeBlock}[First]{python} | ||
print('bla') | ||
\end{codeBlock} | ||
|
||
Code: Second | ||
|
||
\begin{codeBlock}{python} | ||
print('code without caption') | ||
\end{codeBlock} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(for convenience, · are replaced with simple single spaces in the tests) | ||
# first 1 | ||
|
||
> Code inside quote | ||
> ```python | ||
> print('bla') | ||
> ``` | ||
> Code: code source | ||
Source: Quotation Source | ||
|
||
```python | ||
print('bla') | ||
``` | ||
Code: First | ||
Code: Second | ||
|
||
```python | ||
print('code without caption') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
/* Expose. */ | ||
module.exports = code; | ||
|
||
var defaultMacro = function defaultMacro(content, lang) { | ||
var param = ''; | ||
if (lang.indexOf('hl_lines=') > -1) { | ||
var lines = lang.split('hl_lines=')[1].trim(); | ||
param += '[][' + lines + ']'; | ||
} | ||
lang = lang.split(' ')[0]; | ||
return '\\begin{codeBlock}' + param + '{' + lang + '}\n' + content + '\n\\end{codeBlock}\n\n'; | ||
}; | ||
|
||
/* Stringify a Blockquote `node`. */ | ||
function code(ctx, node) { | ||
var macro = ctx.code || defaultMacro; | ||
return macro(node.value, node.lang); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Expose. */ | ||
module.exports = code | ||
|
||
const defaultMacro = (content, lang) => { | ||
let param = '' | ||
if (lang.indexOf('hl_lines=') > -1) { | ||
const lines = lang.split('hl_lines=')[1].trim() | ||
param += `[][${lines}]` | ||
} | ||
lang = lang.split(' ')[0] | ||
return `\\begin{codeBlock}${param}{${lang}}\n${content}\n\\end{codeBlock}\n\n` | ||
} | ||
|
||
/* Stringify a Blockquote `node`. */ | ||
function code (ctx, node) { | ||
const macro = ctx.code || defaultMacro | ||
return macro(node.value, node.lang) | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/remark-captions/__tests__/fixtures/code.expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h2>Code</h2> | ||
<p>Normal code</p> | ||
<pre><code class="language-python">print('bla') | ||
</code></pre> | ||
<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> |
21 changes: 21 additions & 0 deletions
21
packages/remark-captions/__tests__/fixtures/code.fixture.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Code | ||
|
||
Normal code | ||
|
||
```python | ||
print('bla') | ||
``` | ||
|
||
With Legend | ||
|
||
```python | ||
print('bla') | ||
``` | ||
Code: figcapt1 | ||
|
||
|
||
```python | ||
print('bla2') | ||
``` | ||
Code: figcapt1 | ||
Code: bis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.