huacnlee / autocorrect

A linter and formatter to help you to improve copywriting, correct spaces, words, and punctuations between CJK (Chinese, Japanese, Korean).
https://huacnlee.github.io/autocorrect
MIT License
918 stars 34 forks source link

Ability to adding HTML tag/element instead of spaces around English words #182

Open thomjiji opened 8 months ago

thomjiji commented 8 months ago

Is it possible for autocorrect to configurate to add others characters or HTML tag/element instead of adding spaces automatically?

I found that in epub's HTML document, simply adding spaces around English words and numbers may not be the most optimal way to handle it. And I found this in the W3C's draft "Requirements for Chinese Text Layout":

In principle, there is tracking or spacing between an adjacent Han character and a Western character of up to 1/4 em, except at the line start or end.

So in terms of epub, the solution I'm thinking of is adding an HTML tag/element around the English or numbers when mixing English words/numbers and Chinese characters, and then add that spacing using CSS. For example:

  1. Adding HTML element around numbers (or English words/characters):
“菲亚特<span class="margin_add_left">1100</span>”靠了过来
尼诺是<span class="margin_add_both">A</span>班的学生
比如说,<span class="margin_add_right">A</span>班的
  1. Styling it using CSS to add space around them.
.margin_add_both {
    margin-left: 0.25em;
    margin-right: 0.25em;
}

.margin_add_left {
    margin-left: 0.25em;
}

.margin_add_right {
    margin-right: 0.25em;
}

I've found autocorrect to be great for dealing with English and Chinese typesetting in the web or document world, but simply adding spaces may not be enough when dealing with epub documents that need to be imported into some ebook readers such as the Kindle for reading. So I would like to know if it is possible for the user to configure it to automatically add HTML tag around English words and numbers instead of just spaces. Thanks! 🌟