Giter Club home page Giter Club logo

textlint-rule-sentence-length's Introduction

textlint-rule-sentence-length Actions Status: test

textlint rule that limit Maximum Length of Sentence.

Installation

npm install textlint-rule-sentence-length

Usage

Add "sentence-length" to your .textlintrc.

{
    "rules": {
        "sentence-length": true
    }
}

Options

  • max
    • default: 100
    • The total number of characters allowed on each sentences.
    • Sentence.length > 100 and throw Error
  • skipPatterns: string[]
  • skipUrlStringLink: boolean
    • Default: true
    • If it is true, skip url string link node like <https:example.com> or [https://example.com](https://example.com)
    • url string link is has the text which is same of url.
{
    "rules": {
        "sentence-length": {
            "max": 100
        }
    }
}

Uncount (...) from A sentence(...).

{
    "rules": {
        "sentence-length": {
            "max": 100,
            "skipPatterns": [
                "/\\(.*\\)$\\./"
            ]
        }
    }
}

A "Sentence"

This rule use sentence-splitter as library. So the definition of "Sentence" is the same as sentence-splitter.

For example, the following text is 3 sentences.

We are talking about pens.
He said "This is a pen. I like it".
I could relate to that statement.

Example sentences

Second line includes "...", but this rule treat second line as a single sentence.

If you want to ignore "...", you can use skipPatterns option.

{
    "rules": {
        "sentence-length": {
            "max": 100,
            "skipPatterns": [
                "/\".*?\"/"
            ]
        }
    }
}

Exception

  • Except BlockQuote
  • Except a single link node
  • Except url string link (skipUrlStringLink)

OK:

> LONG LONG LONG LONG LONG LONG LONG LONG Quote text. But it is quote text.

a single link node ↓

[textlint/textlint-filter-rule-comments: textlint filter rule that disables all rules between comments directive.](https://github.com/textlint/textlint-filter-rule-comments)

Very long https://example.com?longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong url.

NG:

This sentence includes one link and two Str.

This is [textlint/textlint-filter-rule-comments: textlint filter rule that disables all rules between comments directive.](https://github.com/textlint/textlint-filter-rule-comments).

Related Rules

See Other rules

Tests

npm test

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

textlint-rule-sentence-length's People

Contributors

0x6b avatar azu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

0x6b anspsky

textlint-rule-sentence-length's Issues

括弧で囲まれた文章が一文として判定される

image

「」や各種括弧内の文章が"。"で文を区切っているにもかかわらず一文として判定され、指定文字数を超えると指摘対象になってしまいます。小説を書くときは文章を「」で囲うことは珍しくないため、囲っていても通常の文と同様に扱っていただけると助かります。

aタグなどの属性値を無視したい

概要

aタグなどを文章中に含めた場合、そのaタグの属性値なども文字数としてカウントしてしまい、本来の文章よりも長く判定されてしまう。

期待する挙動

タグ自体は無視して、本来のテキスト部分でカウントしてほしい。

再現手順

$ mkdir test-textlint-maxlength && cd $_ && npm init -y
$ npm install -D textlint textlint-rule-sentence-length
$ cat > .textlintrc <<EOS
{
    "rules": {
        "sentence-length": true
    }
}
EOS

$ cat > index.md <<EOS
ではみなさんは、そういうふうに川だと云いわれたり、乳の流れたあとだと云われたりしていたこのぼんやりと白いものがほんとうは何かご承知ですか。

ではみなさんは、そういうふうに川だと云いわれたり、乳の流れたあとだと云われたりしていたこの<a href="https://www.aozora.gr.jp/cards/000081/files/456_15050.html" target="_blank" rel="noopener noreferrer">ぼんやりと白いもの</a>がほんとうは何かご承知ですか。
EOS

$ npx textlint index.md

/path/to/test-textlint-maxlength/index.md
  3:1  error  Line 3 sentence length(184) exceeds the maximum sentence length of 100.
Over 84 characters  sentence-length

✖ 1 problem (1 error, 0 warnings)

Feature request: Exclude URLs even in plaintext

I'd appreciate it if exclude URLs even in plaintext. 🙏

Input: test.txt (plaintext)

https://example.com/longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong

Current behavior:

  1:1  error  Line 1 sentence length(104) exceeds the maximum sentence length of 100.
Over 4 characters  sentence-length

Requested behavior: Exclude URLs even in plaintext, and the error is not occured.

Wrong line number

Maybe, this rule report wrong line number.
The line number is -1 from actual line number.

Should not split `.`?

JavaScriptをWasmにして実行する仕組みについて。
QuickJSを使いJavaScriptをByteCodeにしたxxxxを作成し、`QuickJS.wasm`と動的にリンクして大部分を共有している。
Shopify Functionで利用されるが、非同期処理の制限や5ms未満での実行制限がある。

This example should not be lint error

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.