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

Allow using of non-word characters in [import] tag #52

Merged
merged 8 commits into from Jul 13, 2017
Merged

Conversation

lwchkg
Copy link
Contributor

@lwchkg lwchkg commented Jul 12, 2017

  • Parsing algorithm redone to allow proper parsing of title:"edit:true" or the like. (edit should not be set to true in this case).
  • More validity check for the input is done.
  • Added relevant tests.

Known problems:

  • Cannot parse title:"he's good" properly. In this patch the title we be set to "he".
  • Output escaping is not done (but HandleBar HTML escapes all {{}} tags.) This breaks Nunjucks (in your ace templates) if the last character of the string is exactly \.

@lwchkg
Copy link
Contributor Author

lwchkg commented Jul 12, 2017

Please take a look (I've missed by a day, since there are a lot to read from different packages). There are still two issues to solve, so please advice whether I should ask them here or to put them in another PR.

BTW, some GitBook dependencies appears to be broken in the CI. :-(

@lwchkg
Copy link
Contributor Author

lwchkg commented Jul 13, 2017

Found that the build failure is due to a bug in gitbook-cli 2.3.1. See GitbookIO/gitbook-cli#68 for the bug report.

Copy link
Owner

@azu azu left a comment

Choose a reason for hiding this comment

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

Thanks for PR.
I've review it. It seem to good.

I think that unescapeString is unstable api.
If you know alternative, please use that.

src/parser.js Outdated
@@ -3,13 +3,25 @@
const path = require("path");
const Handlebars = require("handlebars");
const logger = require("winston-color");
import { defaultKeyValueMap, initOptions, checkMapTypes, convertValue } from "./options.js";
const common = require("commonmark/lib/common.js");
Copy link
Owner

Choose a reason for hiding this comment

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

Does commonmark export this? ( Is it a undocument API? )
We want to avoid to use direct require.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it is not documented, nor exported by commonmark package.
I'll copy the implementation to our own code (and the license too - which appears to be 2-clause BSD).

src/parser.js Outdated
let match = "";
while ((match = expressionRegExp.exec(label))) {
let key = match[1];
if (["include", "import"].includes(key)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Node.js v4 does not support Array#inclues
http://node.green/#ES2016-features-Array-prototype-includes-Array-prototype-includes
We want to support Node.js LTS as possible.

Can you use indexOf or add ponyfill or polyfill?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't this be handled by babel instead of by us? I mean, you can use "babel-preset-env", and specify the node version in .babelrc

BTW, I was told that the gitbook server used node 5.1.*. But recently the broken gitbook-cli 2.3.1 moved to node LTS (currentlt v6).

Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't this be handled by babel instead of by us?

No. Babel only transpile syntax by default.

I think that this PR fix a bug - it is a patch version update.
Dropping Node.js 4.x make breaking change - it is a major version update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your clarification! Done.

assert.equal(result, " marker0 , marker1 ");

result = parseValue('"~invalid~"', "string", "marker");
assert.equal(result, undefined);
Copy link
Owner

Choose a reason for hiding this comment

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

use strictEqual insteadof equal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted with thanks.

src/parser.js Outdated
export function parseValue(value, type, key) {
switch (type) {
case "string":
value = common.unescapeString(value.substring(1, value.length - 1));
Copy link
Owner

Choose a reason for hiding this comment

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

const unescapedValue = ... is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted.

@azu
Copy link
Owner

azu commented Jul 13, 2017

I think it's better that adding pattern test to https://github.com/azu/gitbook-plugin-include-codeblock/tree/master/test/patterns

@lwchkg
Copy link
Contributor Author

lwchkg commented Jul 13, 2017

Thanks for pointing out at the pattern test. I'll add a few there.

@lwchkg
Copy link
Contributor Author

lwchkg commented Jul 13, 2017

The new patch is finally prepared. Please take a look.

To resolve failures in CI, I've blacklisted "gitbook-cli" 2.3.1 in the example/*/package.json.


src/unescape-string.js is extracted from https://github.com/jgm/commonmark.js:

Copyright (c) 2014, John MacFarlane
Copy link
Owner

Choose a reason for hiding this comment

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

👍

@azu
Copy link
Owner

azu commented Jul 13, 2017

LGTM

@azu azu merged commit e1866d9 into azu:master Jul 13, 2017
@azu
Copy link
Owner

azu commented Jul 13, 2017

@lwchkg Thanks!

@azu
Copy link
Owner

azu commented Jul 13, 2017

Release 3.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants