Skip to content

Commit 03b48bf

Browse files
committed
Merge pull request #10 from plaid/dc-nbsp
control wrapping of type signatures
2 parents 0e8f30e + 08d8b73 commit 03b48bf

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

bin/transcribe

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ var esc = R.pipe(R.replace(/&/g, '&'),
1616
R.replace(/"/g, '"'));
1717

1818

19+
//. nbsp :: String -> String
20+
var nbsp = R.replace(/[ ]/g, '\u00A0');
21+
22+
23+
//. controlWrapping :: String -> String
24+
var controlWrapping =
25+
R.pipe(R.split(' :: '),
26+
R.map(R.split(' => ')),
27+
R.map(R.map(R.split(/([(][^()]+[)])/))),
28+
R.map(R.map(R.append(''))),
29+
R.map(R.map(R.splitEvery(2))),
30+
R.map(R.map(R.map(R.over(R.lensIndex(1), nbsp)))),
31+
R.map(R.map(R.unnest)),
32+
R.map(R.map(R.map(R.split(' -> ')))),
33+
R.map(R.map(R.map(R.map(nbsp)))),
34+
R.map(R.map(R.map(R.join(' -> ')))),
35+
R.map(R.map(R.join(''))),
36+
R.map(R.join(' => ')),
37+
R.join(' :: '));
38+
39+
1940
//. formatSignature :: Options -> String -> Number -> String -> String
2041
var formatSignature = R.curry(function(options, filename, line, signature) {
2142
var tagName = 'h' + String(options.headingLevel);
@@ -25,7 +46,9 @@ var formatSignature = R.curry(function(options, filename, line, signature) {
2546
return (
2647
'<' + esc(tagName) + ' name="' + esc(signature.split(' :: ')[0]) + '">' +
2748
'<code>' +
28-
'<a href="' + esc(href) + '">' + esc(signature) + '</a>' +
49+
'<a href="' + esc(href) + '">' +
50+
esc(controlWrapping(signature)) +
51+
'</a>' +
2952
'</code>' +
3053
'</' + esc(tagName) + '>\n'
3154
);

examples/fp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h3 name="map"><code><a href="https://github.com/plaid/transcribe/blob/v0.3.0/examples/fp.js#L4">map :: (a -> b) -> [a] -> [b]</a></code></h3>
1+
<h3 name="map"><code><a href="https://github.com/plaid/transcribe/blob/v0.3.0/examples/fp.js#L4">map :: (a -> b) -> [a] -> [b]</a></code></h3>
22

33
Transforms a list of elements of type `a` into a list of elements
44
of type `b` using the provided function of type `a -> b`.
@@ -8,7 +8,7 @@ of type `b` using the provided function of type `a -> b`.
88
['1', '2', '3', '4', '5']
99
```
1010

11-
<h3 name="filter"><code><a href="https://github.com/plaid/transcribe/blob/v0.3.0/examples/fp.js#L24">filter :: (a -> Boolean) -> [a] -> [a]</a></code></h3>
11+
<h3 name="filter"><code><a href="https://github.com/plaid/transcribe/blob/v0.3.0/examples/fp.js#L24">filter :: (a -> Boolean) -> [a] -> [a]</a></code></h3>
1212

1313
Returns the list of elements which satisfy the provided predicate.
1414

0 commit comments

Comments
 (0)