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

upgrade autoloader #1242

Merged
merged 2 commits into from
Dec 7, 2017
Merged

upgrade autoloader #1242

merged 2 commits into from
Dec 7, 2017

Conversation

bazooka07
Copy link

Hi Golmote,

Two points for missing components with autoloader plugin :

  • the data-autoloader-path attribute for the <script> tag is required in some cases. Documentation already exists at http://golmote.free.fr/prism-autoloader/plugins/autoloader/
  • It's better if the languages_path in config object is relative to the src attribute of the calling script than to the document root of a web site.

Copy link
Contributor

@Golmote Golmote left a comment

Choose a reason for hiding this comment

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

Hi @bazooka07. Wow somehow I documented something without implementing it. I'm terribly sorry for that, I probably forgot.

Thanks for working on this! Please take a look at my comments.

languages_path = path;
}
} else {
path = script.src.replace(/[\w\-]+\.js$/, 'components/');
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't you set languages_path here instead?
Also, you don't need to escape \- in that case.

var config = Prism.plugins.autoloader = {
languages_path: 'components/',
languages_path: path,
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too, I think you meants languages_path.

var path = script.getAttribute('data-autoloader-path').trim();
if(path != '') {
languages_path = path;
}
Copy link
Member

Choose a reason for hiding this comment

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

If this condition isn't met, we'd end up with languages_path as undefined. Should we have a fall back / default for languages_path?

@bazooka07
Copy link
Author

Yes, you are right. I fix my PR

    var script = document.getElementsByTagName('script');
    script = script[script.length - 1];
    var languages_path = 'components/';
    if(script.hasAttribute('data-autoloader-path')) {
        var path = script.getAttribute('data-autoloader-path').trim();
        if(path.length > 0 && !/^[a-z]+:\/\//i.test(script.src)) {
            languages_path = path.replace(/\/?$/, '/');
        }
    } else if (/[\w-]+\.js$/.test(script.src)) {
        languages_path = script.src.replace(/[\w-]+\.js$/, 'components/');
    }
    var config = Prism.plugins.autoloader = {
        languages_path: languages_path,
        use_minified: true
    };

@mAAdhaTTah
If the test is broken, we fallback into the initial value.

@Golmote
We rejected data-autoloader-path beginning with "http://", ... for security reason.
a '/' is added at the end if missing.

@Golmote
Copy link
Contributor

Golmote commented Dec 6, 2017

You have conflicts to resolve now @bazooka07
Apart from this, the PR looks to me. I'll wait for your approval too, @mAAdhaTTah, since you're around.

@mAAdhaTTah
Copy link
Member

LGTM. Just need to rebuild the autoloader.min.js.

@bazooka07
Copy link
Author

I'm not an expert about Git and I don't know how to resolve this conflict.
Somebody updates the gh-pages branch just an hour before I pushed my pull-request.

So I do the following commands :

git checkout gh-pages
git pull upstream gh-pages
git checkout autoloader-path1
git rebase gh-pages

But at last, I have a conflict with prism-autoloader.min.js. Even, if I launch gulp.

Can somebody help me ?
If not, I have to create a new branch.

@Golmote Golmote merged commit e66de38 into PrismJS:gh-pages Dec 7, 2017
@Golmote
Copy link
Contributor

Golmote commented Dec 7, 2017

Don't worry it's ok. I solved the conflict locally. Thanks for contributing!

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

3 participants