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

Rewrite html plugin #23

Merged
merged 23 commits into from
Jan 29, 2023
Merged

Rewrite html plugin #23

merged 23 commits into from
Jan 29, 2023

Conversation

azu
Copy link
Member

@azu azu commented Jan 29, 2023

Rewrite ALL!!!

Breaking Changes

  • Require textlint v13.0.0+
    • html plugin is written in Pure ESM
  • Require Node.js 16+
  • Convert JavaScript to TypeScript

Features

  • use rehype instead of hast
  • support <h1> ... <h6>'s levels
  • support <ul> and <ol>
  • support <img />'s alt and title
  • support <a>'s title

Bug Fixes

fix #19
fix textlint-ja/textlint-rule-no-synonyms#4
fix #2

close #15 - It looks like rule implementation issue https://github.com/KeitaMoromizato/textlint-rule-max-appearence-count-of-words/blob/master/src/max-appearence-count-of-words.js

Testings

  • New snapshot testing
    • Tree Dump view for human

📝 Welcome to contribute! We looking for new maintainer!

Comment on lines +1 to +19
Document(root)
html(element)
head(element)
title(element)
Str(text)
Str(text)
body(element)
Str(text)
Paragraph(element)
span(element)
Str(text)
Str(text)
Paragraph(element)
span(element)
span(element)
Str(text)
span(element)
Str(text)
Str(text)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<html>
<head><title>テスト</title></head>
<body>
<p><span>こんにちは、世界。</span></p>
<p><span><span>こんにちは、</span><span>世界。</span></span></p>
</body>
</html>

to be this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

textlint-util-to-string can get "こんにちは、世界。"

@azu azu added Type: Breaking Change Includes breaking changes Type: Bug Bug or Bug fixes Type: Feature New Feature labels Jan 29, 2023
"description": "",
"main": "index.js",
"scripts": {
"test": "textlint test/ -f pretty-error || exit 0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example test

Comment on lines +176 to +193
if (txtNode.type === "Link") {
if (txtNode.properties.href !== undefined) txtNode.url = txtNode.properties.href;
if (txtNode.properties.title !== undefined) txtNode.title = txtNode.properties.title;
} else if (txtNode.type === "Image") {
if (txtNode.properties.alt !== undefined) txtNode.alt = txtNode.properties.alt;
if (txtNode.properties.title !== undefined) txtNode.title = txtNode.properties.title;
if (txtNode.properties.src !== undefined) txtNode.url = txtNode.properties.src;
} else if (txtNode.type === "Header") {
const depth = Number(txtNode.tagName.slice(1)) as TxtHeaderNode["depth"];
if (depth > 0 && depth < 7) txtNode.depth = depth;
} else if (txtNode.type === "List") {
if (txtNode.tagName === "ul") {
txtNode.ordered = false;
} else if (txtNode.tagName === "ol") {
txtNode.ordered = true;
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mapping properties

Comment on lines +61 to +66
} else {
// other case, return original tagName
return node.tagName;
}
} else if (node.type === "doctype") {
return "doctype";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fix #19

html to be html
Previously, html to be Html. This cause textlint-ja/textlint-rule-no-synonyms#4

Comment on lines +1 to +13
Document(root)
doctype(doctype)
html(element)
head(element)
title(element)
Str(text)
Str(text)
body(element)
Paragraph(element)
Str(text)
Str(text)
table(element)
Str(text)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tree dump

@azu azu merged commit 4e442fa into master Jan 29, 2023
@azu azu deleted the rewrite branch January 29, 2023 12:49
@azu azu mentioned this pull request Jan 29, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Breaking Change Includes breaking changes Type: Bug Bug or Bug fixes Type: Feature New Feature
Projects
None yet
1 participant