These are chat archives for wooorm/remark

3rd
Sep 2017
@erquhart What kind of entities are created? The default is false, which shouldn’t create any entities: https://github.com/wooorm/remark/tree/master/packages/remark-stringify#optionsentities
Titus
@wooorm
Sep 03 2017 10:16
@erquhart Your second question: I had that idea a while ago: wooorm/remark#5 and wooorm/remark#32
But, I like that remark is like prettier. I don’t think there’s a good reason to use *foo* and _bar_, and keep that style: using one style is better.
Wang Shidong
@wsdjeg
Sep 03 2017 11:42
@wooorm I need to use remark in cli, but I do not how to include wcwidth in cli.
Wang Shidong
@wsdjeg
Sep 03 2017 11:49

for example when I use

remark --no-color docs/README_zh_cn.md --use remark-frontmatter -s '"stringLength": "s => s.length"'

I get

error  Error: Invalid value `s => s.length` for setting `options.stringLength
and if I want to use wcwidth, I need to install wcwidth via npm install -g wcwidth, then I run the command?
remark --no-color docs/README_zh_cn.md --use remark-frontmatter -s '"stringLength": "s => wcwidth(s)"'
Shawn Erquhart
@erquhart
Sep 03 2017 12:36

I love the prettier-like functionality of Remark! But it should probably be optional.

Regarding entities, I'm referring to encoded entities in raw markdown being decoded by remark-parse, not remark-stringify. So & in markdown becomes & in the MDAST. It breaks intentionally encoded entities.

An example of how these two issues impact documents: Smashing Magazine's new site is using Netlify CMS for content editing, and the markdown editor in the CMS is built on Slate and Unified. They have a ton of articles that have been around for years, and when they touch one with the editor, it often results in a large and unexpected changeset. The entity decoding issue is even more serious because it causes things like example script tags to become actual tags. Just encoding everything when stringifying is the safe fix for that, but it causes things to be encoded that weren't originally encoded.

Shawn Erquhart
@erquhart
Sep 03 2017 12:42
This is one of the last issues to resolve before we can release the new editor (current editor is built on markdown-it and Prosemirror). Encoding everything could work I suppose, it's just rough having these huge diffs on the first edit of every post. I'd love to reduce those changes if possible.
Titus
@wooorm
Sep 03 2017 13:02
@wsdjeg If you’re using the CLI, you have to use a .remarkrc.js file, as the settings passed in bash or other shells are passed in as text
say your .remarkrc.js file looks like this:
{
  settings: {
    stringLength: require('wcwidth')
  },
  plugins: [
    require('remark-frontmatter')
  ]
}
And then run remark like so: remark --no-color docs/README_zh_cn.md, it will automatically pick up on the config file
@erquhart That’s inherent to ASTs: they don’t contain all the information to create the exact input file. That’s what CSTs do. ASTs don’t care about if you’re using double quotes or single quotes: just that something is a “string literal”
It can be done by patching properties (e.g., node.data.marker = '*' for emphasis), but it’ll never be perfect
Titus
@wooorm
Sep 03 2017 13:07
@erquhart the difference between markdown-it (and commonmark) vs remark probably stems that those are meant to compile HTML, whereas remark doesn’t necessarily.
If you pass in charlie &copy; delta to either of the two parsers, or remark with remark-html, they should all output <p>charlie © delta</p>
Shawn Erquhart
@erquhart
Sep 03 2017 13:09
Not Commonmark: try.commonmark.org
Titus
@wooorm
Sep 03 2017 13:09
It sounds more like a bug in markdown-it if script tags are escaped, but not in remark
Shawn Erquhart
@erquhart
Sep 03 2017 13:09
Check the AST tab
yields:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "CommonMark.dtd">
<document xmlns="http://commonmark.org/xml/1.0">
  <paragraph>
    <text>charlie </text>
    <text>©</text>
    <text> delta</text>
  </paragraph>
</document>
Do you have an example?
Shawn Erquhart
@erquhart
Sep 03 2017 13:11
Try &amp;
Or &gt; / &lt;
Titus
@wooorm
Sep 03 2017 13:12
Ah, yes that’s different
That depends on how you’re using remark
Could you show a contrived example where remark, with remark-html, leaves ampersands “unencoded”?
Shawn Erquhart
@erquhart
Sep 03 2017 13:13
This use case doesn't involve html
Titus
@wooorm
Sep 03 2017 13:13
Well, if we’re not dealing with HTML, that there’s no need to use entities in markdown
They’re almost always superfluous
Shawn Erquhart
@erquhart
Sep 03 2017 13:13
The markdown is eventually transformed via Hugo, but that's separate
Titus
@wooorm
Sep 03 2017 13:14
You can pass in entities: 'escape' if you just want to escape “special” (in the sense of, for HTML) entities
Shawn Erquhart
@erquhart
Sep 03 2017 13:15
That's just for stringify right?
Titus
@wooorm
Sep 03 2017 13:15
yup
But there’s no reason that I can think of, of using entities
Shawn Erquhart
@erquhart
Sep 03 2017 13:16
I'm trying to leave things in their current encoded/decoded state, which changes at parse
No reason to use encoded entities? Like <?
Titus
@wooorm
Sep 03 2017 13:16
Only if you’re not using commonmark (if you need to escape special characters, but commonmark allows the \> )
Nope, not needed in markdown
Shawn Erquhart
@erquhart
Sep 03 2017 13:16
That was encoded when I typed it lol
Being lazy, forgot to format
Titus
@wooorm
Sep 03 2017 13:18
So what I mean that &gt; and &lt; and other entities are not needed in markdown
and remark should be smart enough to, when needed, escape them, e.g., with a backslash
Shawn Erquhart
@erquhart
Sep 03 2017 13:20
We had to turn off Remark's HTML escaping, though.
Titus
@wooorm
Sep 03 2017 13:20
?
Shawn Erquhart
@erquhart
Sep 03 2017 13:20
HTML is valid markdown, but it kept getting escaped.
Titus
@wooorm
Sep 03 2017 13:21
my answer depends on what your stack is, which plugins you use, and how
Titus
@wooorm
Sep 03 2017 13:23
why is pedantic on? That can break commonmark support
Shawn Erquhart
@erquhart
Sep 03 2017 13:24
Can't recall what that was solving, I can try turning it off.
Titus
@wooorm
Sep 03 2017 13:25
:+1:
Shawn Erquhart
@erquhart
Sep 03 2017 13:25
Honestly, 100% Commonmark support isn't necessarily a requirement, just need to reduce unnecessary changes.
But yeah, I'll definitely try that.
Titus
@wooorm
Sep 03 2017 13:26
the two allowDangerousHTMLs look fine
:/
I dunno why all HTML is escaped!
Shouldn’t happen from what I can see
But this is too big for me to debug
So if you want me to take a good look at this I need a smaller example
Shawn Erquhart
@erquhart
Sep 03 2017 13:29
For sure, definitely didn't expect that!
Titus
@wooorm
Sep 03 2017 13:29
:+1:
Shawn Erquhart
@erquhart
Sep 03 2017 13:29
I'll get an example together.
Trying pedantic now.
Titus
@wooorm
Sep 03 2017 13:29
Great!
:ok:
Wang Shidong
@wsdjeg
Sep 03 2017 13:51
@wooorm hi, are you hel?
I need to use remark in my plugin, in the plugin I need to run remark with different options, so all the options should be configable in my plugin.
so I can not use the .remarkrc.js, if I need to use pure cli, how should I do?
Wang Shidong
@wsdjeg
Sep 03 2017 14:19
BTW, when I use the .remarkrc.js you shown me, I get
docs/README_zh_cn.md
  1:1  error  Error: Cannot parse file `.remarkrc.js`
Unexpected token ,
    at FormattedError (/home/wsdjeg/.npm-packages/lib/node_modules/remark-cli/node_modules/fault/index.js:30:12)
    at done (/home/wsdjeg/.npm-packages/lib/node_modules/remark-cli/node_modules/unified-engine/lib/find-up.js:143:22)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:504:3)

✖ 1 error
Titus
@wooorm
Sep 03 2017 14:20
I probably made a typo
I didn't check if the js was valid
If you want to use the CLI in JS you're better of using https://github.com/unifiedjs/unified-engine I think
Wang Shidong
@wsdjeg
Sep 03 2017 14:37
I think maybe you do not understand what I want, I do not need to create a js plugin, but a vim plugin, in the vim plugin I need to run differnt kind of remark command, it base on the option provided by the vim plugin.
what I hope is, remark support this kind of command,
    let g:neoformat_markdown_remark = {
            \ 'exe': 'remark',
            \ 'args': ['--no-color', '--silent', '--use', 'remark-frontmatter', '--setting',  JSON],
            \ 'stdin': 1,
            \ }
Titus
@wooorm
Sep 03 2017 14:47
You can create a vim plugin wrapping js code
I think I understand what you’re doing, but you can’t pass a JS function through args
You can pass a config file with --rc-path though
and then specify a path/to/your/config.js, containing the config for wcwidth
Wang Shidong
@wsdjeg
Sep 03 2017 14:49
yeah, I can not pass JS func to the cmd,

hmm, but

{
  settings: {
    stringLength: require('wcwidth')
  },
  plugins: [
    require('remark-frontmatter')
  ]
}

seems does not work

Titus
@wooorm
Sep 03 2017 14:54
Hey, I’d like to help you, but I need more info than that: how are you running this?
Wang Shidong
@wsdjeg
Sep 03 2017 14:56
wsdjeg:SpaceVim [ remark | ✚ 11 ] ➭ cat .remarkrc.js 
{
  settings: {
    stringLength: require('wcwidth')
  },
  plugins: [
    require('remark-frontmatter')
  ]
}
✔ wsdjeg:SpaceVim [ remark | ✚ 11 ] ➭ remark --no-color docs/README_zh_cn.md
docs/README_zh_cn.md
  1:1  error  Error: Cannot parse file `.remarkrc.js`
Unexpected token ,
    at FormattedError (/home/wsdjeg/.npm-packages/lib/node_modules/remark-cli/node_modules/fault/index.js:30:12)
    at done (/home/wsdjeg/.npm-packages/lib/node_modules/remark-cli/node_modules/unified-engine/lib/find-up.js:143:22)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:504:3)

✖ 1 error
I just copy this to .remarkrc.js
then run remark --no-color path/to/md
Titus
@wooorm
Sep 03 2017 14:59
Ah, yes sorry, I forgot module.exports, does this work?
module.exports = {
  settings: {
    stringLength: require('wcwidth')
  },
  plugins: [
    require('remark-frontmatter')
  ]
};
Wang Shidong
@wsdjeg
Sep 03 2017 15:00
nick catch, it works
s/nick/nice
Titus
@wooorm
Sep 03 2017 15:06
👍
Wang Shidong
@wsdjeg
Sep 03 2017 15:09
SpaceVim/SpaceVim#821
I will use vim script to generate the remark configration file, and return the path to to the argv
Titus
@wooorm
Sep 03 2017 15:18
👌