Skip to content

Commit

Permalink
Merge pull request #76 from danielhaim1/master
Browse files Browse the repository at this point in the history
v0.3.2
  • Loading branch information
danielhaim1 authored Oct 19, 2022
2 parents a736873 + 2d21802 commit f36e4ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/punctuation.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module.exports = (text) => {
// Dashes

// M Dash
// https://en.wikipedia.org/wiki/Dash
text = text.replace(/--/g, "–");
text = text.replace(/ /g, " — ");

// Elipses
text = text.replace(/\.\.\./g, "…");
// Ellipsis
// https://en.wikipedia.org/wiki/Ellipsis
text = text.replace(/\.\.\./g, "…");

// Nbsp for punc with spaces
// Non-breaking space
// https://en.wikipedia.org/wiki/Non-breaking_space
const NBSP = " ";
const NBSP_PUNCTUATION_START = /([«¿¡]) /g;
const NBSP_PUNCTUATION_END = / ([\!\?:;\.,»])/g;
Expand Down
8 changes: 4 additions & 4 deletions test/punctuationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ describe("Punctuation", () => {
expect(punc(html)).to.equal("<p>En un lugar de la mancha</p>");
});

it("should replace three dots by elipses symbol", () => {
it("should replace three dots by ellipsis symbol", () => {
const html = "<p>En un lugar de la mancha...</p>";
expect(punc(html)).to.equal("<p>En un lugar de la mancha</p>");
expect(punc(html)).to.equal("<p>En un lugar de la mancha&hellip;</p>");
});

it("should replace three dots by elipses symbol on texts with multiple matches", () => {
it("should replace three dots by ellipsis symbol on texts with multiple matches", () => {
const html =
"<p>En un lugar de la mancha... De cuyo nombre no quiero acordarme... no ha mucho tiempo que vivía...</p>";
expect(punc(html)).to.equal(
"<p>En un lugar de la mancha De cuyo nombre no quiero acordarme no ha mucho tiempo que vivía</p>"
"<p>En un lugar de la mancha&hellip; De cuyo nombre no quiero acordarme&hellip; no ha mucho tiempo que vivía&hellip;</p>"
);
});

Expand Down
2 changes: 1 addition & 1 deletion test/typesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Typeset", () => {
'<p>"She\'s faster than a 120\' 4" whale." <em>Piña co­ladas</em> were widely consumed in Götterdämmerung from 1880–1912. For the low price of $20 / year from Ex­hi­bits A–E... Then the <em>duplex</em> came forward. "Thrice the tower, he mounted the round gunrest, \'awaking\' HTML. He can print a fixed num­ber of dots in a square inch (for in­stance, 600 × 600)."</p>';

expect(typeset(html)).to.equal(
'<p>Yjarni Sigurðardóttir spoke to <span class="small-caps">NATO</span> from Iceland yes­ter­day:<span class="push-double"></span> <span class="pull-double">“</span>Light of my life, fire of my florins&thinsp;&mdash;&thinsp;my sin, my soul. The tip of the tongue tak­ing a trip to 118° 19′ 43.5″.”</p><p><span class="pull-double">“</span>She’s faster than a 120′ 4″ whale.” <em>Piña co­ladas</em> were widely con­sumed in Götterdämmerung from 1880–1912. For the low price of $20 / year from Ex­hi­bits A–E Then the <em>du­plex</em> came for­ward.<span class="push-double"></span> <span class="pull-double">“</span>Thrice the tower, he mounted the round gun­rest,<span class="push-single"></span> <span class="pull-single">‘</span>awaking’ <span class="small-caps">HTML</span>. He can print a fixed num­ber of dots in a square inch (for in­stance, 600 × 600).”</p>'
'<p>Yjarni Sigurðardóttir spoke to <span class="small-caps">NATO</span> from Iceland yes­ter­day:<span class="push-double"></span> <span class="pull-double">“</span>Light of my life, fire of my florins&thinsp;&mdash;&thinsp;my sin, my soul. The tip of the tongue tak­ing a trip to 118° 19′ 43.5″.”</p><p><span class="pull-double">“</span>She’s faster than a 120′ 4″ whale.” <em>Piña co­ladas</em> were widely con­sumed in Götterdämmerung from 1880–1912. For the low price of $20 / year from Ex­hi­bits A–E&hellip; Then the <em>du­plex</em> came for­ward.<span class="push-double"></span> <span class="pull-double">“</span>Thrice the tower, he mounted the round gun­rest,<span class="push-single"></span> <span class="pull-single">‘</span>awaking’ <span class="small-caps">HTML</span>. He can print a fixed num­ber of dots in a square inch (for in­stance, 600 × 600).”</p>'
);
});
});

0 comments on commit f36e4ae

Please sign in to comment.