textlint-rule / textlint-rule-no-unmatched-pair

textlint rule that check unmatched pairs like "(" and "]"
MIT License
7 stars 3 forks source link

Support for tex #4

Closed Mister-Hope closed 3 years ago

Mister-Hope commented 3 years ago

Hope this plugin can omit tex block in markdown image

azu commented 3 years ago

Can you use latex plugin? textlint-plugin-latex2e will parse it.

or, ignore $$ ~ $$ by textlint-filter-rule-allowlist.

{
    "filters": {
        "allowlist": {
            "allow": [
                "/\\$\\$[\\s\\S]*?\\$\\$/m"
            ]
        }
    }
}
Mister-Hope commented 3 years ago

Emm, is this correct?

rules:
  "@textlint-rule/no-unmatched-pair": true

  apostrophe: true

  common-misspellings: true

  # en-capitalization:
  #   allowHeading: false
  #   allowLists: true

  stop-words:
    severity: warning

  terminology:
    terms:
      - Stylus
      - VuePress
      - - front[- ]matter
        - frontmatter
    exclude:
      - Node.js
      - URLs
      - repo

    severity: warning

  write-good:
    passive: false
    severity: warning
    whitelist:
      - daily
      - only
      - multiple
      - validate

  zh-half-and-full-width-bracket:
    bracket: halfWidth

// here
plugins:
  - latex2e

filters:
  allowlist:
    allow:
      - "/@flowstart[\\s\\S]*?@flowend/m"

  comments: true

I am still catching errors:

U:\project\vuepress-theme-hope\docs\theme\src\guide\feature\markdown\presentation.md
  92:3  error  Not found pair character for (.

$$
J(\theta_0,\theta_1) = \sum_{i=0}
$$
azu commented 3 years ago

@tani Does textlint-plugin-latex2e support $$ ~ $$ syntax?

This rule just replies on Paragraph node. If the plugin parses it as Paragraph, this error is expected. ( It can be ignored by textlint-filter-rule-allowlist)

tani commented 3 years ago

@azu Yes, it must support this syntax. I start to work on this issue.

tani commented 3 years ago

I have tested both cases @azu suggested. In my case, there is no problem. Could you show the minimal working example to us, @Mister-Hope ?

I attach my case. textlint-rule-no-umatched-pair-issue4.zip

This is a side topic. As his code is written in markdown, textlint-plugin-latex2e does not suite this problem. I recommend to use allowlist shown by @azu .

Mister-Hope commented 3 years ago

Emm, is this correct?

rules:
  "@textlint-rule/no-unmatched-pair": true

  apostrophe: true

  common-misspellings: true

  # en-capitalization:
  #   allowHeading: false
  #   allowLists: true

  stop-words:
    severity: warning

  terminology:
    terms:
      - Stylus
      - VuePress
      - - front[- ]matter
        - frontmatter
    exclude:
      - Node.js
      - URLs
      - repo

    severity: warning

  write-good:
    passive: false
    severity: warning
    whitelist:
      - daily
      - only
      - multiple
      - validate

  zh-half-and-full-width-bracket:
    bracket: halfWidth

// here
plugins:
  - latex2e

filters:
  allowlist:
    allow:
      - "/@flowstart[\\s\\S]*?@flowend/m"

  comments: true

I am still catching errors:

U:\project\vuepress-theme-hope\docs\theme\src\guide\feature\markdown\presentation.md
  92:3  error  Not found pair character for (.

$$
J(\theta_0,\theta_1) = \sum_{i=0}
$$

@tani here

tani commented 3 years ago

@Mister-Hope Thank you for replying me quickly. However, I can not test your example because of lacking actual document and more. Please show me again your example including with

Thnaks.

Mister-Hope commented 3 years ago

package.json:

{
  "name": "vuepress-theme-hope",
  "private": true,
  "description": "a light vuepress theme",
  "workspaces": [
    "docs/*",
    "packages/*",
    "tests/"
  ],
  "scripts": {
    "build": "lerna run build --parallel",
    "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2",
    "commit": "npx git-cz",
    "demo:build": "yarn workspace test build",
    "demo:serve": "yarn workspace test serve",
    "docs/add-this:build": "yarn workspace add-this-docs build",
    "docs/add-this:serve": "yarn workspace add-this-docs serve",
    "docs/comment:build": "yarn workspace comment-docs build",
    "docs/comment:serve": "yarn workspace comment-docs serve",
    "docs/copy-code:build": "yarn workspace copy-code-docs build",
    "docs/copy-code:serve": "yarn workspace copy-code-docs serve",
    "docs/last-update:build": "yarn workspace last-update-docs build",
    "docs/last-update:serve": "yarn workspace last-update-docs serve",
    "docs/md-enhance:build": "yarn workspace md-enhance-docs build",
    "docs/md-enhance:serve": "yarn workspace md-enhance-docs serve",
    "docs/photo-swipe:build": "yarn workspace photo-swipe-docs build",
    "docs/photo-swipe:serve": "yarn workspace photo-swipe-docs serve",
    "docs/pwa:build": "yarn workspace pwa-docs build",
    "docs/pwa:serve": "yarn workspace pwa-docs serve",
    "docs/reading-time:build": "yarn workspace reading-time-docs build",
    "docs/reading-time:serve": "yarn workspace reading-time-docs serve",
    "docs/seo:build": "yarn workspace seo-docs build",
    "docs/seo:serve": "yarn workspace seo-docs serve",
    "docs/sitemap:build": "yarn workspace sitemap-docs build",
    "docs/sitemap:serve": "yarn workspace sitemap-docs serve",
    "docs/theme:build": "yarn workspace theme-docs build",
    "docs/theme:serve": "yarn workspace theme-docs serve",
    "lerna:bootstrap": "lerna bootstrap",
    "lerna:clean": "lerna clean",
    "lint": "prettier --check --write . && eslint . --ext .js,.ts,.vue --fix && markdownlint **/*.md --ignore **/node_modules/** --fix",
    "lint-md": "yarn lint-md:style && yarn lint-md:wording",
    "lint-md:style": "remark --quiet .",
    "lint-md:wording": "textlint ./docs/**/*.md",
    "lint-md:wording:fix": "textlint ./docs/**/*.md --fix",
    "lint:check": "prettier --check . && eslint . --ext .js,.ts,.vue && markdownlint **/*.md --ignore **/node_modules/**",
    "package/comment:test": "yarn workspace @mr-hope/vuepress-plugin-comment test",
    "package/md-enhance:test": "yarn workspace vuepress-plugin-md-enhance test",
    "package/shared-utils:test": "yarn workspace @mr-hope/vuepress-shared-utils test",
    "package/theme:test": "yarn workspace vuepress-theme-hope test",
    "packages:bootstrap": "node scripts/bootstrap.js",
    "packages:check-update": "lerna exec -- ncu --timeout 600000 && ncu --timeout 600000",
    "packages:release": "node scripts/release.js",
    "packages:update": "lerna exec -- ncu -u --timeout 600000 && ncu -u --timeout 600000 && yarn install && yarn upgrade",
    "test": "lerna run test --parallel",
    "typescript:compile": "tsc && tsc --project tsconfig.commonjs.json"
  },
  "husky": {
    "hooks": {
      "pre-commit": "yarn run typescript:compile && yarn run test && lint-staged"
    }
  },
  "lint-staged": {
    "*.vue": [
      "eslint --fix",
      "prettier --write"
    ],
    "*.{js,ts}": [
      "eslint --fix",
      "prettier --write"
    ],
    "*.{md,json,yml}": [
      "prettier --write"
    ],
    "package.json": [
      "sort-package-json"
    ]
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  },
  "devDependencies": {
    "@textlint-rule/textlint-rule-no-unmatched-pair": "^1.0.7",
    "@types/chai": "4.2.14",
    "@types/mocha": "8.0.3",
    "@typescript-eslint/eslint-plugin": "4.5.0",
    "@typescript-eslint/parser": "4.5.0",
    "@vue/eslint-config-prettier": "6.0.0",
    "@vue/eslint-config-typescript": "7.0.0",
    "@vuepress/test-utils": "1.7.1",
    "chai": "4.2.0",
    "conventional-changelog-cli": "2.1.0",
    "cross-env": "7.0.2",
    "cz-conventional-changelog": "3.3.0",
    "del": "6.0.0",
    "eslint": "7.11.0",
    "eslint-config-prettier": "6.13.0",
    "eslint-plugin-prettier": "3.1.4",
    "eslint-plugin-vue": "7.1.0",
    "husky": "4.3.0",
    "lerna": "3.22.1",
    "lint-staged": "10.4.2",
    "markdownlint-cli": "0.24.0",
    "mocha": "8.2.0",
    "prettier": "2.1.2",
    "remark-cli": "9.0.0",
    "remark-footnotes": "3.0.0",
    "remark-frontmatter": "3.0.0",
    "remark-lint": "8.0.0",
    "remark-math": "4.0.0",
    "remark-preset-lint-consistent": "4.0.0",
    "remark-preset-lint-recommended": "5.0.0",
    "sort-package-json": "1.46.0",
    "textlint": "^11.7.6",
    "textlint-filter-rule-allowlist": "^2.0.1",
    "textlint-filter-rule-comments": "1.2.2",
    "textlint-plugin-latex2e": "^1.0.0",
    "textlint-rule-apostrophe": "2.0.0",
    "textlint-rule-common-misspellings": "1.0.1",
    "textlint-rule-en-capitalization": "2.0.2",
    "textlint-rule-stop-words": "2.0.7",
    "textlint-rule-terminology": "2.1.4",
    "textlint-rule-write-good": "1.6.2",
    "textlint-rule-zh-half-and-full-width-bracket": "1.1.0",
    "ts-node": "9.0.0",
    "typescript": "4.0.3",
    "vue-template-compiler": "2.6.12",
    "webpack": "4.44.2",
    "webpack-bundle-analyzer": "^3.9.0",
    "webpack-chain": "6.5.1",
    "webpack-dev-server": "3.11.0"
  }
}

Markdown:

U:\project\vuepress-theme-hope\docs\theme\src\guide\feature\markdown\presentation.md

---
icon: presentation
tags:
  - feature
  - markdown
---

# Presentation support

Let the Markdown file in your VuePress site support presentation.

## Configuration

```js {5}
module.exports = {
  themeConfig: {
    mdEnhance: {
      // or you can pass an object to config reveal.js
      presentation: true,
    },
  },
};

This plugin is using reveal.js to support this feature.

Syntax

@slidestart [theme]

<!-- slide1 -->

---

<!-- slide2 -->

---

<!-- slide3 -->

@slideend

Theme available:

Demo

@slidestart

Slide 1

A paragraph with some text and a link


Slide 2


Slide 3.1

const a = 1;

--

Slide 3.2

$$ J(\theta_0,\theta1) = \sum{i=0} $$

@slideend

@slidestart

## Slide 1

A paragraph with some text and a [link](https://mrhope.site)

---

## Slide 2

- Item 1
- Item 2

---

## Slide 3.1

```js
const a = 1;

--

Slide 3.2

$$ J(\theta_0,\theta1) = \sum{i=0} $$

@slideend


## Options

You can set `reveal` to pass options to reveal.js per page in frontmatter, you can also set `presentation` in plugin options to set reveal.js globally.

For more options, see [reveal.js config](https://revealjs.com/config/). For more usage, see [reveal.js documatation](https://revealjs.com/)

## Themes

<!-- markdownlint-disable -->

### Auto

@slidestart

## Slide Title

A paragraph with some text and a [link](https://mrhope.site)

---

## Highlight

```js
const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

Black

@slidestart black

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

White

@slidestart white

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

League

@slidestart league

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

Beige

@slidestart beige

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

Sky

@slidestart sky

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

Night

@slidestart night

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

Serif

@slidestart serif

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

Simple

@slidestart simple

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

Solarized

@slidestart solarized

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

Blood

@slidestart blood

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend

Moon

@slidestart moon

Slide Title

A paragraph with some text and a link


Highlight

const add = (a, b) => {
  if (typeof b === "undefined") return a + 1;

  return a + b;
};

@slideend


textlintrc:

```yml
rules:
  "@textlint-rule/no-unmatched-pair": true

  apostrophe: true

  common-misspellings: true

  # en-capitalization:
  #   allowHeading: false
  #   allowLists: true

  stop-words:
    severity: warning

  terminology:
    terms:
      - Stylus
      - VuePress
      - - front[- ]matter
        - frontmatter
    exclude:
      - Node.js
      - URLs
      - repo

    severity: warning

  write-good:
    passive: false
    severity: warning
    whitelist:
      - daily
      - only
      - multiple
      - validate

  zh-half-and-full-width-bracket:
    bracket: halfWidth

plugins:
  - latex2e

filters:
  allowlist:
    allow:
      - "/@flowstart[\\s\\S]*?@flowend/m"
      # - "/\\$\\$[\\s\\S]*?\\$\\$/m"

  comments: true

Error with lint-md:wording

U:\project\vuepress-theme-hope\docs\theme\src\guide\feature\markdown\presentation.md
  92:3  error  Not found pair character for (.
tani commented 3 years ago

@Mister-Hope Thank you. I tested you code and got errors you said. Finally, I can say why this error is caused.

Saying technically, the core module @textlint/kernel choose which plugin should use for given file by file extension like *.md. latex2e plugin sets .tex for this file extension. Thus, textlint CLI runs your configuration unexpectedly. I mean textlint CLI recognize the input file is written in markdown and does not run latex2e plugin.

Let me assume that this file is linted as markdown. The markdown syntax has "emphasize" represented by _a_ rendered as a. Your running example J(\theta_0,\theta_1) = \sum_{i=0} is interpreted as this syntax in textlint. Thus, this rule failed to parse underscores and parenthesis surrounded by them.

Hence, this is not bug of latex2e plugin and this rule. I conclude that we should use allowlist filter for this case.

@azu How about my conclusion?

Mister-Hope commented 3 years ago

Can we add support for latex snnipets in markdown?

tani commented 3 years ago

We have two options

  1. To skip checking latex snippets in markdown
  2. To check latex snippets in markdown

The first option has been solved by the above comments. You would like to do like the second option?

Mister-Hope commented 3 years ago

Yes, I would like them to be checked. Markdown extending syntax is $math inline$ and

$$
math blocks
which can have muti lines
$$

can be write as :

$$math blocks
which can have muti lines$$

or just a single line

$$ math in display mode $$
tani commented 3 years ago

I see. It is not problem of this issue.

We have to discuss the markdown parser. As I commented, it is caused by the confliction of syntaxes between markdown and LaTeX. Textlint disallows to modify parser by rules. Thus, we might not be able to get solutions any more from discussion here.

Please claim your issue to the central repository of textlint. I guess this issue can be solved by