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

Commit

Permalink
Merge pull request #152 from trailimage/develop
Browse files Browse the repository at this point in the history
formatting fixes and test tweaks
  • Loading branch information
Jason-Abbott committed Sep 29, 2018
2 parents 49becb4 + 73c969c commit af9fc5e
Show file tree
Hide file tree
Showing 8 changed files with 672 additions and 629 deletions.
18 changes: 7 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
language: node_js

node_js:
- "10"
- '10'

branches:
only:
- master
only:
- master

script:
- yarn global add codecov
- yarn test
- codecov
- yarn global add codecov
- yarn test
- codecov

sudo: false

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH="$HOME/.yarn/bin:$PATH"

cache:
yarn: true
yarn: true
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## 4.1.7

- Shorten threshold for block quoting and make condition stricter for poem formatting

## 4.1.6

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

## 4.1.5

Expand Down
4 changes: 2 additions & 2 deletions src/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default {
},

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

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

//get any() { return /(^|[\r\n]{1,2})((([^\r\n](?![,?]”[⁰¹²³⁴⁵⁶⁷⁸⁹])){4,80}[\r\n]{1,2}){3,})/gi; },
Expand Down
2 changes: 1 addition & 1 deletion src/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { route, RouteParam } from './routes';
import { MockExpressApp } from '@toba/test';
import { loadMockData } from './.test-data';

const app = new MockExpressApp();
const app: any = new MockExpressApp();

beforeAll(async done => {
await loadMockData();
Expand Down
38 changes: 38 additions & 0 deletions src/views/html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,22 @@ test('identifies quote within text', () => {
expect(html.caption(source)).toBe(target);
});

test('formats blockquote with trailing ellipsis', () => {
const phrase =
'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 ...';
const source = lipsum + ds + '“' + phrase + '”¹' + ds + lipsum;
const target =
'<p>' +
lipsum +
'</p><blockquote><p>' +
phrase +
'<sup>¹</sup></p></blockquote><p class="first">' +
lipsum +
'</p>';

expect(html.caption(source)).toBe(target);
});

test('identifies block quote when it is the entire caption', () => {
const source = '“' + lipsum + '”¹';
const target = '<blockquote><p>' + lipsum + '<sup>¹</sup></p></blockquote>';
Expand Down Expand Up @@ -303,6 +319,28 @@ test('identifies haiku', () => {
expect(html.story(source)).toBe(target);
});

test('does not convert conversation to a poem', () => {
const source =
'“What’s wrong Brenna?” I ask.' +
ds +
'“I can’t sleep.”' +
ds +
'“Just lay down.”' +
ds +
'“I can’t.”' +
ds +
'“Brenna,” I insist, “lay down.”';

const target =
'<p class="quip">“What’s wrong Brenna?” I ask.</p>' +
'<p>“I can’t sleep.”</p>' +
'<p>“Just lay down.”</p>' +
'<p>“I can’t.”</p>' +
'<p>“Brenna,” I insist, “lay down.”</p>';

expect(html.story(source)).toBe(target);
});

test('identifies captions that are entirely a poem', () => {
const source =
'-' +
Expand Down
5 changes: 4 additions & 1 deletion src/views/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@ function caption(text: string): string {
text = text
.replace(re.newLine, '</p><p>')
.replace(re.tag.emptyParagraph, '')
.replace(re.quip, (_match, _tag, body) => '<p class="quip">' + body)
.replace(
re.quip,
(_match, _tag: string, body: string) => '<p class="quip">' + body
)
.replace(re.footnote.number, '$1<sup>$2</sup>')
// restore blockquotes
.replace(/\[\/Q][\r\n\s]*([^<]+)/g, '[/Q]<p class="first">$1')
Expand Down
13 changes: 10 additions & 3 deletions src/views/view.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import '@toba/test';
import { Header, MimeType } from '@toba/tools';
import { MockRequest, MockResponse } from '@toba/test';
import { cache, view, createViewItem, writeItemToResponse, IPv6 } from './view';
import {
cache,
view,
createViewItem,
writeItemToResponse,
IPv6,
Renderer
} from './view';
import { config } from '../config/';

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

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

test('sends already rendered pages from cache', done => {
res.onEnd = done;
view.send(res, viewSlug, _render => {
view.send(res, viewSlug, (_render: Renderer) => {
throw new Error('Attempt to render page that should be cached');
});
});
Expand Down
Loading

0 comments on commit af9fc5e

Please sign in to comment.