remarkjs / remark-retext Goto Github PK
View Code? Open in Web Editor NEWplugin to transform from remark (Markdown) to retext (natural language)
Home Page: https://remark.js.org
License: MIT License
plugin to transform from remark (Markdown) to retext (natural language)
Home Page: https://remark.js.org
License: MIT License
Hey Titus!
Unfortunately running into some issues with upgrading retext-mapbox-standard
to the 'newest everything' and I can isolate the problem up to this module, sort of...
Here's a gist for demonstration: https://gist.github.com/tmcw/0dbd9cbcbccdd10899200cf6d00f04f5
Issues that I've been able to isolate so far:
throw err
for error reporting within the remark callback method, but that gets caught by unified and silenced.Error: mdast-util-to-nlcst expected node
It would be nice if remark-retext
could support a unified plugin list instead of a processor using the same syntax as unified-engine
. Logic for this resides in https://github.com/unifiedjs/unified-engine/blob/main/lib/configuration.js. It probably makes sense to extract it into a new unified project.
remark-retext
is often used with remark-cli
, which supports YAML and JSON configuration files, but remark-retext
only works with JavaScript configuration files, because a processor is needed.
It would be nice if the following .remarkrc
file:
const dictionary = require('dictionary-en');
const english = require('retext-english');
const quotes = require('retext-quotes');
const repeatedWords = require('retext-repeated-words');
const syntaxURLs = require('retext-syntax-urls');
const unified = require('unified');
module.exports = {
plugins: [
'remark-frontmatter',
'remark-gfm',
'remark-lint-heading-increment',
'remark-lint-no-duplicate-defined-urls',
'remark-lint-no-duplicate-definitions',
'remark-lint-no-empty-url',
'remark-lint-no-reference-like-url',
'remark-lint-no-undefined-references',
'remark-lint-no-unneeded-full-reference-image',
'remark-lint-no-unneeded-full-reference-link',
'remark-lint-no-unused-definitions',
'remark-prettier',
['remark-validate-links', { repository: 'https://gitlab.com/remcohaszing/koas.git' }],
[
'remark-retext',
unified()
.use(english)
.use(syntaxURLs)
.use(repeatedWords)
.use(quotes),
],
],
};
could be rewritten as JSON or YAML:
plugins:
- remark-frontmatter
- remark-gfm
- remark-lint-heading-increment
- remark-lint-no-duplicate-defined-urls
- remark-lint-no-duplicate-definitions
- remark-lint-no-empty-url
- remark-lint-no-reference-like-url
- remark-lint-no-undefined-references
- remark-lint-no-unneeded-full-reference-image
- remark-lint-no-unneeded-full-reference-link
- remark-lint-no-unused-definitions
- remark-prettier
- - remark-validate-links
- repository: https://gitlab.com/remcohaszing/koas.git
- - remark-retext
- - retext-english
- retext-syntax-urls
- retext-repeated-words
- retext-quotes
N/A
(I'm not sure if this is the right place to report the issue, since it uses several components of the remark and retext environment, so please excuse me if it should be somewhere else.)
I'm using remark-retext
to run retext-spell
on the content of Markdown files, and I get a warning for a spelling error in an autolink.
package.json
belowRun these commands in a directory with the files below:
$ npm install
$ node index.js
package.json
:
{
"name": "remark-retext-spell-autolink",
"version": "0.0.1",
"license": "BlueOak-1.0.0",
"files": [
"index.js"
],
"dependencies": {
"dictionary-en": "3.0.0",
"remark-parse": "8.0.2",
"remark-retext": "4.0.0",
"remark-stringify": "8.1.0",
"retext-english": "3.0.4",
"retext-spell": "4.0.0",
"unified": "9.0.0",
"vfile-reporter": "6.0.1"
}
}
index.js
:
'use strict'
const unified = require('unified')
unified()
.use(require('remark-parse'))
.use(
require('remark-retext'),
unified()
.use(require('retext-english'))
.use(require('retext-spell'), {dictionary: require('dictionary-en')})
)
.use(require('remark-stringify'))
.process('<https://blueoakcouncil.org/license/1.0.0>', (err, file) => {
console.error(require('vfile-reporter')(err || file))
})
I expected no warning for anything in an autolink, since it will undoubtedly contain things that are not (English) words.
I'm reporting here, since I would expect remark-retext to drop autolinks when passing the text from the Markdown to the retext processor.
$ node index.js
1:10-1:28 warning `blueoakcouncil.org` is misspelt blueoakcouncil-org retext-spell
⚠ 1 warning
I can't get retext-smartypants
to do its thing when combined with remark-retext
.
This works fine:
const file = unified()
.use(require('retext-english'))
.use(require('retext-smartypants'))
.use(require('retext-stringify'))
.processSync('He said, "A \'simple\' English sentence. . ."')
console.log(String(file))
// => He said, “A ‘simple’ English sentence…"
But this doesn't:
const file = unified()
.use(require('remark-parse'))
.use(
require('remark-retext'),
unified()
.use(require('retext-english'))
.use(require('retext-smartypants'))
)
.use(require('remark-stringify'))
.processSync('He said, "A \'simple\' English sentence. . ."')
console.log(String(file))
// => He said, "A 'simple' English sentence. . ."
@wooorm am I doing something wrong?
remark-retext currently returns an async processor with no option to change this.
By adding an option to request a syncronous processor instead, the plugin would become more versatile.
Do not use remark-retext in syncronous functions.
I tested the example code with nodejs v10.11.0
and v12.4.0
, in both cases I get a type error
TypeError: file.warn is not a function
at warn ($MYWORKDIR/node_modules/retext-equality/lib/index.js:268:18)
at Object.simple ($MYWORKDIR/node_modules/retext-equality/lib/index.js:129:5)
at visitor ($MYWORKDIR/node_modules/retext-equality/lib/index.js:88:23)
at overload ($MYWORKDIR/node_modules/unist-util-visit/index.js:27:12)
at one ($MYWORKDIR/node_modules/unist-util-visit-parents/index.js:34:25)
at all ($MYWORKDIR/node_modules/unist-util-visit-parents/index.js:57:16)
at one ($MYWORKDIR/node_modules/unist-util-visit-parents/index.js:42:28)
at visitParents ($MYWORKDIR/node_modules/unist-util-visit-parents/index.js:26:3)
at visit ($MYWORKDIR/node_modules/unist-util-visit/index.js:22:3)
at transformer ($MYWORKDIR/node_modules/retext-equality/lib/index.js:70:5)
Does this library need a specific nodejs version or other libraries than
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
I don't have a lot of experience with JavaScript, so sorry if I made any beginner's mistake 😅
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.