Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.3.2a #5

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Typeset

Typeset is an HTML pre-proces­sor for web ty­pog­ra­phy which pro­vides ty­po­graphic fea­tures used tra­di­tion­ally in fine print­ing which re­main un­avail­able to browser lay­out en­gines. Typeset's pro­cess­ing brings the fol­low­ing to your web­pages:
Typeset is an HTML pre-processor for web typography which provides typographic features used traditionally in fine printing which remain unavailable to browser layout engines. Typeset's processing brings the following to your webpages:

- [Hang­ing punc­tu­a­tion](https://en.wikipedia.org/wiki/Hanging_punctuation)
- [Hanging punctuation](https://en.wikipedia.org/wiki/Hanging_punctuation)
- [Ligatures](https://en.wikipedia.org/wiki/Orthographic_ligature)
- [Optical mar­gin align­ment](https://en.wikipedia.org/wiki/Optical_margin_alignment)
- [Punctuation sub­sti­tu­tion](src/punctuation.js)
- [Optical margin alignment](https://en.wikipedia.org/wiki/Optical_margin_alignment)
- [Punctuation substitution](src/punctuation.js)
- [Small caps](https://en.wikipedia.org/wiki/Small_caps)
- [Soft hy­phen in­ser­tion](https://en.wikipedia.org/wiki/Soft_hyphen)
- [Soft hyphen insertion](https://en.wikipedia.org/wiki/Soft_hyphen)

Typeset does not re­quire any client-side JavaScript and uses less than a kilo­byte of CSS. Processed HTML & CSS works in Internet Explorer 5 and with­out any CSS. Typeset can be used man­u­ally or as a plu­gin for [Grunt](https://github.com/mobinni/grunt-typeset) and [gulp](https://github.com/lucasconstantino/gulp-typeset).
Typeset does not require any client-side JavaScript and uses less than a kilobyte of CSS. Processed HTML & CSS works in Internet Explorer 5 and without any CSS. Typeset can be used manually or as a plugin for [Grunt](https://github.com/mobinni/grunt-typeset) and [gulp](https://github.com/lucasconstantino/gulp-typeset).

<img src="https://i.imgur.com/5dTsGkH.gif" width="600">

Expand Down Expand Up @@ -58,7 +58,7 @@ Then tweak the CSS to match the metrics of your font and include it on your page

/*
Quotation mark
https://en.wikipedia.org/wiki/Quotation_mark)
https://en.wikipedia.org/wiki/Quotation_mark
*/

/* Single quotation marks (') */
Expand Down Expand Up @@ -173,5 +173,4 @@ See the [LICENSE](LICENSE) file for details.

- [Language options & support](https://github.com/davidmerfield/Typeset/issues/25)
- [Widows & orphans](https://github.com/davidmerfield/Typeset/issues/34).
- Incorporate features from [Normalize Opentype](http://kennethormandy.com/journal/normalize-opentype-css)
- Plugins for React, Angular, Svelte, jQuery
- Incorporate features from [Normalize Opentype](http://kennethormandy.com/journal/normalize-opentype-css)
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, "&thinsp;&mdash;&thinsp;");

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

// Nbsp for punc with spaces
// Non-breaking space
// https://en.wikipedia.org/wiki/Non-breaking_space
const NBSP = "&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>'
);
});
});