GithubHelp home page GithubHelp logo

sapegin / richtypo.js Goto Github PK

View Code? Open in Web Editor NEW
123.0 8.0 13.0 2.07 MB

Typography enhancer for Node.js

Home Page: https://sapegin.github.io/richtypo.js/

License: MIT License

CSS 2.52% TypeScript 97.48%
typography quotes

richtypo.js's Introduction

Richtypo: HTML and Markdown typography enhancer for Node.js

npm Codecov Node.js CI status

Richtypo prepares your texts to publication on web: applies typography rules like quotes ("“”), dashes (-) and non-breaking spaces to make text prettier and more readable.

Richtypo comes with typography rules for English, French, and Russian, but you can customize them and create your own rules — each rule is an independent JavaScript function.

Have a look at the example page and its source.

Features

  • Works with plain text, Markdown, or HTML
  • Takes care of your HTML tags
  • English, French, and Russian rules
  • Run only rules you need
  • Add your own rules
  • Works on the server and in the browser
  • No dependencies

Documentation

Read the docs.

Changelog

The changelog can be found on the Releases page.

Contributing

Bug fixes are welcome, but not new features. Please take a moment to review the contributing guidelines.

Sponsoring

This software has been developed with lots of coffee, buy me one more cup to keep it going.

Buy Me A Coffee

Authors and license

Artem Sapegin and contributors.

MIT License, see the included License.md file. Also see the project status.

richtypo.js's People

Contributors

arsenyyankovsky avatar bobthecow avatar dbismut avatar dependabot[bot] avatar nalgeon avatar sapegin avatar strathausen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

richtypo.js's Issues

Add/mention option for UTF nbsps in Readme

I tried the example from the readme and thought it didn't work, as the output had UTF nbsps —  , but Readme had escaped HTML ones —  .

Is there an option for setting the output to html-escaped one? If not, then it should be mentioned in Readme, so people won't confuse when they won't see the escaped nbsps in their result.

Work with markdown documents

If we are using richtypo (via CLI or maybe using an option) for files in markdown format (.md etc.) then richtypo would need to know what not to enhance, because right now there would be a lot of errors and richtypo would destroy the markup in most of the cases.

Here are some of the basic examples, and there could be a lot of them (some of them are not markdown specific, so those could be fixed in general, but whatever):

  • markdown's <hr>s made as --- etc. on a single line now transform to ;
  • hanging typography is applied to the markup like ![](blah) transforming them to ![]<span class="hbrace">(</span>blah);
  • dashes that start the lists are transformed to the &mdash;;
  • indentations are not preserved: if there were more that one spaces at the beginning of the line, then after the convertation there would be only one;
  • text in code blocks (ah, that wouldn't be easy to parse…) shouldn't be typographed, 'cause the actual symbols there should be exact as you write them;

Take care of orphans

From wiki:

A word […] that appears by itself at the end of a paragraph. Orphans result in too much white space between paragraphs or at the bottom of a page.

It could be nice to take care of orphans at the end of different block-level elements like paragraphs, headers, list items etc.

The rule would be rather simple: there should be a nbsp between the last two words at the end of each block-level element.

We should look not at the words only, but also for the wanted length of the last line in symbols, so if there would be a very long word or a few very short words, then there would be either no nbsps inserted, either more that one.

Nbsp bug

Raw:

рынка книги, мы к этой цифре

Result:

рынка книги, мы&nbsp;к этой цифре

Expected result:

рынка книги, мы&nbsp;к&nbsp;этой цифре

Source

richtypo = require "richtypo"
richtypo.lang "ru"
@body = richtypo.full @body

Undo function (duplicate <abbr> and <nobr> on already typographed text)

Richtypo is not idempotent. E.g., if you process text which already has abbreviated (via <abbr>) words, then <abbr> tags are duplicated:

expect(rt.title('<abbr>WWW</abbr>'))
  .toBe(_symb('<abbr>WWW</abbr>'));
// actual: '<abbr><abbr>WWW</abbr></abbr>'

Not sure if you consider it a bug, maybe the library is intended to work this way. I'd certainly prefer it to not duplicate existing abbrs and nobrs.

Maybe preservе content for these tags "as is", like code or pre? Probably if someone is using nobr in his text, he already took care of typography inside it.

Output formats

HTML (the only supported now format), HTML for nerds (<nobr><span class="nobr">), text.

/cc @kizu

Richtypo removes non-breaking spaces in the original text

  1. Consider text like this:
    обзор автомобиля Tesla
    I've put a non-breaking space between автомобиля and Tesla so that it would always end up on the same line.
  2. Rychtypo parses the text, adds &nbsp; where it thinks is appropriate and completely removes the original ones I've put there.

Here is more on why invisible non-breaking space characters are cool: http://destroytoday.com/findings/fix-widows-with-non-breaking-spaces/

Non breaking space rendered as unicode

Hey - sorry but I'm not sure I understand why richtypo renders non breaking space in unicode \xA0 rather than html nbsp;? In my situation, I'm using element.innerHTML = richtypo.full(text) and unicode spaces are not rendered in html.

It seems like cleanup_after is responsible for this. I've forked the repo to make richtypo behave like I think it should (ie doing all transformations using unicode characters and substituting these characters with corresponding html entities after the whole process).

https://github.com/dbismut/richtypo.js

Obviously most of the tests fail :)

CLI interface

It would be nice to have CLI interface for richtypo. It could be used then for a lot of purposes: watchers, usage in editors, piping through etc.

Diacritical marks support

Input:

richtypo.rich('Paul-Löbe')

Actual output:

<nobr>Paul-L</nobr>öbe

Expected output:

<nobr>Paul-Löbe</nobr>

Ability to insert HTML entities instead of Unicode

As discussed in #11.

I see to ways of doing it:

First. Add new ruleset and use it like this:

richtypo.richtypo('Welcome to out website!', […, 'replace_entities', …], 'en');

It’s easy to implement but difficult to use.

Second. Add configuration method:

richtypo. setOptions({
  html_entities: true
})

Requires more work but much easier to use. And we could add more options later.

P. S. It’s probably better to add an option not only for &nbsp;s but for any special character: quotes, dashes, etc.

@algenon, @kizu what do you think?

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Error in Safari due to lookbehind assertion used in regex

Keep consecutive spaces

I tried to use richtypo to enrich my text but it keeps removing consecutive spaces which I do not want. Hence I am not able to write code examples in my text or other text that depends on indentation. I believe this test should pass:

it('should keep repeating consecutive spaces', () => {
    const input = 'function () {\n    console.log(1);\n}';
    expect(richtypo([], input)).to.be.equal(input);
});

But it fails because it always executes beforeAll rule which removes repeating spaces. Can it be configured somehow to not remove repeating spaces?

Hanging punctuation reprocessing problems

richtypo.full can wrap hanging elements several times. wich doen't allow one to edit texts wich were processed earlier

Example:

<span class="hlaquo"><span class="hlaquo">«</span></span>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.