Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit af9fc5e

Browse files
authored
Merge pull request #152 from trailimage/develop
formatting fixes and test tweaks
2 parents 49becb4 + 73c969c commit af9fc5e

8 files changed

+672
-629
lines changed

.travis.yml

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
language: node_js
22

33
node_js:
4-
- "10"
4+
- '10'
55

66
branches:
7-
only:
8-
- master
7+
only:
8+
- master
99

1010
script:
11-
- yarn global add codecov
12-
- yarn test
13-
- codecov
11+
- yarn global add codecov
12+
- yarn test
13+
- codecov
1414

1515
sudo: false
1616

17-
before_install:
18-
- curl -o- -L https://yarnpkg.com/install.sh | bash
19-
- export PATH="$HOME/.yarn/bin:$PATH"
20-
2117
cache:
22-
yarn: true
18+
yarn: true

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
## 4.1.7
2+
3+
- Shorten threshold for block quoting and make condition stricter for poem formatting
4+
15
## 4.1.6
26

3-
- Fix block quote when it's the entire caption (issue #131)
7+
- Fix block quote when it's the entire caption (issue #131)
48

59
## 4.1.5
610

src/regex.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
},
7171

7272
/** Long quote followed by line break or end of text */
73-
block: /(\r\n|\r|\n|^)([^]{275,}[¹²³]*)\s*(\r\n|\r|\n|$)/g
73+
block: /(\r\n|\r|\n|^)([^]{200,}[¹²³]*)\s*(\r\n|\r|\n|$)/g
7474
//get block() { return /[\r\n]*(“[^”]{275,}”[⁰¹²³⁴⁵⁶⁷⁸⁹]*)\s*[\r\n]/g; }
7575
},
7676

@@ -144,7 +144,7 @@ export default {
144144
* leading space and poem body.
145145
*/
146146
get any() {
147-
return /(^|[\r\n]{1,2})((([^\r\n](?![,!?])){4,80}([\r\n]+|$)){3,})/gi;
147+
return /(^|[\r\n]{1,2})((([^\r\n](?![\.,!?])){4,80}([\r\n]+|$)){3,})/gi;
148148
},
149149

150150
//get any() { return /(^|[\r\n]{1,2})((([^\r\n](?![,?]”[⁰¹²³⁴⁵⁶⁷⁸⁹])){4,80}[\r\n]{1,2}){3,})/gi; },

src/routes.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { route, RouteParam } from './routes';
44
import { MockExpressApp } from '@toba/test';
55
import { loadMockData } from './.test-data';
66

7-
const app = new MockExpressApp();
7+
const app: any = new MockExpressApp();
88

99
beforeAll(async done => {
1010
await loadMockData();

src/views/html.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,22 @@ test('identifies quote within text', () => {
190190
expect(html.caption(source)).toBe(target);
191191
});
192192

193+
test('formats blockquote with trailing ellipsis', () => {
194+
const phrase =
195+
'Firefighters are working to get a handle on several wildfires that sparked during a lightning storm on Thursday night. Strong winds and poor visibility created challenges for firefighters working the blazes on Saturday ...';
196+
const source = lipsum + ds + '“' + phrase + '”¹' + ds + lipsum;
197+
const target =
198+
'<p>' +
199+
lipsum +
200+
'</p><blockquote><p>' +
201+
phrase +
202+
'<sup>¹</sup></p></blockquote><p class="first">' +
203+
lipsum +
204+
'</p>';
205+
206+
expect(html.caption(source)).toBe(target);
207+
});
208+
193209
test('identifies block quote when it is the entire caption', () => {
194210
const source = '“' + lipsum + '”¹';
195211
const target = '<blockquote><p>' + lipsum + '<sup>¹</sup></p></blockquote>';
@@ -303,6 +319,28 @@ test('identifies haiku', () => {
303319
expect(html.story(source)).toBe(target);
304320
});
305321

322+
test('does not convert conversation to a poem', () => {
323+
const source =
324+
'“What’s wrong Brenna?” I ask.' +
325+
ds +
326+
'“I can’t sleep.”' +
327+
ds +
328+
'“Just lay down.”' +
329+
ds +
330+
'“I can’t.”' +
331+
ds +
332+
'“Brenna,” I insist, “lay down.”';
333+
334+
const target =
335+
'<p class="quip">“What’s wrong Brenna?” I ask.</p>' +
336+
'<p>“I can’t sleep.”</p>' +
337+
'<p>“Just lay down.”</p>' +
338+
'<p>“I can’t.”</p>' +
339+
'<p>“Brenna,” I insist, “lay down.”</p>';
340+
341+
expect(html.story(source)).toBe(target);
342+
});
343+
306344
test('identifies captions that are entirely a poem', () => {
307345
const source =
308346
'-' +

src/views/html.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,10 @@ function caption(text: string): string {
319319
text = text
320320
.replace(re.newLine, '</p><p>')
321321
.replace(re.tag.emptyParagraph, '')
322-
.replace(re.quip, (_match, _tag, body) => '<p class="quip">' + body)
322+
.replace(
323+
re.quip,
324+
(_match, _tag: string, body: string) => '<p class="quip">' + body
325+
)
323326
.replace(re.footnote.number, '$1<sup>$2</sup>')
324327
// restore blockquotes
325328
.replace(/\[\/Q][\r\n\s]*([^<]+)/g, '[/Q]<p class="first">$1')

src/views/view.test.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import '@toba/test';
22
import { Header, MimeType } from '@toba/tools';
33
import { MockRequest, MockResponse } from '@toba/test';
4-
import { cache, view, createViewItem, writeItemToResponse, IPv6 } from './view';
4+
import {
5+
cache,
6+
view,
7+
createViewItem,
8+
writeItemToResponse,
9+
IPv6,
10+
Renderer
11+
} from './view';
512
import { config } from '../config/';
613

714
const req = new MockRequest();
@@ -33,7 +40,7 @@ test('compresses new pages and adds to cache', done => {
3340
};
3441
res.endOnRender = false;
3542

36-
view.send(res, viewSlug, render => {
43+
view.send(res, viewSlug, (render: Renderer) => {
3744
// mock response echoes back parameters instead of rendering view
3845
render('test-template', {
3946
option1: 'value1',
@@ -50,7 +57,7 @@ test('truncates IPv6 to v4', () => {
5057

5158
test('sends already rendered pages from cache', done => {
5259
res.onEnd = done;
53-
view.send(res, viewSlug, _render => {
60+
view.send(res, viewSlug, (_render: Renderer) => {
5461
throw new Error('Attempt to render page that should be cached');
5562
});
5663
});

0 commit comments

Comments
 (0)